Announcement Announcement Module
Collapse
No announcement yet.
Publisher Confirms with RabbitMQ Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Publisher Confirms with RabbitMQ

    I am trying to do a similar configuration with the Spring RabbitTemplate as shown below with the standard client library without much luck

    Code:
    channel.addConfirmListener(new ConfirmListener() {
                    @Override
                    public void handleAck(long l, boolean b) throws IOException {
                        System.err.println("ack "+l+ " "+ b);
                    }
    
                    @Override
                    public void handleNack(long l, boolean b) throws IOException {
                        System.err.println("nack "+l+ " "+ b);
                    }
                });
    I have setup the RabbitTemplate with publisher-confirms=true and have tried the following.

    Code:
        public void runWithSpring(){
          
            rabbitTemplate.setConfirmCallback(new RabbitTemplate.ConfirmCallback() {
                @Override
                public void confirm(CorrelationData correlationData, boolean b) {
                    System.err.println("confirmedMessage");
                }
            });
    
            rabbitTemplate.setReturnCallback(new RabbitTemplate.ReturnCallback() {
                @Override
                public void returnedMessage(Message message, int i, String s, String s1, String s2) {
                    System.err.println("Returned Message");
                  
                }
            });
            rabbitTemplate.convertAndSend("myqueue", "foriffo");
        }
    I was expecting my test to hit the Confirm callback. Any idea what I am missing?

  • #2
    Did you enable publisher confirms on the connection factory?

    http://static.springsource.org/sprin...#amqp-template

    Comment


    • #3
      Hello!
      I suggest you to take a look into Manual: http://static.springsource.org/sprin...ce/htmlsingle/ via search of word 'Confirms'.
      if you'll still have problem - you are welcome!
      But at a glance you don't provide 'correlationData'
      In othe words: try to use this one:
      Code:
      public void convertAndSend(String routingKey, final Object object, CorrelationData correlationData)
      Cheers,
      Artem

      Comment


      • #4
        Originally posted by Gary Russell View Post
        Did you enable publisher confirms on the connection factory?

        http://static.springsource.org/sprin...#amqp-template

        Here is my connection factory. I think I did it right.

        <rabbit:connection-factory id="connectionFactory" host="localhost" username="guest" password="guest" publisher-confirms="true" publisher-returns="true"/>

        Comment


        • #5
          I added the CorrelationData object as suggested, what am I supposed to use in the constructor for the id?

          I tried the following without better luck.

          Code:
              public void runWithSpring(){
                  System.err.println("begin test");
                  System.err.println(connectionFactory.isPublisherConfirms());
                  rabbitTemplate.setConfirmCallback(new RabbitTemplate.ConfirmCallback() {
                      @Override
                      public void confirm(CorrelationData correlationData, boolean b) {
                          System.err.println("confirmedMessage");
                      }
                  });
          
                  rabbitTemplate.setReturnCallback(new RabbitTemplate.ReturnCallback() {
                      @Override
                      public void returnedMessage(Message message, int i, String s, String s1, String s2) {
                          System.err.println("Returned Message");
          
                      }
                  });
                  rabbitTemplate.convertAndSend("dosomething", "key","foriffo", new CorrelationData("123"));
              }

          Comment


          • #6
            Well I knew it would be something silly, I totally glossed over that this was asynchronous and didn't have anything in my code to wait for a response so my Junit was ending immediately. Adding a loop confirmed that the message arrived and invoked my callback.

            Comment

            Working...
            X