【问题标题】:Apache Camel - JMS Remoting: Exception not thrown back to the producerApache Camel - JMS Remoting:未将异常返回给生产者
【发布时间】:2013-05-04 13:29:43
【问题描述】:

我正在寻找一种解决方案,以在使用 Apache Camel - JMS Remoting 时使消费者端抛出的异常返回到生产者端。

我发现Apache Camel JMS - Exceptions not returned to caller with request/reply 已经有人问过类似的问题。

所以,我按照那里的答案,并按照克劳斯的建议打开了 transferException 选项,但 Camel 仍然给我一个错误 - 另一个错误,InvalidPayloadException 这是由 org.apache.camel.NoTypeConversionAvailableException 引起的 - 没有可用的类型转换器从类型:org.apache.camel.RuntimeCamelException 转换为所需的类型:long with value org.apache.camel.RuntimeCamelException: com.xyzServiceException: test]。

所以,我似乎确实按照克劳斯的建议将异常转移到了生产者端(原始异常包含在 RuntimeCalmelException 中)。问题是 Camel 试图将我的异常转换为很长的返回类型。

有没有办法让异常一直冒泡而不被转换?

详情如下:

界面: PricingService.java

    public long getPrice(String id);

消费者端:PricingServiceImpl.java

    @Service("pricingService")
    public class PricingServiceImpl {
        public long getPrice(String id) {
            //only throw an exception here for simplicity. 
            //Assuming ServiceException is    serializable.
            throw new ServiceException("test");
        }
    }

RouteBuilder:

    public class MyRoutes extends RouteBuilder {
        public void configure() throws Exception {
            getContext().setTracing(true);
            from("jms:queue:pricingService concurrentConsumers=25&transferException=true&transferExchange=true").to("pricingService");
        }
    }

制作方:

    <camel:camelContext id="producer">
        <camel:proxy id="pricingService"
            serviceInterface="com.x.y.z.PricingService"
            serviceUrl="jms:queue:pricingService?transferExchange=true"/>
    </camel:camelContext>

所以,在生产者方面,当我调用pricingService.getPrice("abc") 时,我得到了如下异常:

org.apache.camel.InvalidPayloadException: No body available of type: long but has value:    org.apache.camel.RuntimeCamelException:    com.x.y.z.ServiceException: ERR_NOT_FOUND of type: org.apache.camel.RuntimeCamelException on: JmsMessage[JmsMessageID: ID:localhost.localdomain-35812-1368034706262-11:1:1:1:1]. Caused by: No type converter available to convert from type: org.apache.camel.RuntimeCamelException to the required type: long with value org.apache.camel.RuntimeCamelException: com.x.y.z.ServiceException: ERR_NOT_FOUND. Exchange[JmsMessage[JmsMessageID: ID:localhost.localdomain-35812-1368034706262-11:1:1:1:1]]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.apache.camel.RuntimeCamelException to the required type: long with value org.apache.camel.RuntimeCamelException: com.x.y.z.ServiceException: ERR_NOT_FOUND]
    at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:101)
    at org.apache.camel.component.bean.AbstractCamelInvocationHandler.getBody(AbstractCamelInvocationHandler.java:66)
    at org.apache.camel.component.bean.AbstractCamelInvocationHandler.afterInvoke(AbstractCamelInvocationHandler.java:175)
    at org.apache.camel.component.bean.AbstractCamelInvocationHandler$1.call(AbstractCamelInvocationHandler.java:112)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at org.apache.camel.component.bean.AbstractCamelInvocationHandler.invokeWithBody(AbstractCamelInvocationHandler.java:128)
    at org.apache.camel.component.bean.CamelInvocationHandler.doInvokeProxy(CamelInvocationHandler.java:45)
    at org.apache.camel.component.bean.AbstractCamelInvocationHandler.invoke(AbstractCamelInvocationHandler.java:82)
    ... 103 more
Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: org.apache.camel.RuntimeCamelException to the required type: long with value org.apache.camel.RuntimeCamelException: com.x.y.z.ServiceException: ERR_NOT_FOUND
    at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:169)
    at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:99)
    ... 111 more

