3

我正在寻找一种解决方案,以在使用 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 中)。问题是骆驼试图将我的异常转换为长的返回类型。

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

这是详细信息:

接口: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");
        }
    }

路线构建器:

    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)
4

1 回答 1

1

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

于 2013-05-10T13:50:43.137 回答