跨实例同步对 MDB 方法的访问
我有一个消息驱动 Bean,它接收审核消息。这些消息还包含有关正在审核的系统的信息。当收到消息时,MDB 可以创建系统(如果该系统不存在)或重用现有系统。
我的挑战是,当同时接收到来自新系统的大量消息时,会创建多个 MDB 实例,并最终可能会创建重复的系统。向数据库添加约束是解决该问题的一种方法。有没有办法避免应用程序(在本例中为 MDB)中出现这些重复项?
I have an Message Driven Bean, which receives Audit messages. These messages also have information about the system being audited. When a message is received, the MDB can create the system if it does not exists or reuse an existing system.
My challenge is that when a lot of messages from a new system are received simultaneously, multiple MDB instances are created and can end up creating duplicate systems. Adding a constraint to the database is one way to solve it. Is there a way of avoiding these duplicates in the application, MDB in this case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保只有一个线程处理所有消息。这可以在激活规范、连接池上进行配置。
Make sure to have only a single Thread processing all the Messages. This can be configured on the Activation Spec, connection Pool.
MessageDrivenBean
可以通过队列 Destination Options 进行同步。在我的例子中,对于单个消息处理,MessageDriven
注释看起来像这样:MessageDrivenBean
can be synchronized via queue Destination Options. In my caseMessageDriven
annotation looks like this for single message processing:你可以尝试这样的事情:
You could try something like this: