You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by d1x <zd...@gmail.com> on 2016/02/04 11:03:04 UTC

CamelContext stop with SJMS consumer does not stop consuming messages from broker

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.

Re: CamelContext stop with SJMS consumer does not stop consuming messages from broker

Posted by d1x <zd...@gmail.com>.
Thank you for your reply.
I thought that it may be bug but I wanted to be sure before I report it.
Reported under: https://issues.apache.org/jira/browse/CAMEL-9567



--
View this message in context: http://camel.465427.n5.nabble.com/CamelContext-stop-with-SJMS-consumer-does-not-stop-consuming-messages-from-broker-tp5777207p5777251.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CamelContext stop with SJMS consumer does not stop consuming messages from broker

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Feb 4, 2016 at 6:13 PM, jnk <xn...@gmail.com> wrote:
> We are using camel-sjms 2.15.2 but it can be reproduced with 2.16.2, too.
>

Okay sounds like the suspend opertation on the consumer does not stop
the jms listener. You are welcome to log a JIRA so we get this looked
into and fixed.
http://camel.apache.org/support.html

>
> Claus Ibsen-2 wrote
>> What version of Camel do you use?
>>
>> On Thu, Feb 4, 2016 at 11:03 AM, d1x &lt;
>
>> zdenek.obst@
>
>> &gt; wrote:
>>> 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.
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> http://davsclaus.com @davsclaus
>> Camel in Action 2: https://www.manning.com/ibsen2
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/CamelContext-stop-with-SJMS-consumer-does-not-stop-consuming-messages-from-broker-tp5777207p5777223.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: CamelContext stop with SJMS consumer does not stop consuming messages from broker

Posted by jnk <xn...@gmail.com>.
We are using camel-sjms 2.15.2 but it can be reproduced with 2.16.2, too.


Claus Ibsen-2 wrote
> What version of Camel do you use?
> 
> On Thu, Feb 4, 2016 at 11:03 AM, d1x &lt;

> zdenek.obst@

> &gt; wrote:
>> 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.
> 
> 
> 
> -- 
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2





--
View this message in context: http://camel.465427.n5.nabble.com/CamelContext-stop-with-SJMS-consumer-does-not-stop-consuming-messages-from-broker-tp5777207p5777223.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CamelContext stop with SJMS consumer does not stop consuming messages from broker

Posted by Claus Ibsen <cl...@gmail.com>.
What version of Camel do you use?

On Thu, Feb 4, 2016 at 11:03 AM, d1x <zd...@gmail.com> wrote:
> 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.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: CamelContext stop with SJMS consumer does not stop consuming messages from broker

Posted by d1x <zd...@gmail.com>.
One more thing to mention, I forgot that timeout for shutdown strategy is in
seconds (not millis).
So when timeout occurs, it stops reading new messages. 
Anyway I would still expect the consumer to stop reading NEW messages from
broker instantly after context stop - not after timeout.



--
View this message in context: http://camel.465427.n5.nabble.com/CamelContext-stop-with-SJMS-consumer-does-not-stop-consuming-messages-from-broker-tp5777207p5777208.html
Sent from the Camel - Users mailing list archive at Nabble.com.