0
votes

I'm new to the IBM Websphere MQ server and have few issues when I work with this. I'm using MQQueueConnectionFactory to send a message to a queue. Here is my code.

MQQueueConnectionFactory connectionFactory = null;
QueueConnection queueConn = null;
QueueSession queueSession = null;
QueueSender queueSender = null;
TextMessage message = null;

try
{
    connectionFactory = new MQQueueConnectionFactory();
    connectionFactory.setHostName("192.16.34.45");
    connectionFactory.setPort(1415);
    connectionFactory.setTransportType(1);
    connectionFactory.setQueueManager("MQSLLXQ1");
    connectionFactory.setChannel("TO.MQSLLXQ1");

    queueConn = connectionFactory.createQueueConnection("username", "password");
    queueSession = queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    queueSender = queueSession.createSender(queueSession.createQueue("TestQueue"));
    queueSender.setDeliveryMode(DeliveryMode.PERSISTENT);
    message = queueSession.createTextMessage("Test Message");
    queueSender.send(message);
    queueConn.close();

} catch (Exception je) {
    je.printStackTrace();
}

The message visible in the MQ queue with JMS header.

  <mcd><Msd>jms_text</Msd></mcd>
    <jms><Dst>queue:///TestQueue</Dst><Tms>1454047279356</Tms><Div>2</Div></jms>
   Test Message

1) Is there a way to avoid this jms header and get only the payload in MQ Queue?

2) Is there a way to sync both MQ Queue and JMS Queue together?

2

2 Answers

1
votes

JMS is an API specification, not a wire level protocol specification. So different vendors have their own way of implementing JMS API specification. IBM MQ (a.k.a WebSphere MQ) uses RFH2 headers to implement JMS API.

1) If you are using JMS API to receive the message, that header is made available to application as different message properties. The payload can be retrieved using message.getBody() (in MQ v8) method. Depending on type of the message, i.e. Text, Byte etc, you can use getText(), readBytes() etc methods to retrieve message body.

If your receiving application uses MQ APIs, then it's possible to strip off message headers by changing the queue properties.

2) In IBM MQ, a JMS queue actually points to a MQ Queue.

1
votes

If you are interested in using JMS to send a message to a traditional MQI application then the TARGCLIENT option of the JMS queue. Note that this will mean that some of the JMS properties won't be transferred.

As Shashi explained earlier on, the MQ JMS Queue points to the MQ Queue; it also has the properties that the MQ JMS code uses to know how to open the queue, properties to use etc.