Spring AMQP
  1. Spring AMQP
  2. AMQP-72

Add receive-and-reply convenience to RabbitTemplate

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Complete
    • Affects Version/s: None
    • Fix Version/s: 1.3.0.M1
    • Component/s: Core
    • Labels:

      Description

      RabbitTemplate has a producer send-and-receive convenience (unlike the JMS cases), but it is pretty hard to use without the mirror image for the consumer.

        Activity

        Show
        Artem Bilan added a comment - PR: https://github.com/spring-projects/spring-amqp/pull/138
        Hide
        Pulkit Singhal added a comment -

        I used 1.3.0.BUILD-SNAPSHOT artifact built from commit [2589e58] like so:

                    String queueName = "blah";
                    rabbitAdmin.declareQueue(new Queue(queueName, true));
                    rabbitTemplate.receiveAndReply(
                            queueName,
                            new ReceiveAndReplyCallback<RequestDelegate, ResponseDelegate>() {
                                @Override
                                public ResponseDelegate handle(RequestDelegate requestDelegate) {
                                    System.out.println("RABBIT PAYLOAD:\n" + requestDelegate.toString());
                                    ResponseDelegate responseDelegate =
                                            new ResponseDelegate(200, null,"No soup for you!"); // default reply
                                    return responseDelegate;
                                }
                            });
        

        in order to send back a dummy message to the producer.

        On the producer side I am using 1.2.0.M1 which gets the message but then somewhere along the line ... it trips-up with a NPE (NullPointerException) on Line 790 of RabbitTemplate class. I hope the links to the eclipse debug screenshots are self-explanatory ... the correlation id is null.
        https://www.dropbox.com/s/0i1xx71ygv4eci3/Screen%20Shot%202013-12-21%20at%203.13.00%20PM.png
        https://www.dropbox.com/s/rji3ylf7ym1f3gv/Screen%20Shot%202013-12-21%20at%203.13.06%20PM.png

        Show
        Pulkit Singhal added a comment - I used 1.3.0.BUILD-SNAPSHOT artifact built from commit [2589e58] like so: String queueName = "blah" ; rabbitAdmin.declareQueue( new Queue(queueName, true )); rabbitTemplate.receiveAndReply( queueName, new ReceiveAndReplyCallback<RequestDelegate, ResponseDelegate>() { @Override public ResponseDelegate handle(RequestDelegate requestDelegate) { System .out.println( "RABBIT PAYLOAD:\n" + requestDelegate.toString()); ResponseDelegate responseDelegate = new ResponseDelegate(200, null , "No soup for you!" ); // default reply return responseDelegate; } }); in order to send back a dummy message to the producer. On the producer side I am using 1.2.0.M1 which gets the message but then somewhere along the line ... it trips-up with a NPE (NullPointerException) on Line 790 of RabbitTemplate class. I hope the links to the eclipse debug screenshots are self-explanatory ... the correlation id is null. https://www.dropbox.com/s/0i1xx71ygv4eci3/Screen%20Shot%202013-12-21%20at%203.13.00%20PM.png https://www.dropbox.com/s/rji3ylf7ym1f3gv/Screen%20Shot%202013-12-21%20at%203.13.06%20PM.png
        Hide
        Pulkit Singhal added a comment -

        Probably the logic for something like the postProcessResponse from MessageListenerAdapter which "sets the response's correlation id to the request message's correlation id, if any" ... isn't wired into the receiveAndReply* methods ... yet?

        Show
        Pulkit Singhal added a comment - Probably the logic for something like the postProcessResponse from MessageListenerAdapter which "sets the response's correlation id to the request message's correlation id, if any" ... isn't wired into the receiveAndReply* methods ... yet?
        Hide
        Pulkit Singhal added a comment -

        So instead of:

        if (reply != null) {
        	Address replyTo = replyToAddressCallback.getReplyToAddress(message, reply);
        	RabbitTemplate.this.doSend(channel, replyTo.getExchangeName(), replyTo.getRoutingKey(),
        			RabbitTemplate.this.convertMessageIfNecessary(reply), null);
        }
        

        Maybe something like:

        if (reply != null) {
        	Address replyTo = replyToAddressCallback.getReplyToAddress(message, reply);
        	Message replyAsMessage = RabbitTemplate.this.convertMessageIfNecessary(reply);
        	RabbitTemplate.this.postProcessResponse(message, replyAsMessage);
        	RabbitTemplate.this.doSend(channel, replyTo.getExchangeName(), replyTo.getRoutingKey(),
        			replyAsMessage, null);
        }
        
        Show
        Pulkit Singhal added a comment - So instead of: if (reply != null ) { Address replyTo = replyToAddressCallback.getReplyToAddress(message, reply); RabbitTemplate. this .doSend(channel, replyTo.getExchangeName(), replyTo.getRoutingKey(), RabbitTemplate. this .convertMessageIfNecessary(reply), null ); } Maybe something like: if (reply != null ) { Address replyTo = replyToAddressCallback.getReplyToAddress(message, reply); Message replyAsMessage = RabbitTemplate. this .convertMessageIfNecessary(reply); RabbitTemplate. this .postProcessResponse(message, replyAsMessage); RabbitTemplate. this .doSend(channel, replyTo.getExchangeName(), replyTo.getRoutingKey(), replyAsMessage, null ); }
        Hide
        Artem Bilan added a comment -

        Good catch, Pulkit!
        You are right: `correlationId` has be covered too.
        So, it is pushed to PR https://github.com/spring-projects/spring-amqp/pull/138
        You can provide your feedbacks in PRs as well.

        Thank you for your contribution!
        Excellent!

        Show
        Artem Bilan added a comment - Good catch, Pulkit! You are right: `correlationId` has be covered too. So, it is pushed to PR https://github.com/spring-projects/spring-amqp/pull/138 You can provide your feedbacks in PRs as well. Thank you for your contribution! Excellent!
        Hide
        Pulkit Singhal added a comment -

        Hello Artem,

        I was building your github source to my local maven repo until recently but 1.3.0.BUILD-SNAPSHOT was published on Jan 3rd here:
        http://repo.springsource.org/libs-snapshot/org/springframework/amqp/spring-rabbit/1.3.0.BUILD-SNAPSHOT/
        and my maven build picked up on this.

        The interesting part is that org.springframework.amqp.core.ReceiveAndReplyCallback cannot be found in the snapshot release published on Jan 3rd. Is it simply not merged in there yet or did you change any names for your implementation class recently?

        Show
        Pulkit Singhal added a comment - Hello Artem, I was building your github source to my local maven repo until recently but 1.3.0.BUILD-SNAPSHOT was published on Jan 3rd here: http://repo.springsource.org/libs-snapshot/org/springframework/amqp/spring-rabbit/1.3.0.BUILD-SNAPSHOT/ and my maven build picked up on this. The interesting part is that org.springframework.amqp.core.ReceiveAndReplyCallback cannot be found in the snapshot release published on Jan 3rd. Is it simply not merged in there yet or did you change any names for your implementation class recently?
        Hide
        Artem Bilan added a comment -

        No-no. I wasn't merged yet. You should pick my branch up one more time and rebuild it again.
        However, I think it will be merged on Monday, so it really will be avaliable from from our repo in the 1.3.0.BUILD-SNAPSHOT

        Show
        Artem Bilan added a comment - No-no. I wasn't merged yet. You should pick my branch up one more time and rebuild it again. However, I think it will be merged on Monday, so it really will be avaliable from from our repo in the 1.3.0.BUILD-SNAPSHOT
        Hide
        Gary Russell added a comment -

        Merged, but there was a failed test on the CI build...

        https://build.springsource.org/artifact/AMQP-MASTER/JOB1/build-149/Test-Results/spring-rabbit/build/reports/tests/index.html

        6 replies were null due to missing correlation data...

        2014-01-05 11:30:42,765 ERROR SimpleAsyncTaskExecutor-1 [org.springframework.amqp.rabbit.core.RabbitTemplate] - <No correlation header in reply>

        Notice that the seventh message has correlation data in header 'CorrelationKey'.

        This is because the key was set after the launch of the first 10 execs.

        Moved the setting of the key.

        Show
        Gary Russell added a comment - Merged, but there was a failed test on the CI build... https://build.springsource.org/artifact/AMQP-MASTER/JOB1/build-149/Test-Results/spring-rabbit/build/reports/tests/index.html 6 replies were null due to missing correlation data... 2014-01-05 11:30:42,765 ERROR SimpleAsyncTaskExecutor-1 [org.springframework.amqp.rabbit.core.RabbitTemplate] - <No correlation header in reply> Notice that the seventh message has correlation data in header 'CorrelationKey'. This is because the key was set after the launch of the first 10 execs. Moved the setting of the key.
        Hide
        Gary Russell added a comment -

        Merged

        Show
        Gary Russell added a comment - Merged

          People

          • Assignee:
            Artem Bilan
            Reporter:
            Dave Syer
          • Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: