Announcement Announcement Module
Collapse
No announcement yet.
programmatic RabbitTemplate configuration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    hi gary:
    sorry about not putting code in code quotes.
    the problem is this "stand-alone" library requires "pre-created" queues for a web-app. that's the whole reason to go into "programmatic" configuration.
    will you advice what i should look up so i can become a subscriber to the lifecycle monitor listener?

    thanks for your patience and help,
    -monish

    Comment


    • #17
      No problem - I suggest you take a look at the code in RabbitAdmin.afterPropertiesSet() - you'll see how he registers a class as a ConnectionListener, and how that is invoked to run the declarations whenever a new Connection is established.

      Comment


      • #18
        RE: programmatic RabbitTemplate configuration

        thanks gary for the pointers!
        i took a shortcut, in the init method i did this:
        Code:
        private void init()
            {
                isUsable = true;
                amqpTemplate = new RabbitTemplate(connectionFactory);
                replyContainer = new SimpleMessageListenerContainer(connectionFactory);
                context = new GenericApplicationContext();
                admin = new RabbitAdmin(connectionFactory);
                admin.setApplicationContext(context);
                admin.setAutoStartup(true);
                replyQueueName = "REPLY_QUEUE."+ UUID.randomUUID().toString();
                createReplyQueue();
            }
        ..and in createReplyQueue()
        Code:
         private void createReplyQueue()
            {
                declareQueue();
                replyContainer.setQueueNames(replyQueueName);
                replyContainer.setMessageListener(amqpTemplate);
                replyContainer.afterPropertiesSet();
                replyContainer.start();
            }
        
            private void declareQueue()    
            {
                boolean durable = false;
                boolean autoDelete = true;
                boolean exclusive = true;
                replyQueue = new Queue(replyQueueName,durable,exclusive,autoDelete);
                context.getBeanFactory().registerSingleton(replyQueueName, replyQueue);
                admin.afterPropertiesSet();
        
            }
        this works very well and passes all the tests. any potential overhead might be only due to creating GenericApplicationContext at initialization time. not sure if that's too much.
        RabbitAdmin is a constructor parameter and the manager now hands out pre-configured with a connectionFactory.
        The user is allowed to specify #of connections (for performance).

        when you get a chance, feel free to point as many errors/bugs/in-efficiencies with this code!
        best regards and thanks much,
        -cogitate

        Comment

        Working...
        X