【问题标题】:javax.jms.MessageFormatException: Invalid message formatjavax.jms.MessageFormatException:消息格式无效
【发布时间】:2013-04-04 00:41:50
【问题描述】:

当我尝试在 Glassfish 3.1 Open MQ 上使用 JMS 在 MapMessage 中发送 Date 对象时,我收到以下错误:

javax.jms.MessageFormatException: [C4017]: Invalid message format.

以下是我如何尝试在MapMessage 中发送Date 对象的代码:

public class JSenderMockClient {
    public static void main(String[] args) {
        try {           
            //using jndiContext to get ConnectionFactory, Queue, Session and stuff

            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            MessageProducer producer = session.createProducer(destination);

            MapMessage mapMessage = session.createMapMessage();
            mapMessage.setObject("now", new Date());

            producer.send(mapMessage);

            System.out.println("MapMessage \"now\" sent..");            
        } catch (Throwable ex) {
            //just in case stuff
        } finally {
            //closing session and connection
        }
    }
}

有人可以帮我理解为什么会出现这个异常吗?

谢谢。

【问题讨论】:

    标签: date jms java-ee-6 glassfish-3 message-queue


    【解决方案1】:

    我认为 MapMessage 只支持字符串和原语。您可以将日期序列化为字符串,也可以使用 ObjectMessage。

    要序列化日期,您可以使用SimpleDateFormat

    见bind a custom object to a JMS MapMessage

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-06-26
      • 1970-01-01
      • 2022-01-13
      • 2011-11-25
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 2021-05-10
      相关资源
      最近更新 更多