rabbitmq channel参数详解【转】

 

1、Channel 

1.1 channel.exchangeDeclare():
type:有direct、fanout、topic三种
durable:true、false true:服务器重启会保留下来Exchange。警告:仅设置此选项,不代表消息持久化。即不保证重启后消息还在。原文:true if we are declaring a durable exchange (the exchange will survive a server restart)
autoDelete:true、false.true:当已经没有消费者时,服务器是否可以删除该Exchange。原文1:true if the server should delete the exchange when it is no longer in use。
复制代码
 /*** Declare an exchange.* @see com.rabbitmq.client.AMQP.Exchange.Declare* @see com.rabbitmq.client.AMQP.Exchange.DeclareOk* @param exchange the name of the exchange* @param type the exchange type* @param durable true if we are declaring a durable exchange (the exchange will survive a server restart)* @param autoDelete true if the server should delete the exchange when it is no longer in use* @param arguments other properties (construction arguments) for the exchange* @return a declaration-confirm method to indicate the exchange was successfully declared* @throws java.io.IOException if an error is encountered*/Exchange.DeclareOk exchangeDeclare(String exchange, String type, boolean durable, boolean autoDelete,Map<String, Object> arguments) throws IOException;
复制代码
1.2 chanel.basicQos()
prefetchSize:0 
prefetchCount:会告诉RabbitMQ不要同时给一个消费者推送多于N个消息,即一旦有N个消息还没有ack,则该consumer将block掉,直到有消息ack
global:true\false 是否将上面设置应用于channel,简单点说,就是上面限制是channel级别的还是consumer级别
备注:据说prefetchSize 和global这两项,rabbitmq没有实现,暂且不研究
复制代码
    /*** Request specific "quality of service" settings.** These settings impose limits on the amount of data the server* will deliver to consumers before requiring acknowledgements.* Thus they provide a means of consumer-initiated flow control.* @see com.rabbitmq.client.AMQP.Basic.Qos* @param prefetchSize maximum amount of content (measured in* octets) that the server will deliver, 0 if unlimited* @param prefetchCount maximum number of messages that the server* will deliver, 0 if unlimited* @param global true if the settings should be applied to the* entire channel rather than each consumer* @throws java.io.IOException if an error is encountered*/void basicQos(int prefetchSize, int prefetchCount, boolean global) throws IOException;
复制代码
1.3 channel.basicPublish()
routingKey:路由键,#匹配0个或多个单词,*匹配一个单词,在topic exchange做消息转发用

mandatory:true:如果exchange根据自身类型和消息routeKey无法找到一个符合条件的queue,那么会调用basic.return方法将消息返还给生产者。false:出现上述情形broker会直接将消息扔掉
immediate:true:如果exchange在将消息route到queue(s)时发现对应的queue上没有消费者,那么这条消息不会放入队列中。当与消息routeKey关联的所有queue(一个或多个)都没有消费者时,该消息会通过basic.return方法返还给生产者。
BasicProperties :需要注意的是BasicProperties.deliveryMode,0:不持久化 1:持久化 这里指的是消息的持久化,配合channel(durable=true),queue(durable)可以实现,即使服务器宕机,消息仍然保留
简单来说:mandatory标志告诉服务器至少将该消息route到一个队列中,否则将消息返还给生产者;immediate标志告诉服务器如果该消息关联的queue上有消费者,则马上将消息投递给它,如果所有queue都没有消费者,直接把消息返还给生产者,不用将消息入队列等待消费者了。
复制代码
  /*** Publish a message.** Publishing to a non-existent exchange will result in a channel-level* protocol exception, which closes the channel.** Invocations of <code>Channel#basicPublish</code> will eventually block if a* <a href="http://www.rabbitmq.com/alarms.html">resource-driven alarm</a> is in effect.** @see com.rabbitmq.client.AMQP.Basic.Publish* @see <a href="http://www.rabbitmq.com/alarms.html">Resource-driven alarms</a>.* @param exchange the exchange to publish the message to* @param routingKey the routing key* @param mandatory true if the 'mandatory' flag is to be set* @param immediate true if the 'immediate' flag is to be* set. Note that the RabbitMQ server does not support this flag.* @param props other properties for the message - routing headers etc* @param body the message body* @throws java.io.IOException if an error is encountered*/void basicPublish(String exchange, String routingKey, boolean mandatory, boolean immediate, BasicProperties props, byte[] body)throws IOException;
