将自定义对象绑定到 JMS MapMessage

发布于 2025-01-02 01:22:12 字数 469 浏览 2 评论 0原文

是否有一种标准方法可以将我自己的自定义对象添加到 Map,然后将其正确编组到 MapMessage 中?目前我收到无效的对象类型消息。我注意到WebSphere有一个解决方案,但我正在寻找一些不绑定到特定AS的东西,如果没有这样的方法,也许JBoss支持的东西可以工作。

如何在 WebSphere 中执行此操作: http://publib.boulder.ibm.com/infocenter/dmndhelp/v6rxmx/index.jsp?topic=/com.ibm.websphere.wesb.doc/ref/rwesb_jmscustombindings.html

Is there a standard way for me to add my own custom object to a Map and then have it properly marshalled in a MapMessage? Currently I get the Invalid Object Type message. I noticed that WebSphere has a solution but I am looking for something that is not bound to a particular AS, if there is no such method, maybe something supported by JBoss would work.

How to do it in WebSphere:
http://publib.boulder.ibm.com/infocenter/dmndhelp/v6rxmx/index.jsp?topic=/com.ibm.websphere.wesb.doc/ref/rwesb_jmscustombindings.html

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

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

发布评论

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

评论(2

愁杀 2025-01-09 01:22:12

JMS 映射消息的映射仅支持基元和字符串(及其数组)作为值。
来自 javadoc

名称是 String 对象,值是原始数据类型
在 Java 编程语言中。

您最好使用 ObjectMessage 并将序列化对象写入映射然后将地图作为 ObjectMessage 的有效负载发送。这样,您仍然可以拥有名称/值映射访问样式,但不受类型限制。

A JMS map message's map only supports primitives and strings (and their arrays) as values.
From the javadoc:

The names are String objects, and the values are primitive data types
in the Java programming language.

You would be better off using an ObjectMessage and write your serialized objects to a map and then send the map as the payload of the ObjectMessage. That way, you can still have the name/value map access style but without the limitation of types.

牛↙奶布丁 2025-01-09 01:22:12

使用 JsmTemplate在 Spring (2.5, 3.1) 中,如果您想通过 jmsTemplate.convertAndSend() 发送 Map,其中 Map 包含非原始对象,您可以将 Map 转换为 Serialized 并调用 send(MessageCreator) 。这边走:

//...some previous code here

final Map myMap = createYourSerializableMapHere();

jmsTemplate.send(new MessageCreator(){

    @Override
    public Message createMessage(Session session) throws JMSException {
        ObjectMessage objectMessage = session.createObjectMessage((Serializable) myMap);

        return objectMessage;
    }
});

这样 jmsTemplate 将与可序列化的映射一起使用,并通过线路发送 ObjectMessage

请注意,使用消息的侦听器必须能够读取 ObjectMessage,然后再次将其转换为 Map。请注意,线路的两端都必须有相应的类,当然,Map 内的对象必须是可序列化的!

With JsmTemplate in Spring (2.5, 3.1), if you want to send a Map through jmsTemplate.convertAndSend() where the Map contains a non-primitive object, you could cast the Map as Serializable and call send(MessageCreator) . This way:

//...some previous code here

final Map myMap = createYourSerializableMapHere();

jmsTemplate.send(new MessageCreator(){

    @Override
    public Message createMessage(Session session) throws JMSException {
        ObjectMessage objectMessage = session.createObjectMessage((Serializable) myMap);

        return objectMessage;
    }
});

This way jmsTemplate will work with the Map as Serializable and will send an ObjectMessage over the wire.

Note that the listener consuming messages will have to be able to read the ObjectMessage and then cast it as Map again. Be aware that you have to had the corresponding classes at both sides of the wire, and of course, the objects inside the Map has to be Serializable!

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