[英]how to know if the rabbitmq connection is blocked with spring cloud stream?
我們有一個在兔子隊列中發送消息的服務,配置如下:
spring:
cloud:
stream:
bindings:
output:
destination: test
rabbit:
bindings:
output:
producer:
routingKeyExpression: headers.version
在我們的基准測試期間發送了大量消息后,我們注意到與消息隊列的連接被阻塞:阻塞隊列
當 RabbitMQ 服務器使用超過 40% 的可用 RAM 時,似乎出現了阻塞,它會引發 memory 警報並阻止所有正在發布消息的連接。
我們的問題是,在這種特殊情況下,我們丟失了隊列中發送的消息。
如何使用 spring 雲 stream 避免消息丟失。 這是我們的 class 的片段:
@Service
@EnableBinding(Source.class)
public class OurService {
Source source;
public void send(OurMessage ourMessage, Map<String, Object> headers) {
source.output().send(MessageBuilder.createMessage(ourMessage, new MessageHeaders(headers))));
}
}
即使隊列被阻塞,此代碼也不會返回任何異常。 有沒有辦法在發送消息之前知道隊列的狀態(阻塞)?
添加@EventListener
方法(或ApplicationListener
bean)以使用ConnectionBlockedEvent
和ConnectionUnblockedEvent
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.