I'm using SJMS (simple JMS) component for consuming messages from JMS broker
(e.g. ActiveMQ).
When I'm stopping Camel Context, I'm used to that consumers will stop
accepting new messages (in case JMS I would expect consumer will stop
reading new messages from broker and will finish only processing ones). But
it does not work for SJMS. When I stop camel context with SJMS consumer, it
keeps reading messages forever (as long as there are any present in broker
queue).
Am I misusing the SJMS component or is it a bug?
Here is the code I'm using for testing (I pre-fill ActiveMQ queue test with
100 messages for example):
public class Test {
public static void main(String[] args) throws Exception {
RouteBuilder rb = new RouteBuilder() {
@Override
public void configure() throws Exception {
from("sjms:queue:test?consumerCount=5")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws
Exception {
Thread.sleep(1000); // not to consume all
messages instantly
System.out.println("Processed message " +
exchange.getExchangeId());
}
});
}
};
CamelContext context = new DefaultCamelContext();
context.getShutdownStrategy().setTimeout(2 * 1000); // 2 seconds is
enough for already fetched messages
addJmsComponent(context);
context.addRoutes(rb);
System.out.println("=====> Starting context");
context.start();
Thread.sleep(5 * 1000); // Consume few messages at the beginning
System.out.println("=====> Stopping context");
context.stop();
System.out.println("=====> Context stopped"); // Will not get here
as long as there are any messages left in the queue
}
private static void addJmsComponent(CamelContext context) {
ConnectionFactory factory = new
ActiveMQConnectionFactory("tcp://localhost:61616");
ConnectionFactoryResource connResource = new
ConnectionFactoryResource(5, factory);
SjmsComponent comp = new SjmsComponent();
comp.setConnectionResource(connResource);
context.addComponent("sjms", comp);
}
}
--
View this message in context:
http://camel.465427.n5.nabble.com/CamelContext-stop-with-SJMS-consumer-does-not-stop-consuming-messages-from-broker-tp5777207.html
Sent from the Camel - Users mailing list archive at Nabble.com.