Java Spring集成:让所有标题都参与到一个加积中,而不仅仅是最后一个标题
我有一个定义如下的Spring集成流:Java Spring集成:让所有标题都参与到一个加积中,而不仅仅是最后一个标题,java,spring,spring-integration,spring-integration-amqp,Java,Spring,Spring Integration,Spring Integration Amqp,我有一个定义如下的Spring集成流: IntegrationFlows.from(Amqp.inboundAdapter(connectionFactory, "queueName") .id("id") .acknowledgeMode(MANUAL) .autoStartup(autoStartup) .concurrentCons
IntegrationFlows.from(Amqp.inboundAdapter(connectionFactory, "queueName")
.id("id")
.acknowledgeMode(MANUAL)
.autoStartup(autoStartup)
.concurrentConsumers(2)
.maxConcurrentConsumers(3)
.messageConverter(messageConverter()))
.aggregate(a -> ...)
.handle(serviceActivatorBean, "myMethod", e -> e.advice(requestHandlerRetryAdviceForIntegrationFlow()))
.get();
@Component
@Transactional
public class ServiceActivator {
@ServiceActivator
public void myMethod(List<> Collection<MyEvent> events) {
....
}
}
以及定义如下的服务激活器:
IntegrationFlows.from(Amqp.inboundAdapter(connectionFactory, "queueName")
.id("id")
.acknowledgeMode(MANUAL)
.autoStartup(autoStartup)
.concurrentConsumers(2)
.maxConcurrentConsumers(3)
.messageConverter(messageConverter()))
.aggregate(a -> ...)
.handle(serviceActivatorBean, "myMethod", e -> e.advice(requestHandlerRetryAdviceForIntegrationFlow()))
.get();
@Component
@Transactional
public class ServiceActivator {
@ServiceActivator
public void myMethod(List<> Collection<MyEvent> events) {
....
}
}
但在这里,我似乎只获得最后一条消息的标题值(即频道
和标记
总是大小为1,即使事件
集合中有多个事件)
我还尝试将Collection
更改为Collection
(org.springframework.messaging.Message
),以尝试手动提取标题,但在以下情况下失败:
org.springframework.messaging.MessageHandlingException: nested exception is java.lang.ClassCastException: com.x.y.MyEvent cannot be cast to org.springframework.messaging.Message
因为消息已经由IntegrationFlow中定义的消息转换器转换
如何实现这一点?您需要在
聚合器上安装一个自定义的输出处理器
,以返回所需的消息(标题中有频道/传递标签列表,负载中有事件列表)