Results 1 to 4 of 4

Thread: RabbitMq plugin additional listeners

  1. #1
    Join Date
    Feb 2011
    Location
    Brighton, UK
    Posts
    9

    Question RabbitMq plugin additional listeners

    Hi guys,

    Peter if your reading, thanks for a great plugin.

    I have a small question regarding how to implement listeners to the connection.

    Currently if the rabbitmq server is down it throws an AlreadyClosedException,

    I want to catch this and send an email to notify an admin that we have a problem with the messaging.

    I Have tried wrapping the rabbitSend in a try catch block but no luck

    Also I noticed there is the ability to get info on the reason why it cant access the rabbitmq server using (from RabbitMQ API GUIDE)

    Code:
    connection.addShutdownListener(new ShutdownListener() {
        public void shutdownCompleted(ShutdownSignalException cause)
        {
            ...
        }
    });
    Is it also possible to recover from a AlreadyClosedException once the rabbitMq server has been restarted

    Basically how do you expose the connection and channels to my grails app so I can deal with them directly or is this functionality already in place and i am missing something.

    Thanks in advance

    Antony Jukes
    Last edited by ajukes; Jun 8th, 2011 at 01:42 PM. Reason: additional info

  2. #2
    Join Date
    Jun 2010
    Location
    London
    Posts
    304

    Default

    Getting hold of the connections and channels directly is tricky since these are created on demand by Spring AMQP. For the particular problem you want to solve, I suggest checking out the section on error handlers in the Spring AMQP user guide.

    Every service that has a
    Code:
    rabbitQueue
    or
    Code:
    rabbitSubscribe
    property will result in a bean called
    Code:
    <serviceName>_MessageListenerContainer
    . So, you just need to grab all beans with that suffix (probably in a BeanFactoryPostProcessor) and set their
    Code:
    errorHandler
    properties to your error handler bean.

    I would raise one or more issues if you would like extra features.

  3. #3
    Join Date
    Feb 2011
    Location
    Brighton, UK
    Posts
    9

    Default

    Thanks for the reply Peter,

    Sorry if I am being obtuse but how would you go about setting the errorHandler. I think I need to spend some time to understand the whole spring beans injection etc!

    I have one service called NotifyServerService, which is publishing messages using rabbit send (I also have a consumer in a different app which needs the same handling). Would you place it in resources.xml like such:


    Code:
    notifyServerService_MessageListenerContainer(SimpleMessageListenerContainer) {
            connectionFactory = ref("rabbitMQConnectionFactory")
            errorHandler = ref("myNewErrorHandler")
    }
    
    //This throws:
    //Failed to start bean 'notifyServerService_MessageListenerContainer'; nested exception is org.springframework.amqp.UncategorizedAmqpException: java.lang.IllegalArgumentException: Queue //name must not be null.
    I assume im kinda on the right tracks but i need to use the connectionFactory from the plugin and just add a listener to it. If i remove the connectionFactory line it complains that there is no connectionFactory.

    Thanks for the help

    Antony Jukes

  4. #4
    Join Date
    Jun 2010
    Location
    London
    Posts
    304

    Default

    The error handler can be set in a couple of ways. First, provide your own bean definition (as you do in the above example) and do a
    Code:
    errorHandler = ref("myErrorHandler")
    in the bean definition. Second, you could implement a BeanFactoryPostProcessor that sets the property. This is core Spring stuff, so I would look at the Spring user guide and Spring articles.

    That said, I think there is some confusion here. The
    Code:
    SimpleMessageListenerContainer
    class is only for AMQP consumers, not producers. The
    Code:
    rabbitSend()
    method uses an instance of
    Code:
    RabbitTemplate
    to send the messages. The method call itself should throw an exception that you can catch.

Tags for this Thread

Posting Permissions

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