如何通过 Stomp/JSON 在 ActiveMQ 中使用 JMS 消息转换

发布于 2024-07-11 04:48:08 字数 553 浏览 7 评论 0原文

我正在将 JSON 格式的消息发送到 ActiveMQ 服务器。 我正在尝试使用 JMS 转换将 JSON 编码对象转换为真正的 Java 对象,希望能够在内部数据上使用选择器。

此处是有关 Stomp 和消息转换的文档的链接。 此处是有关该补丁的讨论的链接,其中有人展示了合法 JSON 对象的示例

我发送的 JSON 对象的格式(以漂亮的打印形式)与此类似:

{
   "msg": {
      "flag1" : "value1",
      "flag2" : "value2"
   }
}

消息到达消息队列,但转换错误属性设置为“msg : msg” 。

I am sending messages in JSON format to an ActiveMQ server. I am trying to use JMS Transformation to transform the JSON encoded object into a true Java Object in hopes of being able to use selectors on the data inside.

Here is a link to the documentation on Stomp and Message Transformation.
Here is a link to a discussion on the patch where someone shows an example of a legal JSON object

The format of the JSON objects I am sending (in pretty print) are similar to this:

{
   "msg": {
      "flag1" : "value1",
      "flag2" : "value2"
   }
}

The messages arrive in the message queue, but with the transformation-error property set to 'msg : msg'.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷迭香的记忆 2024-07-18 04:48:09

您可以使用任何 JSON 表示法进行 jms-object-json 转换,只要 XStream 可以处理它即可。 您可以查看测试用例以获取一些示例。 在那里,我们使用 SamplePojo 类:

https://svn.apache.org/repos/asf/activemq/trunk/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/SamplePojo .java

已正确注释,因此可以用以下 JSON

{"pojo":{ 表示
"name":"德扬",
“城市”:“贝尔格莱德”

可以尝试对您的课程使用相同的方法。

希望这可以帮助,
德扬

you can use any JSON notation for your jms-object-json transformations as long as XStream can handle it. You can take a look at test cases for some examples. There, we use SamplePojo class:

https://svn.apache.org/repos/asf/activemq/trunk/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/SamplePojo.java

which is properly annotated so it can be represented with the following JSON

{"pojo":{
"name":"Dejan",
"city":"Belgrade"
}}

You can try using the same approach for your classes.

Hope this helps,
Dejan

梦幻的味道 2024-07-18 04:48:09

应该提到的是,ActiveMQ 版本必须至少为 5.8,因为使用 5.6 版本时,我遇到了转换不起作用的问题。

It should be mentioned that ActiveMQ version must at least 5.8, because with 5.6 version I had problem when transformation just did not work.

爱情眠于流年 2024-07-18 04:48:08

转换 jms-map-json 或 jms-object-json 接受的唯一格式是简单的 Map 格式,在 JSON 中为:

{"map" : 
  {"entry" : 
    [ 
      { "string1": [ "key1", "value1" ] },
      { "string2": [ "key2", "value2" ] }
    ]
  }
}

这与讨论论坛中显示的格式相同。 这种格式表示java中的名称/值对映射对象。

选择器仅可用于属性和标题。

The only format accepted by the transformation jms-map-json or jms-object-json is a simple Map format, which in JSON is:

{"map" : 
  {"entry" : 
    [ 
      { "string1": [ "key1", "value1" ] },
      { "string2": [ "key2", "value2" ] }
    ]
  }
}

This is the same format shown in the discussion forum. This format represents a name/value pair map object in java.

Selectors are only usable on Properties and Headers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文