复制代码

1.4 channel.basicAck();

deliveryTag:该消息的index
multiple:是否批量.true:将一次性ack所有小于deliveryTag的消息。

 

复制代码
    /*** Acknowledge one or several received* messages. Supply the deliveryTag from the {@link com.rabbitmq.client.AMQP.Basic.GetOk}* or {@link com.rabbitmq.client.AMQP.Basic.Deliver} method* containing the received message being acknowledged.* @see com.rabbitmq.client.AMQP.Basic.Ack* @param deliveryTag the tag from the received {@link com.rabbitmq.client.AMQP.Basic.GetOk} or {@link com.rabbitmq.client.AMQP.Basic.Deliver}* @param multiple true to acknowledge all messages up to and* including the supplied delivery tag; false to acknowledge just* the supplied delivery tag.* @throws java.io.IOException if an error is encountered*/void basicAck(long deliveryTag, boolean multiple) throws IOException;
复制代码

 

1.5 channel.basicNack(delivery.getEnvelope().getDeliveryTag(), false, true);

deliveryTag:该消息的index
multiple:是否批量.true:将一次性拒绝所有小于deliveryTag的消息。
requeue:被拒绝的是否重新入队列

 

复制代码
    /*** Reject one or several received messages.** Supply the <code>deliveryTag</code> from the {@link com.rabbitmq.client.AMQP.Basic.GetOk}* or {@link com.rabbitmq.client.AMQP.Basic.GetOk} method containing the message to be rejected.* @see com.rabbitmq.client.AMQP.Basic.Nack* @param deliveryTag the tag from the received {@link com.rabbitmq.client.AMQP.Basic.GetOk} or {@link com.rabbitmq.client.AMQP.Basic.Deliver}* @param multiple true to reject all messages up to and including* the supplied delivery tag; false to reject just the supplied* delivery tag.* @param requeue true if the rejected message(s) should be requeued rather* than discarded/dead-lettered* @throws java.io.IOException if an error is encountered*/void basicNack(long deliveryTag, boolean multiple, boolean requeue)throws IOException;
复制代码

1.5 channel.basicReject(delivery.getEnvelope().getDeliveryTag(), false);

deliveryTag:该消息的index
requeue:被拒绝的是否重新入队列

channel.basicNack 与 channel.basicReject 的区别在于basicNack可以拒绝多条消息,而basicReject一次只能拒绝一条消息

复制代码
 /*** Reject a message. Supply the deliveryTag from the {@link com.rabbitmq.client.AMQP.Basic.GetOk}* or {@link com.rabbitmq.client.AMQP.Basic.Deliver} method* containing the received message being rejected.* @see com.rabbitmq.client.AMQP.Basic.Reject* @param deliveryTag the tag from the received {@link com.rabbitmq.client.AMQP.Basic.GetOk} or {@link com.rabbitmq.client.AMQP.Basic.Deliver}* @param requeue true if the rejected message should be requeued rather than discarded/dead-lettered* @throws java.io.IOException if an error is encountered*/void basicReject(long deliveryTag, boolean requeue) throws IOException;
复制代码
1.6 channel.basicConsume(QUEUE_NAME, true, consumer);
autoAck:是否自动ack,如果不自动ack,需要使用channel.ack、channel.nack、channel.basicReject 进行消息应答
 
复制代码
    /*** Start a non-nolocal, non-exclusive consumer, with* a server-generated consumerTag.* @param queue the name of the queue* @param autoAck true if the server should consider messages* acknowledged once delivered; false if the server should expect* explicit acknowledgements* @param callback an interface to the consumer object* @return the consumerTag generated by the server* @throws java.io.IOException if an error is encountered* @see com.rabbitmq.client.AMQP.Basic.Consume* @see com.rabbitmq.client.AMQP.Basic.ConsumeOk* @see #basicConsume(String, boolean, String, boolean, boolean, Map, Consumer)*/String basicConsume(String queue, boolean autoAck, Consumer callback) throws IOException;
复制代码
 

1.7 chanel.exchangeBind()

 

channel.queueBind(queueName, EXCHANGE_NAME, bindingKey);
用于通过绑定bindingKey将queue到Exchange,之后便可以进行消息接收

 

 
复制代码
    /*** Bind an exchange to an exchange, with no extra arguments.* @see com.rabbitmq.client.AMQP.Exchange.Bind* @see com.rabbitmq.client.AMQP.Exchange.BindOk* @param destination the name of the exchange to which messages flow across the binding* @param source the name of the exchange from which messages flow across the binding* @param routingKey the routine key to use for the binding* @return a binding-confirm method if the binding was successfully created* @throws java.io.IOException if an error is encountered*/Exchange.BindOk exchangeBind(String destination, String source, String routingKey) throws IOException;
复制代码
 

1.8 channel.queueDeclare(QUEUE_NAME, false, false, false, null);

 

durable:true、false true:在服务器重启时,能够存活
exclusive :是否为当前连接的专用队列,在连接断开后,会自动删除该队列,生产环境中应该很少用到吧。
autodelete:当没有任何消费者使用时,自动删除该队列。this means that the queue will be deleted when there are no more processes consuming messages from it.

 

 
复制代码
 /*** Declare a queue* @see com.rabbitmq.client.AMQP.Queue.Declare* @see com.rabbitmq.client.AMQP.Queue.DeclareOk* @param queue the name of the queue* @param durable true if we are declaring a durable queue (the queue will survive a server restart)* @param exclusive true if we are declaring an exclusive queue (restricted to this connection)* @param autoDelete true if we are declaring an autodelete queue (server will delete it when no longer in use)* @param arguments other properties (construction arguments) for the queue* @return a declaration-confirm method to indicate the queue was successfully declared* @throws java.io.IOException if an error is encountered*/Queue.DeclareOk queueDeclare(String queue, boolean durable, boolean exclusive, boolean autoDelete,Map<String, Object> arguments) throws IOException;

 

转:https://www.cnblogs.com/piaolingzxh/p/5448927.html

 

转载于:https://www.cnblogs.com/royfans/p/9628924.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/388533.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

感染EXE文件代码(C++)

C代码#include <windows.h> #include <winnt.h> #include <stdio.h> #include <assert.h> #define DEBUG 1 #define EXTRA_CODE_LENGTH 18 #define SECTION_SIZE 0x1000 #define SECTION_NAME ".eViLhsU" #define F…

nlp gpt论文_GPT-3:NLP镇的最新动态

nlp gpt论文什么是GPT-3&#xff1f; (What is GPT-3?) The launch of Open AI’s 3rd generation of the pre-trained language model, GPT-3 (Generative Pre-training Transformer) has got the data science fraternity buzzing with excitement!Open AI的第三代预训练语言…

真实不装| 阿里巴巴新人上路指北

新手上路&#xff0c;总想听听前辈们分享他们走过的路。橙子选取了阿里巴巴合伙人逍遥子&#xff08;阿里巴巴集团CEO&#xff09; 、Eric&#xff08;蚂蚁金服董事长兼CEO&#xff09;、Judy&#xff08;阿里巴巴集团CPO&#xff09;的几段分享&#xff0c;他们是如何看待职场…

小程序学习总结

上个周末抽空了解了一下小程序,现在将所学所感记录以便日后翻看;需要指出的是我就粗略过了下小程序的api了解了下小程序的开发流程以及工具的使用,然后写了一个小程序的demo;在我看来,如果有前端基础学习小程序无异于锦上添花了,而我这个三年的码农虽也写过不少前端代码但离专业…

tomcat java环境配置

jsp 环境变量配置 一、配置JDK 首先&#xff0c;从Sun网站上下载jdk。 双击jdk-1_5_0_04-windows-i586-p.exe开始安装&#xff0c;默认安装到C:/Program Files/Java/jdk1.5.0_04&#xff0c;你也可以更改路径&#xff0c;但要记住最后选择的路径&#xff0c;设置环境变量的时候…

uber 数据可视化_使用R探索您在Uber上的活动:如何分析和可视化您的个人数据历史记录

uber 数据可视化Perhaps, dear reader, you are too young to remember that before, the only way to request a particular transport service such as a taxi was to raise a hand to make a signal to an available driver, who upon seeing you would stop if he was not …

java B2B2C springmvc mybatis电子商城系统(四)Ribbon

2019独角兽企业重金招聘Python工程师标准>>> 一&#xff1a;Ribbon是什么&#xff1f; Ribbon是Netflix发布的开源项目&#xff0c;主要功能是提供客户端的软件负载均衡算法&#xff0c;将Netflix的中间层服务连接在一起。Ribbon客户端组件提供一系列完善的配置项如…

c语言函数的形参有几个,C中子函数最多有几个形参

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼C89 31个&#xff0c;C99 127个。ANSI C892.2.4.1 Translation limitsThe implementation shall be able to translate and execute at least one program that contains at least one instance of every one of the following lim…

Linux上Libevent的安装

1、下载wget -O libevent-2.0.21-stable.tar.gz https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz2、解压 tar zxvf libevent-2.0.21-stable.tar.gz3、配置安装路径 cd libevent-2.0.21-stable ./configure -prefix/usr4、编译并安装 make make …

Win7安装oracle 10 g

开始-运行-输入hdwwiz-回车 ——选则手动 ——网络适配器——左边选Microsoft&#xff0c;右边找到Microsoft Loopback Adapter ——完成 打开 控制面板\网络和 Internet\网络和共享中心 会发现多了一个本地连接 点详细信息 发现是Microsoft Loopback Adapter的。…

基于plotly数据可视化_[Plotly + Datashader]可视化大型地理空间数据集

基于plotly数据可视化简介(我们将创建的内容)&#xff1a; (Introduction (what we’ll create):) Unlike the previous tutorials in this map-based visualization series, we will be dealing with a very large dataset in this tutorial (about 2GB of lat, lon coordinat…

Centos用户和用户组管理

inux系统是一个多用户多任务的分时操作系统&#xff0c;任何一个要使用系统资源的用户&#xff0c;都必须首先向系统管理员申请一个账号&#xff0c;然后以这个账号的身份进入系统。1、添加新的用户账号使用useradd命令&#xff0c;其语法如下&#xff1a;useradd 选项 用户名-…

吹气球问题的C语言编程,C语言怎样给一个数组中的数从大到小排序

满意答案#include "stdio.h"int main(){int i,j;int a[12];for(i1; i<10; i)scanf("%d",&a[i]);for(i1; i<10; i)for(ji; j<10; j)if(a[i]{int ta[i];a[i]a[j];a[j]t;}//前十个数的排序for(i1; i<10; i)printf("%d ",a[i]);prin…

裴波那契数列

斐波那契数列&#xff1a;0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... 求斐波那契数列第 n 项的值&#xff1a; 方法一&#xff1a;递归 function fibonacci(n) {if (!Number.isSafeInteger(n) || n < 0) {return;}if (n 0 || n 1) {return n;} else {return fibo…

划痕实验 迁移面积自动统计_从Jupyter迁移到合作实验室

划痕实验 迁移面积自动统计If you want to use Google Colaboratory to perform your data analysis, for building data pipelines and data visualizations, here is the beginners’ guide to migrate from one tool to the other.如果您想使用Google Colaboratory进行数据分…

英法德三门语言同时达到c1,【分享】插翅而飞的孩子(转载)

微信转来的&#xff0c;觉得发人深思&#xff0c;转来这里插翅而飞的孩子(一)开篇一&#xff1a;让孩子拥有一双丰满的翅膀。作者简介&#xff1a;英华兰的Dr.Bing,德国儿童教育学博士&#xff0c;数字媒体硕士和计算机软件工程本科。精通英法德三门语言&#xff0c;从事儿童语…

数据库建表赋予权限语句

sqlplus /nologconn / as sysdba//创建临时表空间create temporary tablespace zfmi_temptempfile D:\oracle\oradata\zfmi\zfmi_temp.dbf size 32m autoextend on next 32m maxsize 2048mextent management local;//tempfile参数必须有//创建数据表空间create tablespace zfmi…

day03 基本数据类型

1.什么是数据类型 变量值即我们 存放的数据 &#xff0c;数据类型及变量值的类型 2.变量值为何要区分类型 因为变量值使用记录现实世界中事物的特征&#xff0c;针对不同的特征就应该用不同类型的值去标识 3.如何应用数据类型 一 数据类型&#xff1a; 1.整型int &#xff1a;…

美国移民局的I797表原件和I129表是什么呢

I-129表,Petition for a Non-immigrant Worker&#xff0c;即非移民工作许可申请表I797 表 &#xff0c;Original L1-1A approval notice L1签证批准通过通知表L-1签证的申请程序1. L-1签证的申请必须首先由准备调派雇员的外国母公司在美国的分支机构向移民局提出陈情申请。这些…

数据开放 数据集_除开放式清洗之外:叙述是开放数据门户的未来吗?

数据开放 数据集There is growing consensus in the open data community that the mere release of open data — that is data that can be freely accessed, remixed, and redistributed — is not enough to realize the full potential of openness. Successful open data…