【问题标题】:Apache Camel Proxy isn't workingApache Camel 代理不工作
【发布时间】:2013-06-24 21:15:34
【问题描述】:

问题也可能与我对这个概念的理解有关。
ActionClass 正在调用代理 bean,它是 AccountingInterface。代理 bean 接口是用AccountingUtil 类实现的。所以我期待AccountingUtil 返回的xml 会通过seda:accountingQueue,然后在控制台上流出。
ApplicationContext

    <bean id="accountingInterface" class="org.apache.camel.spring.remoting.CamelProxyFactoryBean">
      <property name="serviceUrl" value="seda:accountingQueue"/>
      <property name="serviceInterface" value="acord.transaction.util.AccountingInterface"/>
    </bean>
    <route>
        <from uri="seda:accountingQueue"/>
        <setHeader headerName="nowInMillis">
           <groovy>new Date().getTime()</groovy>
         </setHeader>
         <to uri="stream:out"/>
    </route>

会计接口

public interface AccountingInterface 
{
    void send(String xml);
    String accountingUpdate(EDITDate accountingProcessDate);
}

AccountingUtil

public class AccountingUtil implements AccountingInterface
{
  public String accountingUpdate(EDITDate accountingProcessDate)
     {
       //doSomething
      return xml;
    }

动作类

AccountingInterface accountingInterface = (AccountingInterface) AppContext.getBean("accountingInterface");
accountingInterface.accountingUpdate(accountingProcessDate);

但我遇到了异常:

No body available of type: java.lang.String but has value: BeanInvocation public abstract java.lang.String acord.transaction.util.AccountingInterface.accountingUpdate(edit.common.EDITDate) with [2012/11/08]] of type: org.apache.camel.component.bean.BeanInvocation on: Message: BeanInvocation public abstract java.lang.String acord.transaction.util.AccountingInterface.accountingUpdate(edit.common.EDITDate) with [2012/11/08]]. Caused by: No type converter available to convert from type: org.apache.camel.component.bean.BeanInvocation to the required type: java.lang.String with value BeanInvocation public abstract java.lang.String acord.transaction.util.AccountingInterface.accountingUpdate(edit.common.EDITDate) with [2012/11/08]]. Exchange[Message: BeanInvocation public abstract java.lang.String acord.transaction.util.AccountingInterface.accountingUpdate(edit.common.EDITDate) with [2012/11/08]]]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: org.apache.camel.component.bean.BeanInvocation to the required type: java.lang.String with value BeanInvocation public abstract java.lang.String acord.transaction.util.AccountingInterface.accountingUpdate(edit.common.EDITDate) with [2012/11/08]]]
    at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:101)

还有一个问题 单个proxyBean(interface) 可以有多个serviceURL 吗?
我想要不同的方法来调用不同的serviceURL,但它是单个接口的一部分。

【问题讨论】:

    标签: java apache-camel


    【解决方案1】:

    更新: 啊,刚刚明白你的问题。一开始就有点第一了。

    在进行代理时,Camel 将调用(到哪个方法/接口和哪些参数)转换为一个 BeanInvocation 对象。然后通过选择的 Camel 端点(在您的情况下为 seda)进行处理。但是您尝试将其打印到标准输出,而不是调用 AccountingInterface 的 bean 实例(例如您的情况下的 AccountingUpdateACORDUtil)。

    不,不同的方法将调用相同的 URL,但在 BeanInvocation 中使用不同的方法。这当然可以通过在 Camel 路由中路由您的请求来实现,例如首先将其发送到简单的direct:routeAccoutingRequest,然后查看调用的方法以确定它应该在选择构造中转到哪个端点。

    您可以使用带有 ProducerTemplates 的普通对象构建自己的逻辑,以实现发送字符串、调用不同方法等任务。代理用于代理 bean 调用。

    【讨论】:

    • 我认为这应该不是问题。对于一个简单的用例,普通代理 bean 正在工作。 Camel In Action 中提到了这种方法。 return of proxy interface method 将转到服务 url 是一个公平的假设吗?
    • 阅读问题有点太快了。彻底改变了答案
    • 我明白你的意思,每个代理 bean 都有 onw serviceURL。无法理解为什么我的流程会出错。更新了我的问题以解释代码流。
    • 我想问题是我对整个隐藏中间件概念本身的理解:(查看我的其他 [question][1] 具体到这个想法。[1]:stackoverflow.com/questions/17300004/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-24
    • 2016-01-31
    • 2014-11-25
    • 2015-12-08
    • 1970-01-01
    相关资源
    最近更新 更多