You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by jamie3 <ja...@gmail.com> on 2016/01/29 20:24:33 UTC

Shutting down route with jms

I have a Camel route as follows:

onException(EmitException.class)
			.maximumRedeliveries(3)
			.handled(true)
			.delay(3000)
			.process(new ShutdownRoute("Failed to send email"))
			.end();

from("jms:queue:someQueue?acknowledgementModeName=CLIENT_ACKNOWLEDGE")
to(myProcessor);

class ShutdownRoute implements Processor {
        @Override
	public void process(Exchange exg) throws Exception {
		LOG.fatal("Shutting down service: " + message);
		exg.getContext().stop();
	}
}


myProcessor contains logic to send the message to another system. If that
system becomes unavailable I want to shutdown the camel route and stop
listening for JMS messages.

The JMS connection factory fetched from JNDI using WebSphere Application
Server and MQ.

I do receive the call back for ShutdownRoute however when I stop the camel
context, MQ shows that the JMS connections are still active. I've confirmed
that I cannot send anymore messages to the queue, thus the connection
factory is connected to MQ but not accepting messages.

Even if I stop the EAR file in WAS (which contains my camel route) the jms
connections are still active.

Also since I have CLIENT_ACKNOWLEDGE mode enabled the messages are placed
back onto the queue only when I restart WAS.

What I am trying to do is completely shutdown Camel and the connections to
MQ via JMS. Is this possible? Am I implementing this correctly, or is there
a better way?




--
View this message in context: http://camel.465427.n5.nabble.com/Shutting-down-route-with-jms-tp5777011.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Shutting down route with jms

Posted by jamie3 <ja...@gmail.com>.
Thanks Claus, since my original post I tried shutting it down from another
thread. I can see 9 out of 10 JMSConsumer threads being shut down. It's only
until I shutdown WAS that the message is put back on the Queue.

Luckily I have the source code, so I'll do some more digging and report
back!



--
View this message in context: http://camel.465427.n5.nabble.com/Shutting-down-route-with-jms-tp5777011p5777057.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Shutting down route with jms

Posted by jamie3 <ja...@gmail.com>.
A bit of an update. I changed the code to use control bus. The logs show that
control bus is signaling to the camel context to shut down, however when
inspecting the debug thread, the Camel JMSConsumer class is still running,
as shown below with 1 inflight and pending exchange. My processor logic will
not mark the JMS message as acknowledged. I haven't looked at whether camel
is rolling back the JMS transaction. It appears the JMSConsumer thread is
waiting for the transaction to be rolled back.

