Announcement Announcement Module
Collapse
No announcement yet.
Automatic startup of incoming gateway Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Automatic startup of incoming gateway

    Hello,

    I have an Amqp gateway server application based on a mix of annotations and xml configuration. As soon as the application starts and Spring gets initialized, it connects to RabbitMQ and my gateway starts listening for messages.

    I would like to have a bit more control over when this takes place, since the connection parameters aren't always known at startup.

    What's the recommended way of doing this?

  • #2
    You can set the 'autoStartup' property to false on the gateway. It is true by default. If false, then you have to call start() at some point explicitly.

    HTH,
    Mark

    Comment


    • #3
      Thanks Mark, now my gateway doesn't start automatically.

      However, I also need to be able to set the connection parameters before starting the gateway. When I use the following Spring config, it doesn't appear as if I can change for example the username before calling start() on the gateway:

      Code:
      	<bean id="rcf" class="com.rabbitmq.client.ConnectionFactory">
      		<property name="requestedHeartbeat" value="10"/>
      	</bean>
      	
      	<rabbit:connection-factory id="connectionFactory"
      		port="${ei.messaging.amqp.portnumber}"
      		host="${ei.messaging.amqp.servername}"
      		username="${ei.messaging.amqp.username}"
      		password="${ei.messaging.amqp.password}"
      		connection-factory="rcf"
      	/>
      
      	<rabbit:admin connection-factory="connectionFactory" auto-startup="false"/>
      The server startup code:


      Code:
      		AmqpInboundGateway amqpInboundGateway = spring.getBean("amqpInboundGateway",AmqpInboundGateway.class);
      		amqpInboundGateway.setReplyTimeout(4000);
      		
      		ConnectionFactory rcf = spring.getBean("rcf", ConnectionFactory.class);
      		rcf.setUsername("xxxxxxx");
      		
      		// Still tries to connect with the username configured in Spring xml...
      		amqpInboundGateway.start();

      Comment


      • #4
        You should be able to change the username. Can you show the excerpt where you initialize the rcf instance?

        Comment


        • #5
          The rcf instance is initialized like this:

          Code:
          <bean id="rcf" class="com.rabbitmq.client.ConnectionFactory">
          		<property name="requestedHeartbeat" value="10"/>
          	</bean>
          	
          	<rabbit:connection-factory id="connectionFactory"
          		port="${ei.messaging.amqp.portnumber}"
          		host="${ei.messaging.amqp.servername}"
          		username="${ei.messaging.amqp.username}"
          		password="${ei.messaging.amqp.password}"
          		connection-factory="rcf"
          	/>
          
          	<rabbit:admin connection-factory="connectionFactory" auto-startup="false"/>

          Comment


          • #6
            (The reason for having both an rcf declaration and the rabbit:connection-factory tag is because I wanted the convenience and readability of the namespace tag but also the ability to set explicit details such as heartbeat, which I don't think can be set on the namespace tag)

            Comment


            • #7
              I see. Can you try grabbing the "connectionFactory" bean within your initialization code in order to set the username on that instead of the "rcf" bean?

              Comment


              • #8
                Well, if I make the assumption that what I get back from a <rabbit:connection-factory> is an instance of AbstractConnectionFactory (the ConnectionFactory has no setter methods), I can set the username like this:

                Code:
                AbstractConnectionFactory connectionFactory = spring.getBean("connectionFactory", AbstractConnectionFactory.class);
                connectionFactory.setUsername("xxxx");
                However, this does not seem to work either. As soon as the gateway.start() method is called, it uses the connection parameters originally supplied in the Spring XML configuration.

                Comment

                Working...
                X