Results 1 to 8 of 8

Thread: Automatic startup of incoming gateway

Hybrid View

  1. #1

    Default 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. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,844

    Default

    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

  3. #3

    Default

    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();

  4. #4
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,844

    Default

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

  5. #5

    Default

    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"/>

  6. #6

    Default

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

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
  •