Results 1 to 6 of 6

Thread: Publisher Confirms with RabbitMQ

  1. #1
    Join Date
    May 2010
    Posts
    10

    Default 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. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,028

    Default

    Did you enable publisher confirms on the connection factory?

    http://static.springsource.org/sprin...#amqp-template
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    637

    Default

    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

  4. #4
    Join Date
    May 2010
    Posts
    10

    Default

    Quote 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"/>

  5. #5
    Join Date
    May 2010
    Posts
    10

    Default

    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"));
        }

  6. #6
    Join Date
    May 2010
    Posts
    10

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •