JMS 消息重新传递到队列
我在我的应用程序中使用 Jboss MQ。
我正在尝试处理重新传递到 JMS 队列的消息。 有没有办法可以在消费者收到的原始消息中设置一些值(我第一次收到消息) 这样,无论何时重新传递消息,我都可以读取该值并做出一些决定。
如果问题不清楚,请告诉我,我可以尝试详细解释。
I am using Jboss MQ in my application.
I am trying to handle redelivered message to the JMS Queue.
Is there a way I can set some values in the original message I received in the consumer(First time I received the message)
So that whenever the message is redelivered I can read the value and make some decisions.
Please let me know if the question is not clear, I can try to explain in detail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,JMS 不是这样工作的。
您作为消费者(接收)、生产者(发送)或浏览器(查看)与队列进行交互。没有用于放回更改的消息的操作。如果消费者在回滚的事务中工作,则消息将显示为“放回”,但仅仅是因为它在队列中等待事务的提交。
理论上,您可以为获得消息的同一队列创建一个生产者,修改它并将其发送“给您自己”(消息驱动 bean?),但这将是不同的消息 ,仅具有相似内容。它会到达队列的末尾。当然不建议这样做。
最好将消息数据(至少是您感兴趣的部分)保存在数据库中,以便检测它是新的还是重新传递的。
No, JMS does not work that way.
You interact with queues as a consumer (receives), producer (sends), or browser (peeks). There is no operation for putting back a changed message. If the consumer works in a transaction that gets rolled back, the message will appear to be "put back", but only so because it was waiting in the queue for the transaction's commit.
You could, in theory, create a producer for the same queue you obtained the message, modify it and send it "to yourself" (a message-drive bean?), but that would be a different message, only with similar contents. And it would get to the end of the queue. And it is certainly not recommended to do so.
It is better to persist message data (at least the parts that interest you) in a database and so detect if it's new or redelivered.
企业集成模式 Content Enricher (1) (2) 可能会帮助您。
The enterprise integration pattern Content Enricher (1) (2) might help you.