简体   繁体   中英

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.

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. Here's a snippet of our 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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