You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "Preben.Asmussen" <pr...@dr.dk> on 2013/05/17 08:03:44 UTC

Best way for ScheduledBatchPollingConsumer to signal failure

Hi

I have worked on a consumer component that extends the
ScheduledBatchPollingConsumer, and want to signal when an error occurs
during connect to a remote resource (basic http). Atm any connect error will
be logged, but I want it to surface in jmx attribute like the
ExchangesFailed and LastExchangeFaliure..... attributes. This way monitoring
can pick up any failures and report it.
The problem is that to expose this as a jmx attribute it requires a
exchange, and since the error occurs while  connecting to the remote
resource (to poll and create exchanges) it is not possible.
Is there any examples to handle such feature ? eg. catch the exception and
create a 'failed exchange' manually, or ??

/Preben



--
View this message in context: http://camel.465427.n5.nabble.com/Best-way-for-ScheduledBatchPollingConsumer-to-signal-failure-tp5732703.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Best way for ScheduledBatchPollingConsumer to signal failure

Posted by "Preben.Asmussen" <pr...@dr.dk>.
Not working quite as expected The DefalultPollingConsumerPollStrategy loggs
the error as WARN, but i'm not seeing any failed exchages in jmx ??
Shouldn't the bridgeErrorHandler create an empty Exchange with the error
that gets picket up as failed ?
Running on camel v. 2.10.0

 07 Jun. 2013 - 08:01:14,231 WARN
org.apache.camel.impl.DefaultPollingConsumerPollStrategy [Consumer
Consumer[drupalqueue://message_export?consumer.bridgeErrorHandler=true&delay=120s&host=xxxx&&maxMessagesPerPoll=200&password=******&port=443&username=admin]
could not poll endpoint:
Endpoint[drupalqueue://message_export?consumer.bridgeErrorHandler=true&delay=120s&host=xxxx&maxMessagesPerPoll=200&password=******&port=443&username=admin]
caused by: Empty or non-JSON response]
dk.dr.drip.component.drupalqueue.client.HTTPException: Empty or non-JSON
response
	at
dk.dr.drip.component.drupalqueue.client.Client.singleRequest(Client.java:201)
	at dk.dr.drip.component.drupalqueue.client.Client.request(Client.java:115)
	at dk.dr.drip.component.drupalqueue.client.Client.get(Client.java:96)
	at dk.dr.drip.component.drupalqueue.client.Client.get(Client.java:86)
	at
org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:139)
	at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:94)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:440)
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:662)




--
View this message in context: http://camel.465427.n5.nabble.com/Best-way-for-ScheduledBatchPollingConsumer-to-signal-failure-tp5732703p5733978.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Best way for ScheduledBatchPollingConsumer to signal failure

Posted by "Preben.Asmussen" <pr...@dr.dk>.
Ahh. Just for the update. 
I was developing a custom component, and one has to remember 2 things to
support the BridgeErrorhandler.
1. call the configureConsumer in the Endoint.createConsumer method.
      public Consumer createConsumer(Processor processor) throws Exception {
		DrupalQueueConsumer drupalQueueConsumer = new DrupalQueueConsumer(this,
processor);
		configureConsumer(drupalQueueConsumer);
	
drupalQueueConsumer.setMaxMessagesPerPoll(configuration.getMaxMessagesPerPoll());
		return drupalQueueConsumer;
	}
This will attatch the BridgeErrorhander support

2. In the polling consumer catch Exceptions and call
getExceptionHandler().handleException("Error creating exchange", e);

        @Override
	protected int poll() throws Exception {
		// must reset for each poll
		shutdownRunningTask = null;
		pendingExchanges = 0;
		Messages messages = null;
		if (endpoint.getConfiguration().getTimeout() > 0) {
			try {
				messages = endpoint.getClient().get(getMaxMessagesPerPoll(),
endpoint.getConfiguration().getTimeout());
			} catch (HTTPException e) {
				getExceptionHandler().handleException("Error creating exchange", e);
				return 0;
			}
			LOG.trace("Receiving messages with request [messagePerPoll{}, timeout
{}]...", getMaxMessagesPerPoll(),
					endpoint.getConfiguration().getTimeout());
		}
		LOG.trace("Received {} messages", messages.getMessages().length);

		Queue<Exchange> exchanges = createExchanges(messages.getMessages());
		return processBatch(CastUtils.cast(exchanges));
	}

Then there will be created an dummy exchange with the exception and
everything works as expected.

 



--
View this message in context: http://camel.465427.n5.nabble.com/Best-way-for-ScheduledBatchPollingConsumer-to-signal-failure-tp5732703p5734056.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Best way for ScheduledBatchPollingConsumer to signal failure

Posted by "Preben.Asmussen" <pr...@dr.dk>.
Oh yeah - I seem to recall comething like that.



--
View this message in context: http://camel.465427.n5.nabble.com/Best-way-for-ScheduledBatchPollingConsumer-to-signal-failure-tp5732703p5732769.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Best way for ScheduledBatchPollingConsumer to signal failure

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You can use the bridge error handler option
http://camel.apache.org/why-does-my-file-consumer-not-pick-up-the-file-and-how-do-i-let-the-file-consumer-use-the-camel-error-handler.html

Then an empty exchange with the caused exception is routed, and your
error handler can detect and handle it, as if the error occurred
during routing.

On Fri, May 17, 2013 at 8:03 AM, Preben.Asmussen <pr...@dr.dk> wrote:
> Hi
>
> I have worked on a consumer component that extends the
> ScheduledBatchPollingConsumer, and want to signal when an error occurs
> during connect to a remote resource (basic http). Atm any connect error will
> be logged, but I want it to surface in jmx attribute like the
> ExchangesFailed and LastExchangeFaliure..... attributes. This way monitoring
> can pick up any failures and report it.
> The problem is that to expose this as a jmx attribute it requires a
> exchange, and since the error occurs while  connecting to the remote
> resource (to poll and create exchanges) it is not possible.
> Is there any examples to handle such feature ? eg. catch the exception and
> create a 'failed exchange' manually, or ??
>
> /Preben
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Best-way-for-ScheduledBatchPollingConsumer-to-signal-failure-tp5732703.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
www.camelone.org: The open source integration conference.

Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen