我正在使用带有RabbitMQ的Spring Cloud Stream,并且我需要发送一个事件,该事件需要由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 Docs