首页 文章

Spring intgeration - recipientlistrouter - 并行处理

提问于
浏览
0

如何在spring-integration中使用recipient-list-router实现并行处理 .

我的目标是路由器必须基于内容,并在并行处理时向各种信道发送消息,就像多播一样 . 我尝试使用camel-spring-integration在Camel中进行多播,但无法为基于内容的配置进行配置

如果有事情要做,请帮忙

谢谢

2 回答

  • 1

    我通过扩展Spring-Integrations的RecipientListRouter实现了类似的要求,如下所示:

    public class CententBasedRecipientListRouter extends RecipientListRouter {
        @Override
        protected void handleMessageInternal(final Message<?> message) {
           ......
        }
    }
    

    在重写方法中,您可以根据您的要求实现任何基于定制内容的路由逻辑 .

    此自定义路由器可以配置如下:

    <bean id="customRecipientListRouter" class="CententBasedRecipientListRouter">
      <property name="channels">
        <list>
          <ref bean="parallelProcessingChannel1"/>
          <ref bean="parallelProcessingChannel2"/>
          <ref bean="parallelProcessingChannel3"/>
        </list>
      </property>
    </bean>
    
    <int:router ref="customRecipientListRouter" 
                input-channel="routingChannel"
                default-output-channel="errorChannel" />
    

    为了实现并行处理,您可以使用以下任务 Actuator 通道:

    <int:channel id="parallelProcessingChannel1">
       <int:dispatcher task-executor="threadPoolExecutor"/>
    </int:channel>
    
  • 0

    如果我理解正确的问题,您只需要使用发布订阅 Channels 作为路由器的输出通道 . 路由器将根据内容将消息定向到正确的pubsub通道,然后订阅该通道的所有处理程序将并行执行,假设输出通道任务执行程序配置为具有多个线程 .

    <int:publish-subscribe-channel id="channel1" task-executor="someExecutor"/>
    <int:publish-subscribe-channel id="channel2" task-executor="someExecutor"/>
    
    <int:recipient-list-router id="customRouter" input-channel="routingChannel">
        <int:recipient channel="channel1" selector-expression="payload.equals('foo')"/>   
        <int:recipient channel="channel2" selector-expression="headers.containsKey('bar')"/>
    </int:recipient-list-router>
    

    上面的收件人列表路由器配置是从Spring Integration参考手册的第5.1节中复制的 .

相关问题