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.pswp.cn/news/388533.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388533.shtml
英文地址,請注明出處:http://en.pswp.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…