java - JMS 2.0 规范 - JMS 提供者如何检测 JMS 客户端对 Message 对象的更改?

标签 java jms activemq

我正在阅读 JMS 2.0 规范,其中提到(相关摘录下方)如果客户端尝试修改 Message 对象,则 JMS 提供程序可能会抛出异常。

我的问题是 JMS 提供者如何知道客户端是否试图修改 Message 对象,因为 Message 对象将通过线路传输,并且在 JMS 提供者端它不是同一个堆对象,所以即使客户端修改了该 Message对象,JMS 提供者无法检测到更改。

我错过了什么吗?

7.3.9. Restrictions on the use of the Message object

Applications which perform an asynchronous send must take account of the restriction that a Message object is designed to be accessed by one logical thread of control at a time and does not support concurrent use. See section 2.14 “Multi-threading”.

After the send method has returned, the application must not attempt to read the headers, properties or body of the Message object until the CompletionListener’s onCompletion or onException method has been called. This is because the JMS provider may be modifying the Message object in another thread during this time.

A JMS provider may throw a JMSException if the application attempts to access or modify the Message object after the send method has returned and before the CompletionListener has been invoked. If the JMS provider does not throw an exception then the behaviour is undefined.

最佳答案

此摘录在此处将 JMS 客户端实现称为 JMS 提供者,它告诉您一旦您使用异步 API 调用发送,您将不再控制消息,直到通知异步完成或成功或失败事件。

客户端通常会在发送调用上使用内部“只读”标志来标记消息现在不会被客户端代码触及,并且会在之后将只读状态重置回读/写发送调用以一种或另一种方式完成。

关于java - JMS 2.0 规范 - JMS 提供者如何检测 JMS 客户端对 Message 对象的更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44504240/

相关文章:

在 switch 表达式中尝试记录模式时出现 Java 19 编译器问题

java - Python 和 Java 之间的 For 循环区别

java - 如何重写不是为扩展设计的方法

java - BorderLayout 中心的网格

security - WebSphere 7,配置没有用户 ID : MQRC_NOT_AUTHORIZED 的 JMS Q 连接工厂

session - ActiveMQ,多 session 与多连接

spring-boot - SpringBoot ActiveMQ 通过1099禁用JMX连接

java - Mule 持久 ActiveMQ 重新交付策略

java - Spring Boot JMS - 何时应在 @Transacted 方法上发送消息?

java - IBM MQ V6.0 是否设置 JMSXDeliveryCount 属性?