2016-02-01 12:53:21 ERROR DeliveryRouter:145 - Failed to send email.
Shutting down delivery engine
2016-02-01 12:53:21 INFO  DefaultCamelContext:1833 - Apache Camel 2.13.0
(CamelContext: camel-1) is shutting down
2016-02-01 12:53:21 INFO  DefaultShutdownStrategy:173 - Starting to graceful
shutdown 1 routes (timeout 10 seconds)
2016-02-01 12:53:21 INFO  DefaultShutdownStrategy:573 - Waiting as there are
still 1 inflight and pending exchanges to complete, timeout in 10 seconds.
2016-02-01 12:53:22 INFO  DefaultShutdownStrategy:573 - Waiting as there are
still 1 inflight and pending exchanges to complete, timeout in 9 seconds.
2016-02-01 12:53:23 INFO  DefaultShutdownStrategy:573 - Waiting as there are
still 1 inflight and pending exchanges to complete, timeout in 8 seconds.
2016-02-01 12:53:24 INFO  DefaultShutdownStrategy:573 - Waiting as there are
still 1 inflight and pending exchanges to complete, timeout in 7 seconds.
2016-02-01 12:53:25 INFO  DefaultShutdownStrategy:573 - Waiting as there are
still 1 inflight and pending exchanges to complete, timeout in 6 seconds.
2016-02-01 12:53:26 INFO  DefaultShutdownStrategy:573 - Waiting as there are
still 1 inflight and pending exchanges to complete, timeout in 5 seconds.
2016-02-01 12:53:27 INFO  DefaultShutdownStrategy:573 - Waiting as there are
still 1 inflight and pending exchanges to complete, timeout in 4 seconds.
2016-02-01 12:53:28 INFO  DefaultShutdownStrategy:573 - Waiting as there are
still 1 inflight and pending exchanges to complete, timeout in 3 seconds.
2016-02-01 12:53:29 INFO  DefaultShutdownStrategy:573 - Waiting as there are
still 1 inflight and pending exchanges to complete, timeout in 2 seconds.
2016-02-01 12:53:30 INFO  DefaultShutdownStrategy:573 - Waiting as there are
still 1 inflight and pending exchanges to complete, timeout in 1 seconds.
2016-02-01 12:53:31 WARN  DefaultShutdownStrategy:202 - Timeout occurred.
Forcing the routes to be shutdown now.
2016-02-01 12:53:31 WARN  DefaultShutdownStrategy:581 - Interrupted while
waiting during graceful shutdown, will force shutdown now.
2016-02-01 12:53:31 INFO  DefaultShutdownStrategy:610 - Route: route1
shutdown complete, was consuming from:
Endpoint[mq://queue:ENS.NOTIFICATION.Q?acknowledgementModeName=CLIENT_ACKNOWLEDGE&concurrentConsumers=10]


.

		// 10 threads used to connect to IBM MQ
		// If messages are successfully sent to email server we will commit the
transaction, otherwise rollback
		// to MQ and shutdown the route if fails more than 3 times in a single
exchange
		String props =
		"?concurrentConsumers=10" +
		"&acknowledgementModeName=CLIENT_ACKNOWLEDGE";
		
		Endpoint mq = endpoint("mq:queue:ENS.NOTIFICATION.Q" + props);
		Endpoint shutdownRoute =
endpoint("controlbus:language:simple?async=true");
		
		// wait 30 seconds
		getContext().getShutdownStrategy().setTimeout(10);
		getContext().getShutdownStrategy().setSuppressLoggingOnTimeout(true);
		
		onException(EmitException.class)
			.maximumRedeliveries(2)
			.handled(false)
			.delay(3000)
			.log(LoggingLevel.ERROR, "Failed to send email. Shutting down delivery
engine")
			.setBody(simple("${camelContext.stop()}"))
			.to(shutdownRoute)
			.end();
		
		// Routing logic for processing the message
		from(mq)
		.id("delivery")
		.process(messageHandler);



--
View this message in context: http://camel.465427.n5.nabble.com/Shutting-down-route-with-jms-tp5777011p5777113.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Shutting down route with jms

Posted by jamie3 <ja...@gmail.com>.
Thanks quinn! I'll try this out!

On Sat, Jan 30, 2016 at 10:30 AM, Quinn Stevenson [via Camel] <
ml-node+s465427n5777058h64@n5.nabble.com> wrote:

> I normally use the ControlBus EIP (
> http://camel.apache.org/controlbus.html <
> http://camel.apache.org/controlbus.html> ) for this kind of thing - then
> I don’t have to write any custom processors or other supporting code.
>
>
> > On Jan 30, 2016, at 12:16 AM, Claus Ibsen <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=5777058&i=0>> wrote:
> >
> > See this FAQ
> > http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html
> >
> > On Fri, Jan 29, 2016 at 8:24 PM, jamie3 <[hidden email]
> <http:///user/SendEmail.jtp?type=node&node=5777058&i=1>> wrote:
> >> I have a Camel route as follows:
> >>
> >> onException(EmitException.class)
> >>                        .maximumRedeliveries(3)
> >>                        .handled(true)
> >>                        .delay(3000)
> >>                        .process(new ShutdownRoute("Failed to send
> email"))
> >>                        .end();
> >>
> >> from("jms:queue:someQueue?acknowledgementModeName=CLIENT_ACKNOWLEDGE")
> >> to(myProcessor);
> >>
> >> class ShutdownRoute implements Processor {
> >>        @Override
> >>        public void process(Exchange exg) throws Exception {
> >>                LOG.fatal("Shutting down service: " + message);
> >>                exg.getContext().stop();
> >>        }
> >> }
> >>
> >>
> >> myProcessor contains logic to send the message to another system. If
> that
> >> system becomes unavailable I want to shutdown the camel route and stop
> >> listening for JMS messages.
> >>
> >> The JMS connection factory fetched from JNDI using WebSphere
> Application
> >> Server and MQ.
> >>
> >> I do receive the call back for ShutdownRoute however when I stop the
> camel
> >> context, MQ shows that the JMS connections are still active. I've
> confirmed
> >> that I cannot send anymore messages to the queue, thus the connection
> >> factory is connected to MQ but not accepting messages.
> >>
> >> Even if I stop the EAR file in WAS (which contains my camel route) the
> jms
> >> connections are still active.
> >>
> >> Also since I have CLIENT_ACKNOWLEDGE mode enabled the messages are
> placed
> >> back onto the queue only when I restart WAS.
> >>
> >> What I am trying to do is completely shutdown Camel and the connections
> to
> >> MQ via JMS. Is this possible? Am I implementing this correctly, or is
> there
> >> a better way?
> >>
> >>
> >>
> >>
> >> --
> >> View this message in context:
> http://camel.465427.n5.nabble.com/Shutting-down-route-with-jms-tp5777011.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
>
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://camel.465427.n5.nabble.com/Shutting-down-route-with-jms-tp5777011p5777058.html
> To unsubscribe from Shutting down route with jms, click here
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5777011&code=amFtaWUzQGdtYWlsLmNvbXw1Nzc3MDExfDE2Mjk2MjEyNTg=>
> .
> NAML
> <http://camel.465427.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>



-- 
Jamie




--
View this message in context: http://camel.465427.n5.nabble.com/Shutting-down-route-with-jms-tp5777011p5777059.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Shutting down route with jms

Posted by Quinn Stevenson <qu...@pronoia-solutions.com>.
I normally use the ControlBus EIP ( http://camel.apache.org/controlbus.html <http://camel.apache.org/controlbus.html> ) for this kind of thing - then I don’t have to write any custom processors or other supporting code.


> On Jan 30, 2016, at 12:16 AM, Claus Ibsen <cl...@gmail.com> wrote:
> 
> See this FAQ
> http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html
> 
> On Fri, Jan 29, 2016 at 8:24 PM, jamie3 <ja...@gmail.com> wrote:
>> I have a Camel route as follows:
>> 
>> onException(EmitException.class)
>>                        .maximumRedeliveries(3)
>>                        .handled(true)
>>                        .delay(3000)
>>                        .process(new ShutdownRoute("Failed to send email"))
>>                        .end();
>> 
>> from("jms:queue:someQueue?acknowledgementModeName=CLIENT_ACKNOWLEDGE")
>> to(myProcessor);
>> 
>> class ShutdownRoute implements Processor {
>>        @Override
>>        public void process(Exchange exg) throws Exception {
>>                LOG.fatal("Shutting down service: " + message);
>>                exg.getContext().stop();
>>        }
>> }
>> 
>> 
>> myProcessor contains logic to send the message to another system. If that
>> system becomes unavailable I want to shutdown the camel route and stop
>> listening for JMS messages.
>> 
>> The JMS connection factory fetched from JNDI using WebSphere Application
>> Server and MQ.
>> 
>> I do receive the call back for ShutdownRoute however when I stop the camel
>> context, MQ shows that the JMS connections are still active. I've confirmed
>> that I cannot send anymore messages to the queue, thus the connection
>> factory is connected to MQ but not accepting messages.
>> 
>> Even if I stop the EAR file in WAS (which contains my camel route) the jms
>> connections are still active.
>> 
>> Also since I have CLIENT_ACKNOWLEDGE mode enabled the messages are placed
>> back onto the queue only when I restart WAS.
>> 
>> What I am trying to do is completely shutdown Camel and the connections to
>> MQ via JMS. Is this possible? Am I implementing this correctly, or is there
>> a better way?
>> 
>> 
>> 
>> 
>> --
>> View this message in context: http://camel.465427.n5.nabble.com/Shutting-down-route-with-jms-tp5777011.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: Shutting down route with jms

Posted by Claus Ibsen <cl...@gmail.com>.
See this FAQ
http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html

On Fri, Jan 29, 2016 at 8:24 PM, jamie3 <ja...@gmail.com> wrote:
> I have a Camel route as follows:
>
> onException(EmitException.class)
>                         .maximumRedeliveries(3)
>                         .handled(true)
>                         .delay(3000)
>                         .process(new ShutdownRoute("Failed to send email"))
>                         .end();
>
> from("jms:queue:someQueue?acknowledgementModeName=CLIENT_ACKNOWLEDGE")
> to(myProcessor);
>
> class ShutdownRoute implements Processor {
>         @Override
>         public void process(Exchange exg) throws Exception {
>                 LOG.fatal("Shutting down service: " + message);
>                 exg.getContext().stop();
>         }
> }
>
>
> myProcessor contains logic to send the message to another system. If that
> system becomes unavailable I want to shutdown the camel route and stop
> listening for JMS messages.
>
> The JMS connection factory fetched from JNDI using WebSphere Application
> Server and MQ.
>
> I do receive the call back for ShutdownRoute however when I stop the camel
> context, MQ shows that the JMS connections are still active. I've confirmed
> that I cannot send anymore messages to the queue, thus the connection
> factory is connected to MQ but not accepting messages.
>
> Even if I stop the EAR file in WAS (which contains my camel route) the jms
> connections are still active.
>
> Also since I have CLIENT_ACKNOWLEDGE mode enabled the messages are placed
> back onto the queue only when I restart WAS.
>
> What I am trying to do is completely shutdown Camel and the connections to
> MQ via JMS. Is this possible? Am I implementing this correctly, or is there
> a better way?
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Shutting-down-route-with-jms-tp5777011.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: Shutting down route with jms

Posted by jamie3 <ja...@gmail.com>.
Further investigation it seems the JMS Consumer threads are not being
shutdown and the Camel logger is outputting the following:


[1/29/16 15:04:59:785 MST] 00000039 SystemOut     O 2016-01-29 15:04:59 WARN 
DefaultShutdownStrategy:202 - Timeout occurred. Forcing the routes to be
shutdown now.
[1/29/16 15:04:59:786 MST] 00000044 SystemOut     O 2016-01-29 15:04:59 WARN 
DefaultShutdownStrategy:581 - Interrupted while waiting during graceful
shutdown, will force shutdown now.
[1/29/16 15:05:24:041 MST] 00000045 SystemOut     O 2016-01-29 15:05:24
FATAL ShutdownRoute:21 - Shutting down delivery engine: Failed to send email
[1/29/16 15:07:20:269 MST] 0000003f SystemOut     O 2016-01-29 15:07:20 WARN 
DefaultShutdownStrategy:202 - Timeout occurred. Forcing the routes to be
shutdown now.
[1/29/16 15:07:20:270 MST] 00000046 SystemOut     O 2016-01-29 15:07:20 WARN 
DefaultShutdownStrategy:581 - Interrupted while waiting during graceful
shutdown, will force shutdown now


Seems like the thread is blocked and likely causing camel to block as well.



--
View this message in context: http://camel.465427.n5.nabble.com/Shutting-down-route-with-jms-tp5777011p5777018.html
Sent from the Camel - Users mailing list archive at Nabble.com.