繁体   English   中英

Apache Camel - JMS Remoting:异常没有被抛回到制作人

[英]Apache Camel - JMS Remoting: Exception not thrown back to the producer

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

我发现在Apache Camel JMS上已经提出了类似的问题- 异常未通过请求/回复返回给调用者

所以,我按照那里的答案,我打开了Claus建议的transferException选项,但Camel仍然给我一个错误 - 一个不同的错误,由org.apache.camel.NoTypeConversionAvailableException引起的InvalidPayloadException - 没有类型转换器可用于转换类型: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)

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM