Results 1 to 10 of 18

Thread: programmatic RabbitTemplate configuration

Hybrid View

  1. #1
    Join Date
    Oct 2010
    Posts
    21

    Default programmatic RabbitTemplate configuration

    hi gary:
    what would be the java programmatic way to do the following spring-context:
    <rabbit:template id="amqpTemplate"
    connection-factory="connectionFactory" reply-queue="replies">
    <rabbit:reply-listener />
    </rabbit:template>

    is it enough to do the following:
    //Queue queueX
    RabbitTemplate template = new RabbitTemplate(connFactory);
    //queueX is declared using rabbit admin?
    template.setReplyQueue(queueX);

    is there anything to be done for setting a reply-listener as in the spring-context config?

    regards,
    -cogitate

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,036

    Default

    It's quite a lot more involved than that; you need to create and configure a SimpleMessageListenerContainer, and set the RabbitTemplate as its MessageListener.

    Probably the best place to start is to look at the TemplateParser.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  3. #3
    Join Date
    Oct 2010
    Posts
    21

    Default

    thanks gary! will do.
    in the meanwhile if i were to use the template as a prototype bean for configuring a template or maybe use @Configuration is there a way i can do the same thing?
    1. would like to configure template with a reply-queue
    2. would like to use connections configured with "N" channels (max)
    3. and of course, use a reply-listener...

  4. #4
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,036

    Default

    Hi Monish,

    Here's how to programmatically configure a RabbitTemplate to use a fixed reply queue with a reply listener container...

    Code:
    SimpleMessageListenerContainer replyContainer = new SimpleMessageListenerContainer(connectionFactory);
    replyContainer.setQueueNames("reply.queue");
    
    RabbitTemplate template = new RabbitTemplate(connectionFactory);
    template.setReplyQueue(new Queue("reply.queue"));
    
    replyContainer.setMessageListener(template);
    replyContainer.afterPropertiesSet();
    replyContainer.start();
    
    
    
    Object reply = template.convertSendAndReceive("test.exchange", "test.binding", "Hello, world!");
    Hope that helps.

    There is currently no way to limit the number of channels; the number of cached channels can be controlled on the CachingConnectionFactory.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  5. #5
    Join Date
    Oct 2010
    Posts
    21

    Default

    thanks Gary!
    this goes a long way in improving what i have today.
    many many thanks,
    -monish

  6. #6
    Join Date
    Oct 2010
    Posts
    21

    Default

    Hi Gary:
    sorry to bother you, but i have one more question. if i'd want to have control over #of connections how would i do that?
    let's say configuration params from user is :
    [1] # of connections = 2
    [2] # of channels(threads/reply_queues) = 6 ( executorservice threads per connection )
    for a total concurrency of 12. is it possible to specify this?

    kind regards,
    -cogitate

Posting Permissions

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