简体   繁体   English

如何知道 rabbitmq 连接是否被 spring 云 stream 阻止?

[英]how to know if the rabbitmq connection is blocked with spring cloud stream?

We have a service that send a message in a rabbit queue configure like this:我们有一个在兔子队列中发送消息的服务,配置如下:

spring:
  cloud:
    stream:
      bindings:
        output:
          destination: test
      rabbit:
        bindings:
          output:
            producer:
              routingKeyExpression: headers.version

After having sent a very large number of messages during our bench tests, we noticed that the connection to the message queue is blocked: Blocked queue在我们的基准测试期间发送了大量消息后,我们注意到与消息队列的连接被阻塞:阻塞队列

It seems that the blockage comes when the RabbitMQ server uses above 40% of the available RAM, it raises a memory alarm and blocks all connections that are publishing messages.当 RabbitMQ 服务器使用超过 40% 的可用 RAM 时,似乎出现了阻塞,它会引发 memory 警报并阻止所有正在发布消息的连接。

Our problem is that in this particular case, we lose the messages sent in the queue.我们的问题是,在这种特殊情况下,我们丢失了队列中发送的消息。

How to avoid loss of messages using spring cloud stream.如何使用 spring 云 stream 避免消息丢失。 Here's a snippet of our class:这是我们的 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))));
     }

}

This code does not return any exception even though the queue is blocked.即使队列被阻塞,此代码也不会返回任何异常。 Is there a way to know the status of the queue (blocked) before sending the messages?有没有办法在发送消息之前知道队列的状态(阻塞)?

Add @EventListener methods (or ApplicationListener beans) to consume ConnectionBlockedEvent and ConnectionUnblockedEvent .添加@EventListener方法(或ApplicationListener bean)以使用ConnectionBlockedEventConnectionUnblockedEvent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM