Announcement Announcement Module
No announcement yet.
Heartbeat configuration prevents startup Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Heartbeat configuration prevents startup

    I noticed from AMQP-62 open bug there was not a direct way of setting the heartbeat, but it mentioned in the comments that it should be easy to reference a raw rabbit ConnectionFactory to accomplish this.

    I tried the following:

     <rabbit:connection-factory id="rabbitConnectionFactory" host="${}"  username="${rabbitmq.username}"
                                   port="${rabbitmq.port}" password="${rabbitmq.password}" virtual-host="/"
       <bean id="rabbitConn" class="com.rabbitmq.client.ConnectionFactory" p:requestedHeartbeat="10"
              p:host="${}" p:username="${rabbitmq.username}" p:port="${rabbitmq.port}"
              p:password="${rabbitmq.password}" p:virtualHost="/" p:connectionTimeout="1000"/>
    The application will not start up - it just hangs. In fact the unit tests will not pass, and also hangs - no messages.

    I have tried many variations on this - none work as long as I leave the "rabbitConn" bean in the configuration.

    If I remove (i.e. comment) the rabbitConn bean (and remove the associated "connection-factory" reference in the spring-amqp element), it all works, but now it does not have the heartbeat set.

    I have tried leaving the username, password, etc in the raw bean, or just in the spring-amqp bean, or both, nothing works. Any hints on how I reference a rabbitmq Connection in a way I can set the heartbeat (and have it work)?

    As a side note, the reason for the heartbeat is in our production system IT uses a load balancer setup for the rabbit. We have found, for our erlang applications, we need to have a heartbeat running or if their is a significant pause in messages on some queue, the load balancer will mess with the connection and rabbit does not handle the interruption in a way the clients can subsequently send or receive messages. I am having the same symptom on the production system that the erlang applications had until they set the heartbeat. It does not occur on setups that does not have the load balancer.

    This is running on Spring 3.1, Spring-Integration 2.1, RabbitMQ 2.6.0, Spring-amqp 1.0.0 client (with amqp 2.5.1 client jar from dependency)

  • #2
    I'm not that familiar with configuring Spring through xml config, but the backing ConnectionFactory for CachingConnectionFactory can only be set through ctor.

    Is there a way to use ctor parameters when declaring connection-factory? I am setting heartbeat without a problem, but using spring "java config" to pass preconfigured com.rabbitmq.client.ConnectionFactory to CachingConnectionFactory.

    @Import(value = Array[Class[_]](classOf[CommonApplicationConfiguration]))
    class AmqpApplicationConfiguration {
      // I manage the Amqp connections
      @Bean(destroyMethod = "destroy")
      def connectionFactory(rabbitMqConfiguration: RabbitMqConfiguration): ConnectionFactory = {
        val rabbitConnectionFactory = new com.rabbitmq.client.ConnectionFactory()
        new CachingConnectionFactory(rabbitConnectionFactory)


    • #3
      The namespace handler injects the referenced CF via the constructor.

      I just tried this with our sample, changed

          <rabbit:connection-factory id="connectionFactory" />

          <rabbit:connection-factory id="connectionFactory" connection-factory="rcf" />
          <bean id="rcf" class="com.rabbitmq.client.ConnectionFactory">
          	<property name="host" value="localhost"/>
          	<property name="requestedHeartbeat" value="10" />
      And everything worked fine.

      @gnuphie - can you attach a debug log?


      • #4
        Can I attach a debug log? That's what was so frustrating with this; it just hung - no log output.

        OTOH, the good news is your solution fixed it. The problem was the p namespace I was using (in fact I was prompted by Intellij IDEA to use it, because the namespace was in my xml header), did not work. I will have to look into that part of it, but once I used the old-style nested properties it worked fine. Darn me for trying to use a new-fangled whiz bang syntax.

        It seemed like this should have been this simple. Too bad there wasn't better indication of what spring didn't like in my configuration (or more likely I just didn't know where to look).