ibm-messaging / mq-jms-spring

Components to assist MQ JMS integration with Spring frameworks
Apache License 2.0
190 stars 102 forks source link

MessageBodyStyle and TextMessage customization #39

Closed doppiak closed 4 years ago

doppiak commented 5 years ago

Is it possible to set messageBodyStyle and customizing TextMessage (setting WMQConstants.JMS_IBM_CHARACTER_SET)? How?

Using javax.jms I can do: ((MQDestination) sender.getDestination()).setMessageBodyStyle(WMQConstants.WMQ_MESSAGE_BODY_MQ);

and I can customize TextMessage like this:

final TextMessage msg = session.createTextMessage(); msg.setIntProperty(WMQConstants.JMS_IBM_CHARACTER_SET, 37);

Thank you

ibmmqmet commented 4 years ago

There's probably quite a few ways to do this, depending on how you are writing the rest of the JMS code. This Spring Boot component itself doesn't mandate how you create messages or destinations - it only really helps with the ConnectionFactory setup. But given that a lot of Spring Framework samples use the simple JmsTemplate class, then this may work for you, using a MessagePostProcessor:

jmsTemplate.convertAndSend(qName, inputMsg, ppMsg -> {
      MQDestination dest = new MQDestination(qName);  
      dest.setMessageBodyStyle(WMQConstants.WMQ_MESSAGE_BODY_MQ);
      ppMsg.setJMSDestination(dest);
      if (ppMsg instanceof TextMessage) {
        ppMsg.setIntProperty(WMQConstants.JMS_IBM_CHARACTER_SET, 37);
      }     
      return ppMsg;
  });
ibmmqmet commented 4 years ago

answered. no additional followup.