Announcement Announcement Module
No announcement yet.
RabbitMq plugin additional listeners Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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)

    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, 01:42 PM. Reason: additional info

  • #2
    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
    property will result in a bean called
    . So, you just need to grab all beans with that suffix (probably in a BeanFactoryPostProcessor) and set their
    properties to your error handler bean.

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


    • #3
      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:

      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
        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
        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
        class is only for AMQP consumers, not producers. The
        method uses an instance of
        to send the messages. The method call itself should throw an exception that you can catch.