【发布时间】:2020-06-04 07:46:00
【问题描述】:
我正在将 Spring Cloud Stream 与 RabbitMQ 一起使用,我需要发送一个需要恰好 2 个消费者消费的事件。
在生产者中我添加了多个目的地:
标签微服务:
public interface OutgoingEventChannels {
@Output("updateTagNameChannel")
MessageChannel updateTagName();
}
@Component
@EnableBinding(OutgoingEventChannels.class)
public class EventProducer {
@Autowired
private OutgoingEventChannels outgoingEventChannels;
public void sendUpdateTagNameEvent(UpdateTagNameEvent updateTagNameEvent) {
outgoingEventChannels.updateTagName().send(new GenericMessage<>(updateTagNameEvent));
}
}
spring.cloud.stream.bindings.updateTagNameChannel.destination=updateCustomerTagName,updateSectionTagName
spring.cloud.stream.bindings.updateTagNameChannel.group=tags-group
每个消费者都绑定到不同的目的地:
客户微服务:
public interface IncomingEventChannels {
@Input("updateTagNameChannel")
MessageChannel updateTagName();
}
@Component
@EnableBinding(IncomingEventChannels.class)
public class EventListener {
private static final Logger LOG = LogManager.getLogger(EventListener.class);
@Autowired
private CustomerService customerService;
@StreamListener("updateTagNameChannel")
public void handleUpdateTagNameEvent(UpdateTagNameEvent updateTagNameEvent) {
LOG.info("Received update tag event: " + updateTagNameEvent);
customerService.updateTagName(updateTagNameEvent);
}
}
spring.cloud.stream.bindings.updateTagNameChannel.destination=updateCustomerTagName
spring.cloud.stream.bindings.updateTagNameChannel.group=tags-group
两个消费者中的任何一个都不会收到该事件。有谁知道我做错了什么?
提前谢谢你!
【问题讨论】:
标签: spring-boot stream rabbitmq spring-cloud