I have a batch (java application) with spring-rabbit 1.1.4 (and spring 3.1.2) for connection to rabbit (consumer), like this :
<bean class="org.springframework.amqp.support.converter.JsonMessageConverter" name="jsonMessageConverter">
<property name="classMapper">
<bean class="com.mydomain.amqp.mapper.CustomClassMapper"/>
</property>
</bean>
<rabbit:connection-factory id="connectionFactory"
host="${rabbitmq.host}"
port="${rabbitmq.port}"
virtual-host="${rabbitmq.vhost}"
username="${rabbitmq.username}"
password="${rabbitmq.password}"
/>
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" message-converter="jsonMessageConverter" />
In application, I use rabbit template like this :
@Value("${rabbitmq.exchange.name}")
private String exchange;
@Value("${rabbitmq.routing.key}")
private String routingKey;
@Autowired
private RabbitTemplate amqpTemplate;
@Override
public boolean sendMessage(BussinessMessage message) {
amqpTemplate.convertAndSend(exchange, routingKey, message);
return true;
}
I start batch in script shell with java command. It work well and all java code execute, but linux process keep alive because connection with rabbit keep alive. In rabbit manager UI, if I close connection, linux process terminate.
What I do wrong ? Thank !
When your job completes you can close the connection:
@Autowired
CachingConnectionFactory cachingConnectionFactory;
...
cachingConnectionFactory.resetConnection();
or
context.getBean(CachingConnectionFactory.class).resetConnection();
or simply close the application context when the job completes:
context.close();
Any one of these will shut down the connection.