简体   繁体   English

Java JMS - 显式向死信队列发送消息

[英]Java JMS - Send message to Dead Letter Queue explicitly

Is there a way to explicitly tell the broker to send a message to the queue's assigned dead letter queue?有没有办法明确告诉代理发送消息到队列的分配死信队列?

I know we can configure a queue to automatically send messages to the DLQ after a certain number of re-delivery attempts.我知道我们可以配置一个队列,在一定次数的重新投递尝试后自动将消息发送到 DLQ。 That makes perfect sense for transient errors such as database issues,.network issues, etc. However in the case of a business rule error, it doesn't make sense to have that message attempt redelivery X number of times over X number of minutes before being sent to the dead letter queue when we know it's a business rule violate / malformed message, etc.这对于数据库问题、网络问题等暂时性错误非常有意义。但是,在业务规则错误的情况下,让该消息在 X 分钟之前尝试重新传递 X 次是没有意义的当我们知道这是违反业务规则/格式错误的消息等时被发送到死信队列。

I was hoping there was a way that when we catch a business rule violation we can immediately send it to that queues dead letter queue.我希望有一种方法,当我们发现违反业务规则时,我们可以立即将其发送到死信队列。 I know I could explicitly write the code to send it to that dead letter queue but we will have many (dozens) of configurable queues and their associated dead letter queues will be configured by our middleware team.我知道我可以明确地编写代码将它发送到那个死信队列,但我们将有许多(几十个)可配置队列,它们相关的死信队列将由我们的中间件团队配置。 I don't want to explicitly code the dead letter queue queue names or even configure them in my own properties.我不想明确编码死信队列队列名称,甚至不想在我自己的属性中配置它们。 I'm hoping there is a simple way to tell the broker to immediately send the message to the dead letter queue and not attempt redelivery.我希望有一种简单的方法可以告诉代理立即将消息发送到死信队列,而不是尝试重新传递。

It seems like it should be something like message.deadLetter() .它似乎应该类似于message.deadLetter() I feel like I must be missing something simple but I don't see any mechanism like that on the consumer, session or message.我觉得我一定遗漏了一些简单的东西,但我没有在消费者 session 或消息上看到任何类似的机制。

There is no accommodation for the feature you're describing in the JMS specification.您在 JMS 规范中描述的功能没有任何便利。 The JMS spec incorporates redelivery via things like the JMSRedelivered header and JMSXDeliveryCount property. JMS 规范通过诸如JMSRedelivered header 和JMSXDeliveryCount属性之类的东西合并了重新传递。 However, it actually makes no mention of "dead-letter" destinations.然而,它实际上没有提到“死信”目的地。

That said, such a feature might be provided by a particular JMS broker, but since you don't mention what JMS broker implementation you're using it's impossible to say whether your chosen broker implements such a feature.也就是说,这样的功能可能由特定的 JMS 代理提供,但由于您没有提及您使用的是什么 JMS 代理实现,因此不可能说您选择的代理是否实现了这样的功能。 In any case, it would be configured and/or invoked via an implementation-specific mechanism that would be, by definition, non-portable between brokers and not available from the JMS API.在任何情况下,它都将通过特定于实现的机制进行配置和/或调用,根据定义,该机制在代理之间不可移植,并且无法从 JMS API 获得。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM