每个主题在集​​群中运行的每个侦听器仅消耗一次消息 [英] Consume message only once from Topic per listeners running in cluster

查看:168
本文介绍了每个主题在集​​群中运行的每个侦听器仅消耗一次消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现域事件基础结构,但是该项目不允许任何消息传递基础设施(金融服务客户端),因此在Hazelcast Topics和ExecutorService中找到了替代方法,

I'm implementing an Domain Event infrastructure, but the project doesn't allow any messaging infra(financial services client) so found an alternative in Hazelcast Topics and ExecutorService,

但是问题是,当在集群中运行时,消息将传递给将在集群中运行的侦听器,因此对于集群2,我们在2个jvm中运行了相同的侦听器,并且消息消耗了两次并采取了行动,假设Domain事件应该执行一些非幂等的操作,例如为某些忠诚度积分打分,除非我明确维护所作用的Domain事件的踪迹并核对每次收到事件的检查,否则我都会两次归功于它,任何建议实施此操作,而不必在下层写那些样板",或者是否有已知的实施方法.

But the problem is when running in cluster the message shall be delivered to listeners which is going to be running in cluster, so for a cluster of 2, we have same listener running in 2 jvm, and message consume twice and acted upon, suppose the Domain event is supposed to perform some non idempotent operation like credit some loyalty points, unless I explicitly maintain a trace of domain event acted upon and check against that everytime I receive an event, I will end up crediting it twice, "any suggestion implementing this without having to write those boiler plates possibly at the infralayer", or is there a known patter for such implementation.

同时,我也在评估 Hazelcast ExecutorService 根据建议此处

Meanwhile I'm also evaluating Hazelcast ExecutorService as suggested Here

推荐答案

可以通过使用Hazelcast的Queues(而不是Topics)来解决您描述的用例.使用主题的主要原因是,如果您有兴趣让多个(可能是独立的)使用者获得相同的消息.您的要求听起来像是您只对其中一个消费者感兴趣,这就是队列的意义,请参阅

The use case you described can be solved by using Hazelcast's Queues instead of Topics. The main reason to use topics is if you are interested that multiple (possibly independent) consumers get the same message. Your requirement sounds like you are interested that only one of the consumers gets the message, and that's what queues are for, see the Hazelcast documentation for Queues.

这篇关于每个主题在集​​群中运行的每个侦听器仅消耗一次消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