Results 1 to 4 of 4

Thread: Heartbeat configuration prevents startup

  1. #1
    Join Date
    Aug 2009
    Posts
    28

    Default 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:

    Code:
     <rabbit:connection-factory id="rabbitConnectionFactory" host="${rabbitmq.host}"  username="${rabbitmq.username}"
                                   port="${rabbitmq.port}" password="${rabbitmq.password}" virtual-host="/"
    connection-factory="rabbitConn"/>
    
       <bean id="rabbitConn" class="com.rabbitmq.client.ConnectionFactory" p:requestedHeartbeat="10"
              p:host="${rabbitmq.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. #2
    Join Date
    Jan 2012
    Posts
    24

    Default

    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.

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

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

    Default

    The namespace handler injects the referenced CF via the constructor.

    I just tried this with our sample, changed

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

    Code:
        <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" />
        </bean>
    And everything worked fine.

    @gnuphie - can you attach a debug log?
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  4. #4
    Join Date
    Aug 2009
    Posts
    28

    Default

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

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
  •