来自ActiveMQ的重新输入消息
当消息消耗消息并且处理消息存在问题时,该消息没有保存在数据源中。由于该消息是消耗的,因此不存在ActiveMQ经纪人和DataSource中。
有没有办法从ActiveMQ重新接收消息?
When the message is consumed and there is an issue with the processing of the message and it's not saved in the datasource. Since the message is consumed it's not present in ActiveMQ broker and datasource.
Is there a way to reconsume the message from ActiveMQ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个经典的消息丢失方案。
处理这种用例的最强大方法是使用XA事务,以便JMS工作和JDBC工作是原子。这意味着,如果消息消费者有问题并且无法在数据库中插入数据,则可以将XA事务回滚,并将消息放回队列上,以便再次消费。
处理此问题的一种不那么强大但更容易访问的方法是在食用消息时使用交易的JMS会话。完成数据库工作后,您可以确认消息并提交会话。如果有问题,则您会回滚会话。
This is a classic message loss scenario.
The most robust way to deal with this kind of use-case is by using an XA transaction so that the JMS work and the JDBC work is atomic. This means that if the message consumer has a problem and is not able to insert data in the database then the XA transaction can be rolled back and the message will be put back on the queue so it can be consumed again.
A less robust, but more accessible way to deal with this is to use a transacted JMS session when consuming messages. Once the database work is done then you can acknowledge the message and commit the session. If there is a problem then you rollback the session.