Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring Camel动态构建处理器bean调用_Spring_Apache Camel_Javabeans_Processor - Fatal编程技术网

Spring Camel动态构建处理器bean调用

Spring Camel动态构建处理器bean调用,spring,apache-camel,javabeans,processor,Spring,Apache Camel,Javabeans,Processor,下面是一个主题的bean设置示例。请记住有多个bean…每种消息类型一个 通过为每种消息类型设置一个路由,我已经能够成功地接收和处理我的所有消息类型,但我希望简化上下文文件,因此我希望只有一个路由接收我的所有主题 下面是我的路线设置的样子 <route id="Netty7001Route"> <from uri="netty4:tcp://192.168.200.3:7001…"/> <to uri=”seda:Proces

下面是一个主题的bean设置示例。请记住有多个bean…每种消息类型一个

通过为每种消息类型设置一个路由,我已经能够成功地接收和处理我的所有消息类型,但我希望简化上下文文件,因此我希望只有一个路由接收我的所有主题

下面是我的路线设置的样子

    <route id="Netty7001Route">
       <from uri="netty4:tcp://192.168.200.3:7001…"/>
       <to uri=”seda:ProcessRoute”/>
    </route>

    <route id=”ProcessRoute”/>
      <from uri=”seda:ProcessRoute”/>
           <setHeader headerName="LOGMESSAGE"><simple>A10::Entering endpoint for track message ${in.header.MSGNAME} via netty4</simple></setHeader>
           <to uri="log:messageLogger?level=ERROR"/>
           <setHeader headerName="LOGMESSAGE"><simple>A11::Leaving endpoint for track message ${in.header.MSGNAME}</simple></setHeader>
           <to uri="log:messageLogger?level=ERROR"/>
           <setHeader headerName="LOGMESSAGE"><constant>A14::Entering Mediation</constant></setHeader>
           <to uri="log:messageLogger?level=ERROR"/>
           **<process ref="DDS_C2_NewSystemReferencePointMediationBean"/>**
       <setHeader headerName="MSGNAME"><constant>C2_TM_NewSystemReferencePoint</constant></setHeader>
       <setHeader headerName="MSGTYPE"><constant>C2_NewSystemReferencePoint</constant></setHeader>
           <setHeader headerName="LOGMESSAGE"><constant>A15::Leaving Mediation</constant></setHeader>
           <to uri="log:messageLogger?level=ERROR"/>
           <setHeader headerName="LOGMESSAGE"><constant>A17::Sending message to DDS domain 4</constant></setHeader>   
           <to uri="log:messageLogger?level=ERROR"/>
       <to uri="dds://4/C2_TM_NewSystemReferencePoint?typeName=C2_NewSystemReferencePoint"/>
    </route>

A10::通过netty4为跟踪消息${in.header.MSGNAME}输入端点
A11::正在离开跟踪消息${in.header.MSGNAME}的端点
A14::进入中介
****
C2_TM_新闻系统参考点
C2_新闻系统参考点
A15:离开调解
A17::正在向DDS域4发送消息
因此,上面的processref=line是我想要的动态过程,因为在我查看头部中的MSGNAME之前,我不知道调用哪个bean处理器。我尝试过使用recipientList,但失败了,因为它们不是端点,而是处理器bean,并且我尝试过只使用ref:DDS_C2{$in.header.MSGNAME}MediationBean,但camel不会启动并抱怨这里的简单标记。在camel-spring配置中是否有这样做的方法

我尝试了一种解决方法,使用标记检查MSGNAME,然后调用相应的处理器bean,但我需要为每种消息类型设置条件。这是可行的,但与每个主题都有一个路由相比,效率极低


我曾考虑过编写一个处理器,在java代码中调用适当的bean处理器,但我不确定这是否是完成我需要的任务的正确方法,也不确定使用标记是否更有效


感谢您的帮助。

最好的方法是使用ProcessorEndpoint创建一个新组件,如前所述

工作示例(带处理器)
  • 创建自定义组件:

    package com.mgyongyosi.sample.component;
    
    // imports
    
    public class SpecifiedProcessor extends DefaultComponent {
    
    @Override
    protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
        Object registryObj = getCamelContext().getRegistry().lookupByName(remaining);
    
        if(!(registryObj instanceof Processor))
            throw new IllegalArgumentException("The Processor with the specified name was not found in the Registry.");
    
        return new ProcessorEndpoint(uri, this, (Processor)registryObj);
    }
    
  • Java DSL的使用示例:

    from("timer:helloworld?period=5000")
            .setHeader("MSGNAME", constant("NewSystemReferencePoint"))
            .toD("specified-processor://DDS_C2_${in.header.MSGNAME}MediationBean")
            .log("${body}");
    
  • 在XML中:

    <toD uri="specified-processor://DDS_C2_${in.header.MSGNAME}MediationBean"/>
    
    
    
    如果是豆子 JavaDSL:
    .toD(“bean:DDS\uC2\u${in.header.MSGNAME}MediationBean”)


    XML:

    为了澄清,我在谈论代码中的processref=tag。此外,为我编写一个处理器来确定bean调用将在消息类型更改或添加时强制更新代码,因此我需要一个基于spring的解决方案。“我曾考虑编写一个处理器,在java代码中调用适当的bean处理器”,我相信这是一种方法(不管安全问题如何,提供一个类在http头中调用。)直接andpoint在启动时进行计算,因此您无法动态提供“ref”参数。为什么不使用choice()。when(header==“where”)然后调用您的进程?注意,我说的是使用choice/when功能。xml dsl也有类似的功能。我尝试使用choice/when,但我有96种不同的消息类型,在测试过程中,性能要比我有每个主题的路由时慢得多。问题是我的MediationBean没有处理器。还有吗有一种方法可以通过将这些中介bean包装到您在这里概述的ProcessorEndpoint中来调用它们?使用
    .toD(“bean:DDS\u C2\u${in.header.MSGNAME}.MediationBean”)
    。太棒了!谢谢您,先生。就是不知道如何正确地调用它。如果bean名称包含“dot”,这个“bean:”表达式会工作吗“?我有一个类似的案例,有什么出路吗?
    <toD uri="specified-processor://DDS_C2_${in.header.MSGNAME}MediationBean"/>