rabbitmq channel參數(shù)詳解

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

1但指、Channel

1.1 channel.exchangeDeclare():

type:有direct、fanout彻舰、topic三種

durable:true佛猛、false true:服務(wù)器重啟會(huì)保留下來Exchange惑芭。警告:僅設(shè)置此選項(xiàng),不代表消息持久化继找。即不保證重啟后消息還在遂跟。原文:true if we are declaring a durable exchange (the exchange will survive a server restart)

autoDelete:true、false.true:當(dāng)已經(jīng)沒有消費(fèi)者時(shí),服務(wù)器是否可以刪除該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, booleandurable,boolean autoDelete,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Map arguments)throwsIOException;

1.2 chanel.basicQos()

prefetchSize:0

prefetchCount:會(huì)告訴RabbitMQ不要同時(shí)給一個(gè)消費(fèi)者推送多于N個(gè)消息,即一旦有N個(gè)消息還沒有ack哄尔,則該consumer將block掉假消,直到有消息ack

global:true\false 是否將上面設(shè)置應(yīng)用于channel,簡單點(diǎn)說岭接,就是上面限制是channel級(jí)別的還是consumer級(jí)別

備注:據(jù)說prefetchSize 和global這兩項(xiàng)富拗,rabbitmq沒有實(shí)現(xiàn),暫且不研究

/**? ? * 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

? ? */voidbasicQos(intprefetchSize,intprefetchCount,booleanglobal)throwsIOException;

1.3 channel.basicPublish()

routingKey:路由鍵鸣戴,#匹配0個(gè)或多個(gè)單詞啃沪,*匹配一個(gè)單詞,在topic exchange做消息轉(zhuǎn)發(fā)用

mandatory:true:如果exchange根據(jù)自身類型和消息routeKey無法找到一個(gè)符合條件的queue窄锅,那么會(huì)調(diào)用basic.return方法將消息返還給生產(chǎn)者创千。false:出現(xiàn)上述情形broker會(huì)直接將消息扔掉

immediate:true:如果exchange在將消息route到queue(s)時(shí)發(fā)現(xiàn)對(duì)應(yīng)的queue上沒有消費(fèi)者,那么這條消息不會(huì)放入隊(duì)列中入偷。當(dāng)與消息routeKey關(guān)聯(lián)的所有queue(一個(gè)或多個(gè))都沒有消費(fèi)者時(shí)追驴,該消息會(huì)通過basic.return方法返還給生產(chǎn)者。

BasicProperties :需要注意的是BasicProperties.deliveryMode疏之,0:不持久化 1:持久化 這里指的是消息的持久化殿雪,配合channel(durable=true),queue(durable)可以實(shí)現(xiàn),即使服務(wù)器宕機(jī)锋爪,消息仍然保留

簡單來說:mandatory標(biāo)志告訴服務(wù)器至少將該消息route到一個(gè)隊(duì)列中冠摄,否則將消息返還給生產(chǎn)者;immediate標(biāo)志告訴服務(wù)器如果該消息關(guān)聯(lián)的queue上有消費(fèi)者几缭,則馬上將消息投遞給它,如果所有queue都沒有消費(fèi)者沃呢,直接把消息返還給生產(chǎn)者年栓,不用將消息入隊(duì)列等待消費(fèi)者了。

/**? ? * Publish a message.

? ? *

? ? * Publishing to a non-existent exchange will result in a channel-level

? ? * protocol exception, which closes the channel.

? ? *

? ? * Invocations of Channel#basicPublish will eventually block if a

? ? * resource-driven alarm is in effect.

? ? *

? ? * @see com.rabbitmq.client.AMQP.Basic.Publish

? ? * @see Resource-driven alarms.

? ? * @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

? ? */voidbasicPublish(String exchange, String routingKey,booleanmandatory,booleanimmediate, BasicProperties props,byte[] body)

? ? ? ? ? ? throwsIOException;

1.4channel.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

? ? */voidbasicAck(longdeliveryTag,booleanmultiple)throwsIOException;


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

deliveryTag:該消息的index

multiple:是否批量.true:將一次性拒絕所有小于deliveryTag的消息某抓。

requeue:被拒絕的是否重新入隊(duì)列


/**? ? * Reject one or several received messages.

? ? *

? ? * Supply the deliveryTag 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

? ? */voidbasicNack(longdeliveryTag,booleanmultiple,boolean requeue)

? ? ? ? ? ? throwsIOException;

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

deliveryTag:該消息的index

requeue:被拒絕的是否重新入隊(duì)列

channel.basicNack 與?channel.basicReject 的區(qū)別在于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

? ? */voidbasicReject(longdeliveryTag,booleanrequeue)throwsIOException;

1.6 channel.basicConsume(QUEUE_NAME, true, consumer);

autoAck:是否自動(dòng)ack惰瓜,如果不自動(dòng)ack否副,需要使用channel.ack、channel.nack崎坊、channel.basicReject 進(jìn)行消息應(yīng)答

