Reputation: 375
I have a producer which sends data to RabbitMQ(version 3.6.1). Previously I was using rabbitmq-client jar and the application was working fine.
Now I switched to spring-amqp 1.2.0 which is also successfully able to sends the data to RabbitMQ broker but the program never terminates. I have used following configuration @ Producer side.
<rabbit:connection-factory id="connectionFactory" host="localhost" port="5672" channel-cache-size="25" />
<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"/>
<rabbit:admin connection-factory="connectionFactory"/>
<rabbit:queue name="text_offline_queue"/>
I'm loading above configuration by using below code:
public static int send(String message) {
ClassPathXmlApplicationContext ctx = null;
try {
ctx = new ClassPathXmlApplicationContext(
"rabbitContext.xml");
}catch (Exception ex){
ex.printStackTrace();
System.out.println(
"Error while open/read the rabbitmq context file");
}
AmqpTemplate template = ctx.getBean(AmqpTemplate.class);
template.send(QUEUE_NAME, new Message(message.getBytes(), new MessageProperties()));
return 1;
}
}
And program never terminates(See attached image).
Thanks in advance
Upvotes: 0
Views: 164
Reputation: 174554
First, 1.2 is very old; the current version is 1.6.3.
The connection factory keeps a connection open for efficiency.
When you want to terminate your application, call ctx.close()
and the application context will be shut down.
Upvotes: 1