1

我可以配置一个JmsMessageDrivenChannelAdapter,以便它能够与不同的目的地一起工作,通过DestinationResolvers或这样吗?我想通过IntegrationFlows构建器提供目标逻辑,所以我可以重用组件(我不需要为每个主题创建一个适配器),或者将所有目标源/决策规则集中在一个类中

4

1 回答 1

1

你可以这样做:

IntegrationFlows
                .from(Jms.messageDrivenChannelAdapter(jmsConnectionFactory())
                        .destination("DUMMY")
                        .configureListenerContainer(c ->
                                c.destinationResolver((session, s, b) ->
                                    YOUR LOGIC FOR DYNAMIC DESTINATION RESOLUTION)))

您需要该"DUMMY"目标配置来模拟容器状态:

protected void validateConfiguration() {
    if (this.destination == null) {
        throw new IllegalArgumentException("Property 'destination' or 'destinationName' is required");
    }
}

OTOH我不确定它是否会正常工作。

容器根据目标启动一个 JMS Consumer(即使您通过 custom 提供它DestinationResolver),并且在容器停止之前无法更改它。

您可以考虑使用Jms.inboundAdapter()虽然,它是可轮询的,但基于JmsTemplate.receiveSelected(). 这样,您可以receive()在轮询器的每次调用中更改目标。

dummy无论如何,您将需要destinationName 配置。否则它不会进入getDestinationResolver().

于 2017-07-18T15:44:39.080 回答