久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 RabbitMQ(Java 客戶端),有沒有辦法確定消費期

Using RabbitMQ (Java client), is there a way to determine if network connection is closed during consume?(使用 RabbitMQ(Java 客戶端),有沒有辦法確定消費期間網(wǎng)絡(luò)連接是否關(guān)閉?) - IT屋-程序員軟件開發(fā)技術(shù)分享社
本文介紹了使用 RabbitMQ(Java 客戶端),有沒有辦法確定消費期間網(wǎng)絡(luò)連接是否關(guān)閉?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

我正在使用 Java 客戶端在 RHEL 5.3 上使用 RabbitMQ.我有 2 個節(jié)點(機器).Node1 正在使用 Java 幫助程序類 QueueingConsumer 從 Node2 上的隊列中消費消息.

I'm using RabbitMQ on RHEL 5.3 using the Java client. I have 2 nodes (machines). Node1 is consuming messages from a queue on Node2 using the Java helper class QueueingConsumer.

QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume("MyQueueOnNode2", noAck, consumer);
while (true)
{
   QueueingConsumer.Delivery delivery = consumer.nextDelivery();
   ... Process message - delivery.getBody()
}

如果接口在 Node1 或 Node2 上關(guān)閉(例如 ifconfig eth1 down),客戶端(上圖)永遠不會知道網(wǎng)絡(luò)不再存在.RabbitMQ 是否在 Java 客戶端上提供某種類型的配置,可用于確定連接是否已消失.關(guān)閉 Node2 上的 RabbitMQ 服務(wù)器將觸發(fā) ShutdownSignalException,可以捕獲該異常,并且應(yīng)用程序可以進入重新連接循環(huán).但是關(guān)閉接口不會導(dǎo)致任何類型的異常發(fā)生,因此代碼將在 consumer.nextDelivery() 上永遠等待.

If the interface is brought down on Node1 or Node2 (e.g. ifconfig eth1 down), the client (above) never knows the network isn't there anymore. Does RabbitMQ provide some type of configuration on the Java client that can be used to determine if the connection has gone away. Shutting down the RabbitMQ server on Node2 will trigger a ShutdownSignalException, which can be caught and the app can go into a reconnect loop. But bringing down the interface doesn't cause any type of exception to happen, so the code will be waiting forever on consumer.nextDelivery().

我也嘗試過使用這個調(diào)用的超時版本.例如

I've also tried using the timeout version of this call. e.g.

QueueingConsumer consumer = new QueueingConsumer(channel);
channel.basicConsume("MyQueueOnNode2", noAck, consumer);
int timeout_ms = 30000;
while (true)
{
   QueueingConsumer.Delivery delivery = consumer.nextDelivery(timeout_ms);
   if (delivery == null)
   {
      if (channel.isOpen() == false)             // Seems to always return true
      { throw new ShutdownSignalException(); }
   }
   else
   {
     ... Process message - delivery.getBody()
   }
}

但似乎這總是返回 true(即使接口已關(guān)閉).我假設(shè)在連接上注冊 ShutdownListener 會產(chǎn)生相同的結(jié)果,但還沒有嘗試過.

but appears that this always returns true (even though the interface is down). I assume registering for the ShutdownListener on the connection will yield the same results, but haven't tried that yet.

有沒有辦法配置某種心跳,或者你只需??要編寫自定義租約邏輯(例如我現(xiàn)在在這里")就可以讓它工作?

Is there a way to configure some sort of heartbeat, or do you just have to write custom lease logic (e.g. "I'm here now") in order to get this to work?

推薦答案

一般來說,你最好在 rabbitmq-discuss 郵件列表上發(fā)布有關(guān) rabbitmq 的問題.我們不傾向于跟蹤在此之外提出的問題.

In general, you're much better off posting questions regarding rabbitmq on the rabbitmq-discuss mailing list. We don't tend to track questions being asked outside of this.

您可以配置心跳,但默認情況下它是關(guān)閉的.您也可以打開 TCP Keep Alive.在創(chuàng)建新連接之前調(diào)用 ConnectionFactory 上的 setRequestedHeartbeat,或者,子類 ConnectionFactory,覆蓋 configureSocket 方法,并調(diào)用 socket.setKeepAlive(true).當(dāng)網(wǎng)絡(luò)中斷時,兩者都應(yīng)該導(dǎo)致連接通知.

There is a heartbeat that you can configure, though it is off by default. You could also turn on TCP Keep Alive. Either call setRequestedHeartbeat on the ConnectionFactory before creating a new connection, or, subclass ConnectionFactory, override the configureSocket method, and call socket.setKeepAlive(true). Both should result in the connection noticing when the network dies.

這篇關(guān)于使用 RabbitMQ(Java 客戶端),有沒有辦法確定消費期間網(wǎng)絡(luò)連接是否關(guān)閉?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 日韩欧美在线视频 | 三级在线免费观看 | 国产精品久久久久aaaa九色 | 亚洲国产精品视频一区 | 免费毛片网 | 91大神在线资源观看无广告 | 日韩福利| 国产成人综合亚洲欧美94在线 | av免费网| 天堂一区二区三区 | 精品国产91乱码一区二区三区 | 国产精品一区二区免费看 | 狠狠干影院 | 一区二区三区在线 | 成人超碰在线 | 欧美一级特黄aaa大片在线观看 | 黄色大片毛片 | 午夜网站视频 | 欧美精品综合在线 | 色资源在线 | 国产精品爱久久久久久久 | 精品视频在线观看 | 成人黄色av | 国产999精品久久久久久 | 99免费在线视频 | 亚洲色欲色欲www | 国产不卡一区在线观看 | 天天天堂 | 欧美一级久久久猛烈a大片 日韩av免费在线观看 | 人人操日日干 | 亚洲一区二区三区视频 | 五月激情综合网 | 日韩一区二区在线观看 | 中文字幕国产一区 | 免费日韩av网站 | 国产精品99久久免费观看 | 成人毛片网站 | 久久九 | 天天色图| 亚洲性视频 | 国产精品福利在线 |