2016-11-15 76 views
0

我遇到了Apache Camel(2.15.2)中的無限循環問題。下面顯示的路線在正常情況下工作正常。但是,在極少數情況下,會創建一個消耗所有CPU的無限循環。我不確定是什麼原因造成的,但我有一種感覺,它與在路由上產生消息的遠程應用程序關閉時有關。Apache Camel無限循環出錯

代碼來配置路由(使用RouteBuilder):

@Override 
public void configure() throws Exception { 
    errorHandler(deadLetterChannel(
     "file:messages/myRoute?fileName=${date:now:yyyyMMdd-HHmm-ssSSS}.xml") 
     .useOriginalMessage() 
     .maximumRedeliveries(10) 
     .delayPattern("1:5000"); 
    onException(java.net.ConnectException.class).handled(true); 

    fromF("myEndpoint") 
     .routeId("myRoute") 
     .bean(messageHandler, "process"); 
} 

這個bean處理消息:

public void process(final String message) { 
    final MyMessage message = (MyMessage) marshaller.getXStream().fromXML(message); 
    ...some processing... 
    producer.sendBody("anotherEndpoint", marshaller.getXStream().toXML(message)); 
} 

我做了幾個線程轉儲,他們都表現出與此類似的東西:

at com.thoughtworks.xstream.core.DefaultConverterLookup.lookupConverterForType(DefaultConverterLookup.java:56) 
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:56) 
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50) 
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134) 
at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32) 
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1206) 
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1190) 
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1061) 
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1052) 
at com.example.message.MessageHandler.process(MessageHandler.java:58) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:606) 
at org.apache.camel.component.bean.MethodInfo.invoke(MethodInfo.java:408) 
at org.apache.camel.component.bean.MethodInfo$1.doProceed(MethodInfo.java:279) 
at org.apache.camel.component.bean.MethodInfo$1.proceed(MethodInfo.java:252) 
at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:171) 
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) 
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:448) 
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191) 
at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191) 
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:109) 
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:87) 
at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:103) 
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:746) 
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:684) 
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:651) 
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:315) 
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:253) 
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1164) 
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1156) 
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1053) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
at java.lang.Thread.run(Thread.java:745) 

也許我的errorHandler和/或onException不正確?謝謝!

+0

**另一個終點**是什麼樣的終點?爲什麼你手動解組,編組,發送你的'過程'方法而不是使用普通的駱駝? –

+0

什麼端點是「MyEndpoint」? –

+0

@SoucianceEqdamRashti兩個端點都是ActiveMQ。 – user5806139

回答

0

無限循環可能與底層x-stream庫中的併發問題有關。見https://github.com/x-stream/xstream/issues/2及相關問題。

+0

謝謝。是的,我可以確認這實際上是由x-stream庫中的併發/初始化問題引起的。我應該自己更新這個問題。 – user5806139