谢谢!

更新:

在生产者端添加 transferException 后,我得到的异常更改为以下。我真的无法理解这一点。它仍然试图进行转换...请帮助。谢谢。

Caused by: org.apache.camel.InvalidPayloadException: No body available of type: long but has value: BeanInvocation public abstract long com.x.y.z.PricingService.getPrice(java.lang.String) throws com.x.y.z.ServiceException with [test]] of type: org.apache.camel.component.bean.BeanInvocation on: Message: test. Caused by: Error during type conversion from type: org.apache.camel.component.bean.BeanInvocation to the required type: long with value BeanInvocation public abstract long com.x.y.z.service.billing.PricingService.getPrice(java.lang.String) throws com.x.y.z.ServiceException with [test]] due java.lang.NumberFormatException: For input string: "test". Exchange[Message: test]. Caused by: [org.apache.camel.TypeConversionException - Error during type conversion from type: org.apache.camel.component.bean.BeanInvocation to the required type: long with value BeanInvocation public abstract long com.x.y.z.PricingService.getPrice(java.lang.String) throws com.x.y.z.ServiceException with [test]] due java.lang.NumberFormatException: For input string: "test"]
    at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:101)
    at org.apache.camel.component.bean.AbstractCamelInvocationHandler.getBody(AbstractCamelInvocationHandler.java:72)
    at org.apache.camel.component.bean.AbstractCamelInvocationHandler.afterInvoke(AbstractCamelInvocationHandler.java:175)
    at org.apache.camel.component.bean.AbstractCamelInvocationHandler$1.call(AbstractCamelInvocationHandler.java:112)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at org.apache.camel.component.bean.AbstractCamelInvocationHandler.invokeWithBody(AbstractCamelInvocationHandler.java:128)
    at org.apache.camel.component.bean.CamelInvocationHandler.doInvokeProxy(CamelInvocationHandler.java:45)
    at org.apache.camel.component.bean.AbstractCamelInvocationHandler.invoke(AbstractCamelInvocationHandler.java:82)
    ... 104 more
Caused by: org.apache.camel.TypeConversionException: Error during type conversion from type: org.apache.camel.component.bean.BeanInvocation to the required type: long with value BeanInvocation public abstract long com.x.y.z.PricingService.getPrice(java.lang.String) throws com.x.y.z.ServiceException with [test]] due java.lang.NumberFormatException: For input string: "test"
    at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:162)
    at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:99)
    ... 112 more
Caused by: org.apache.camel.RuntimeCamelException: java.lang.NumberFormatException: For input string: "test"
    at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1316)
    at org.apache.camel.util.ObjectHelper.invokeMethod(ObjectHelper.java:962)
    at org.apache.camel.impl.converter.StaticMethodTypeConverter.convertTo(StaticMethodTypeConverter.java:47)
    at org.apache.camel.component.bean.BeanConverter.convertTo(BeanConverter.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

【问题讨论】:

    标签: java spring jms apache-camel spring-remoting


    【解决方案1】:

    您也应该在生产者端设置 transferException=true。

    【讨论】:

    • 感谢您的回复。我试过了,但仍然得到一个 InvalidPayloadException,尽管底层异常有点不同:org.apache.camel.InvalidPayloadException: No body available of type: long but has value: BeanInvocation public abstract long com.xyzPricingService.getPrice(java.lang .String) 抛出 com.xyzServiceException 类型为 [test]]:org.apache.camel.component.bean.BeanInvocation
    • 我更新了问题,但出现了异常,包括堆栈跟踪。在评论部分不是那么可读。任何输入将不胜感激。谢谢!
    猜你喜欢
    • 2012-10-25
    • 1970-01-01
    • 1970-01-01
    • 2019-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    • 1970-01-01
    相关资源
    最近更新 更多