Search code examples
rabbitmqpushmessage-queuemessagingthreshold

Is it possible to get a "push" when number of messages reaches threshold?


I want to check

  1. What is the best practice to get the number of messages in a queue. I know I can get it via queue.getMessageCount() I also know that you can get it as the monitor plugin gets it. is it an http request? or with the rabbitmqctl application.(JNI?) ? What is the best way if I want to react only when X messages arrive?
  2. And more important - can I get the number of messages in a queue via push?

Can I declare a threshold to receive a push notification? (e.g. get a signal every time I have 5000 messages)


Solution

  • you could use queue x-max-length http://www.rabbitmq.com/maxlength.html

    Queue length is a measure that takes into account ready messages, ignoring unacknowledged messages and message size. Messages will be dropped or dead-lettered from the front of the queue to make room for new messages once the limit is reached.

    So you can configure the Dead Letter Exchanges and manage the messages rejected by limit exceeded.

    The reason is a name describing why the message was dead-lettered and is one of the following: rejected - the message was rejected with requeue=false, expired - the TTL of the message expired; or maxlen - the maximum allowed queue length was exceeded.

    I hope it helps

    EDIT**

    The idea could be:

    Subscribe a queue for example _queue on DLE so when a message arrives means your is reached.

    void hanlemymessage(msg){
    
    .....
    
    }
    
    
      //// consumer _queue
      public void handleDelivery(String consumerTag, Envelope envelope,
                BasicProperties properties, byte[] body) throws java.io.IOException {
    
                   MyMessage m= new MyMessage(body)
                   voidhanlemymessage(m)
    
                  StartmyBulkConsumer()
    
        }
    

    Now you can start your work_consumer.

        //// consumer work_queue
              public void handleDelivery(String consumerTag, Envelope envelope,
                        BasicProperties properties, byte[] body) throws java.io.IOException {
    
                           MyMessage m= new MyMessage(body)
                           voidhanlemymessage(m)
    
                           if (msgcount.addandget()==mythreshold){
                              closeConsumer()
    
                             }
    

    This could be one solution.

    Actually I think that this logic should be delegated to the application: For example the work_consumer always running and your application trigger your bulk function when reaches the .