/**? ? * 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, booleanautoAck, Consumer callback)throwsIOException;

1.7 chanel.exchangeBind()


channel.queueBind(queueName, EXCHANGE_NAME, bindingKey);

用于通過綁定bindingKey將queue到Exchange备禀,之后便可以進(jìn)行消息接收


/**? ? * 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) throwsIOException;

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


durable:true、false true:在服務(wù)器重啟時(shí),能夠存活

exclusive :是否為當(dāng)前連接的專用隊(duì)列曲尸,在連接斷開后赋续,會(huì)自動(dòng)刪除該隊(duì)列,生產(chǎn)環(huán)境中應(yīng)該很少用到吧另患。

autodelete:當(dāng)沒有任何消費(fèi)者使用時(shí)纽乱,自動(dòng)刪除該隊(duì)列。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, booleandurable,booleanexclusive,boolean autoDelete,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Map arguments)throwsIOException;

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末昆箕,一起剝皮案震驚了整個(gè)濱河市鸦列,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌鹏倘,老刑警劉巖薯嗤,帶你破解...
    沈念sama閱讀 211,290評(píng)論 6 491
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異第股,居然都是意外死亡应民,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,107評(píng)論 2 385
  • 文/潘曉璐 我一進(jìn)店門夕吻,熙熙樓的掌柜王于貴愁眉苦臉地迎上來诲锹,“玉大人,你說我怎么就攤上這事涉馅」樵埃” “怎么了?”我有些...
    開封第一講書人閱讀 156,872評(píng)論 0 347
  • 文/不壞的土叔 我叫張陵稚矿,是天一觀的道長庸诱。 經(jīng)常有香客問我,道長晤揣,這世上最難降的妖魔是什么桥爽? 我笑而不...
    開封第一講書人閱讀 56,415評(píng)論 1 283
  • 正文 為了忘掉前任,我火速辦了婚禮昧识,結(jié)果婚禮上钠四,老公的妹妹穿的比我還像新娘。我一直安慰自己跪楞,他們只是感情好缀去,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,453評(píng)論 6 385
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著甸祭,像睡著了一般缕碎。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上池户,一...
    開封第一講書人閱讀 49,784評(píng)論 1 290
  • 那天咏雌,我揣著相機(jī)與錄音凡怎,去河邊找鬼。 笑死处嫌,一個(gè)胖子當(dāng)著我的面吹牛栅贴,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播熏迹,決...
    沈念sama閱讀 38,927評(píng)論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼檐薯,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了注暗?” 一聲冷哼從身側(cè)響起坛缕,我...
    開封第一講書人閱讀 37,691評(píng)論 0 266
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎捆昏,沒想到半個(gè)月后赚楚,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,137評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡骗卜,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,472評(píng)論 2 326
  • 正文 我和宋清朗相戀三年宠页,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片寇仓。...
    茶點(diǎn)故事閱讀 38,622評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡举户,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出遍烦,到底是詐尸還是另有隱情俭嘁,我是刑警寧澤,帶...
    沈念sama閱讀 34,289評(píng)論 4 329
  • 正文 年R本政府宣布服猪,位于F島的核電站供填,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏罢猪。R本人自食惡果不足惜近她,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,887評(píng)論 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望膳帕。 院中可真熱鬧泄私,春花似錦、人聲如沸备闲。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,741評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽恬砂。三九已至,卻和暖如春蓬痒,著一層夾襖步出監(jiān)牢的瞬間泻骤,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,977評(píng)論 1 265
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留狱掂,地道東北人演痒。 一個(gè)月前我還...
    沈念sama閱讀 46,316評(píng)論 2 360
  • 正文 我出身青樓,卻偏偏與公主長得像趋惨,于是被迫代替她去往敵國和親鸟顺。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,490評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理器虾,服務(wù)發(fā)現(xiàn)讯嫂,斷路器,智...
    卡卡羅2017閱讀 134,629評(píng)論 18 139
  • 來源 RabbitMQ是用Erlang實(shí)現(xiàn)的一個(gè)高并發(fā)高可靠AMQP消息隊(duì)列服務(wù)器兆沙。支持消息的持久化欧芽、事務(wù)、擁塞控...
    jiangmo閱讀 10,346評(píng)論 2 34
  • 為了一些初學(xué)習(xí)者更好理解我就從簡單的解釋一下Rabbitmq的原理吧?葛圃,首先你可以這樣想RabbitMq就是一個(gè)隊(duì)...
    螃蟹和駱駝先生Yvan閱讀 7,395評(píng)論 6 4
  • 本文章翻譯自http://www.rabbitmq.com/api-guide.html千扔,并沒有及時(shí)更新。 術(shù)語對(duì)...
    joyenlee閱讀 7,645評(píng)論 0 3
  • 什么叫消息隊(duì)列 消息(Message)是指在應(yīng)用間傳送的數(shù)據(jù)库正。消息可以非常簡單曲楚,比如只包含文本字符串,也可以更復(fù)雜...
    lijun_m閱讀 1,340評(píng)論 0 1