我将 Camel 2.9.1 与 Spring 3.1.1.RELEASE 和 ActiveMQ 5.5.1 一起使用。
我有一个 Swing GUI 客户端,它使用 Camel JMS 对数据服务进行@InOut
请求-答复调用,该数据服务在我们服务器上的 Karaf/Felix OSGi 容器的捆绑包中运行。
在某些情况下,此服务会引发我们想要在客户端处理的异常。
当抛出这些异常时,Camel 将它们传递回包裹在 a 中的客户端,RuntimeCamelException
并且一切正常。
但是现在我想抑制当异常传回客户端时 Camel 似乎自动记录的堆栈跟踪。这是来自服务器日志的片段:
2012-11-01 13:04:13,463 | ERROR | org.apache.camel.util.CamelLogger | Failed delivery for (MessageId: ID-pc01-48122-1351720826468-9-121549 on ExchangeId: ID-pc01-48122-1351720826468-9-121547). Exhausted after delivery attempt: 1 caught:org.apache.camel.RuntimeCamelException: our.own.SomethingException: Some explanation of exception here
org.apache.camel.RuntimeCamelException: our.own.SomethingException: Some explanation of exception here
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1221)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.component.bean.BeanInvocation.invoke(BeanInvocation.java:87)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:128)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:73)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.impl.ProcessorEndpoint.onExchange(ProcessorEndpoint.java:101)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:71)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[120:org.apache.camel.camel-core:2.9.1]
... etc.
在日志中紧随其后的是:
2012-11-01 13:04:13,517 | WARN | org.apache.camel.util.CamelLogger | Execution of JMS message listener failed. Caused by: [org.apache.camel.RuntimeCamelException - our.own.SomethingException: Some explanation of exception here]
org.apache.camel.RuntimeCamelException: our.own.SomethingException: Some explanation of exception here
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1221)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.component.bean.BeanInvocation.invoke(BeanInvocation.java:87)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:128)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:73)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.impl.ProcessorEndpoint.onExchange(ProcessorEndpoint.java:101)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:71)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:115)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:285)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:110)[120:org.apache.camel.camel-core:2.9.1]
...etc
现在,客户端的 Spring 文件具有以下定义:
<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="tcp://${current.host}:${current.port}?jms.prefetchPolicy.queuePrefetch=0"/>
<property name="transacted" value="false"/>
<property name="requestTimeout" value="60000"/>
<property name="transferException" value="true"/>
<property name="errorHandlerLogStackTrace" value="false"/>
<property name="concurrentConsumers" value="1"/>
<property name="maxConcurrentConsumers" value="1"/>
</bean>
哪个errorHandlerLogStackTrace
属性设置为“false”,所以我不确定为什么它仍在记录堆栈跟踪。
我是否需要在服务器端进行类似的属性设置(因为这是包含堆栈跟踪的服务器日志)?
顺便说一句,这些东西大部分是由不再为我们工作的前员工设置的。尽管我对正在发生的事情有相当好的了解,但其中一些对我来说仍然是个谜。
更新:2012 年 5 月 11 日 - 在克劳斯的回答之后
好的,我深入挖掘了 Spring DSL XML 文件,发现 JMS 组件是在服务器上定义的一个单独的 OSGi 包中,称为“代理”,其他服务器包所指的是该包。该捆绑包具有与客户端相同的“jms”bean 的 XML 定义(上图)。
我在这个定义中添加了“errorHandlerLogStackTrace”属性,这已经成功地摆脱了堆栈跟踪之一。我现在得到的是一个带有堆栈跟踪的错误,然后是一个没有堆栈跟踪的 WARN。这是一个更完整的片段:
2012-11-05 10:44:35,323 | ERROR | org.apache.camel.util.CamelLogger | Failed delivery for (MessageId: ID-pc01-38192-1352065125718-9-62 on ExchangeId: ID-pc01-38192-1352065125718-9-60). Exhausted after delivery attempt: 1 caught: org.apache.camel.RuntimeCamelException: our.own.SomethingException: Some explanation of exception here
org.apache.camel.RuntimeCamelException: our.own.SomethingException: Some explanation of exception here
at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1221)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.component.bean.BeanInvocation.invoke(BeanInvocation.java:87)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:128)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:73)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.impl.ProcessorEndpoint.onExchange(ProcessorEndpoint.java:101)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:71)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProcessor.java:115)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.java:285)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:110)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:71)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:333)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:223)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:304)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:71)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:99)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:86)[120:org.apache.camel.camel-core:2.9.1]
at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:104)[147:org.apache.camel.camel-jms:2.9.1]
at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:562)[63:org.springframework.jms:3.1.1.RELEASE]
at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:500)[63:org.springframework.jms:3.1.1.RELEASE]
at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:468)[63:org.springframework.jms:3.1.1.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:326)[63:org.springframework.jms:3.1.1.RELEASE]
at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:264)[63:org.springframework.jms:3.1.1.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1071)[63:org.springframework.jms:3.1.1.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1063)[63:org.springframework.jms:3.1.1.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:960)[63:org.springframework.jms:3.1.1.RELEASE]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_24]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_24]
at java.lang.Thread.run(Thread.java:662)[:1.6.0_24]
Caused by: our.own.SomethingException: Some explanation of exception here
at uniworks.ServiceManagers.SuperDataManager.createInUseForEntity(SuperDataManager.java:2156)[220:uniworks-ejb:1.1.4.SNAPSHOT]
at uniworks.ServiceManagers.SuperDataManager.findForEdit(SuperDataManager.java:913)[220:uniworks-ejb:1.1.4.SNAPSHOT]
at uniworks.ServiceManagers.SuperDataManager.findForEdit(SuperDataManager.java:853)[220:uniworks-ejb:1.1.4.SNAPSHOT]
at uniworks.ServiceManagers.SuperDataManager.findForEdit(SuperDataManager.java:843)[220:uniworks-ejb:1.1.4.SNAPSHOT]
at sun.reflect.GeneratedMethodAccessor106.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)[:1.6.0_24]
at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_24]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)[55:org.springframework.aop:3.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)[55:org.springframework.aop:3.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)[55:org.springframework.aop:3.1.1.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)[65:org.springframework.transaction:3.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)[55:org.springframework.aop:3.1.1.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)[55:org.springframework.aop:3.1.1.RELEASE]
at $Proxy221.findForEdit(Unknown Source)
at sun.reflect.GeneratedMethodAccessor106.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)[:1.6.0_24]
at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_24]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)[55:org.springframework.aop:3.1.1.RELEASE]
at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:58)
at org.springframework.osgi.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:62)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)[55:org.springframework.aop:3.1.1.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)[55:org.springframework.aop:3.1.1.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)[55:org.springframework.aop:3.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)[55:org.springframework.aop:3.1.1.RELEASE]
at org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:56)
at org.springframework.osgi.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:39)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)[55:org.springframework.aop:3.1.1.RELEASE]
at org.springframework.osgi.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:59)[90:org.springframework.osgi.core:1.2.1]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)[55:org.springframework.aop:3.1.1.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131)[55:org.springframework.aop:3.1.1.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119)[55:org.springframework.aop:3.1.1.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)[55:org.springframework.aop:3.1.1.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)[55:org.springframework.aop:3.1.1.RELEASE]
at $Proxy1044.findForEdit(Unknown Source)
at sun.reflect.GeneratedMethodAccessor106.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)[:1.6.0_24]
at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_24]
at org.apache.camel.component.bean.BeanInvocation.invoke(BeanInvocation.java:83)[120:org.apache.camel.camel-core:2.9.1]
... 46 more
2012-11-05 10:44:35,335 | WARN | org.apache.camel.util.CamelLogger | Execution of JMS message listener failed. Caused by: [our.own.SomethingException: Some explanation of exception here]
现在,这里可能使这些复杂化的是此方法调用所采用的“路径”。
客户端使用 JMS Request-Reply 消息使用以下路由定义调用服务器:
<bean id="animalTypeDataManager" class="org.apache.camel.spring.remoting.CamelProxyFactoryBean">
<property name="serviceUrl" value="jms:animalTypeDataManager"/>
<property name="serviceInterface" value="uniworks.ServiceManagers.a.Animal.AnimalTypeDataInterface"/>
</bean>
该路由的服务器端在一个 OSGi 包中定义(让我们调用“BundleA”),如下所示:
<camel:route>
<camel:from uri="jms:animalTypeDataManager"/>
<camel:to uri="bean:osgi_animalTypeDataManager"/>
</camel:route>
这条路线中提到的 bean 实际上作为 OSGi 的“服务”在另一个包 ('BundleB') 中。BundleA 对此 bean 的引用定义如下:
<reference id="osgi_animalTypeDataManager"
interface="uniworks.ServiceManagers.a.Animal.AnimalTypeDataInterface"/>
BundleB 的服务定义如下:
<service id="osgi_animalTypeDataManager" ref="animalTypeDataManager"
interface="uniworks.ServiceManagers.a.Animal.AnimalTypeDataInterface"/>
正是这个最终的服务 bean 引发了异常。
我可以errorHandler
在这些路由的每个服务器端(在 BundleA 中)放置一个,但我希望能够在一个地方通用地执行此操作。
我尝试在 BundleA 中定义一个日志记录错误处理程序(根据Camel Documentation),如下所示:
<camel:errorHandler id="loggingErrorHandler" type="LoggingErrorHandler" logName="mylogger.name" level="DEBUG"/>
<camel:camelContext id="bundleA_camel" errorHandlerRef="loggingErrorHandler">
..... [jms routes defined in here]
</camel:context>
但这似乎没有任何区别。