2

我正在编写一个 Java 批处理,它正在侦听来自队列(Oracle AQ)的消息并将它们发送到另一个队列(Tibco EMS),在那里它们由 Tibco 进程(BW)处理。

问题是 Oracle AQ 驱动程序会自动向消息(JMSXGroupID、JMSXGroupSeq)添加一些属性,这些属性在 Tibco 进程处理时会导致错误,因为它们具有错误的值:JMSXGroupSeq 应该是 int 但设置为 null。尝试解析消息属性时,Tibco 陷入错误...

所以我想从所有消息中只删除这两个属性,但似乎 jms api 只提供 clearProperties() 方法但没有单个属性删除方法(我使用的是 javax.jms.Message 接口)。

目前,我可以看到两种解决方案:

  1. 为这两个属性设置正确的值,因为我假设 Tibco 不会进一步使用它们

  2. 读取所有属性并重建没有导致问题的 2 的消息。但是这种方法非常丑陋...

有没有人有任何其他的解决方案?

4

2 回答 2

10

It is not possible to edit/clear some properties. We need to call clearProperties method as described here to get write access :

Once a message is produced (sent), its properties become read-only; the properties cannot be changed. While consumers can read the properties using the property accessor methods (getProperty( )), they cannot modify the properties using any of the mutator methods (setProperty( )). If the consumer attempts to set a property, the mutator method throws a javax.jms.MessageNotWriteableException.

Once a message is received, the only way its properties can be changed is by clearing out all the properties using the clearProperties( ) method. This removes all the properties from the message so that new ones can be added. Individual properties cannot be modified or removed once a message is sent.

于 2014-01-20T08:34:24.013 回答
0

javax.jms.Message接口的具体类实现中会有一个函数public void removeProperty(String name)。此类是特定于提供商的(在您的情况下为 Tibco EMS)。由于它是封闭源代码,我无法确定该功能的存在。但它存在于 HornetQ 中。它可用于重置特定的标头属性。

除此之外,我认为选项 1 是最好的。您将其设置为 Tibco EMS 的消息头解析器可接受的一些非空值。

于 2014-01-17T14:01:30.233 回答