Reputation: 1
I need to push a message into a remote Queue sending some header properties. In my side I'm using IBM MQ v9 and I must not use the MQRFH2, just the 'native' MQ header (I'm not sure if it is possible). But when I'm pull the message I can no see any of the properties.
import javax.jms.Destination;
import javax.jms.JMSContext;
import javax.jms.JMSException;
import javax.jms.JMSProducer;
import com.ibm.mq.jms.MQDestination;
import com.ibm.msg.client.jms.JmsConnectionFactory;
import com.ibm.msg.client.jms.JmsFactoryFactory;
import com.ibm.msg.client.wmq.WMQConstants;
public class MessageSender {
public void sendMessage() throws JMSException {
JMSContext context = createJMSContext();
JMSProducer producer = context.createProducer();
Destination destination = context.createQueue("queue:///" + queueName);
System.out.println("destination: " + destination);
MQDestination mqDestination = (MQDestination) destination;
// the header properties to be added
mqDestination.setStringProperty("KEY1", "VALUE1");
mqDestination.setStringProperty("KEY2", "VALUE2");
mqDestination.setStringProperty("KEY3", "VALUE3");
// WMQ_CLIENT_NONJMS_MQ - static final int WMQ_CLIENT_NONJMS_MQ
// WMQ_TARGET_CLIENT property value. Target is an MQ application (RFH2 will be excluded).
mqDestination.setTargetClient(WMQConstants.WMQ_CLIENT_NONJMS_MQ);
System.out.println("mqDestination: " + mqDestination);
String message = "mymessage";
producer.send(mqDestination, message);
}
private JMSContext createJMSContext() {
JMSContext context = null;
try {
JmsFactoryFactory ff = JmsFactoryFactory.getInstance(WMQConstants.WMQ_PROVIDER);
JmsConnectionFactory cf = ff.createConnectionFactory();
cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);
cf.setBooleanProperty(WMQConstants.USER_AUTHENTICATION_MQCSP, false);
cf.setStringProperty(WMQConstants.WMQ_HOST_NAME, "hostname");
cf.setStringProperty(WMQConstants.WMQ_CHANNEL, "channel");
cf.setIntProperty(WMQConstants.WMQ_PORT, 1411);
cf.setStringProperty(WMQConstants.WMQ_QUEUE_MANAGER, "queueManager");
context = cf.createContext();
} catch (JMSException e) {
e.printStackTrace();
}
return context;
}
}
Upvotes: 0
Views: 2115
Reputation: 7476
To add to Morag's comment, people get confused over terminology. An MQRFH2 message is the same as saying JMS message.
From a high-level, an MQRFH2 (JMS) message looks like:
[MQMD][MQRFH2]message payload
From a high-level, regular (native) MQ message looks like:
[MQMD]message payload
Upvotes: 1
Reputation: 7525
This code:-
mqDestination.setTargetClient(WMQConstants.WMQ_CLIENT_NONJMS_MQ);
is stripping the message properties off before the message is sent.
You say that you want to use the 'native header' and not 'MQRFH2' but the two are fully interchangeable. There is no one or the other, it is just how the message properties are presented to the receiver of the message depending on how they are capable of consuming them.
If you put messages properties and the receiver asks for them in RFH2 then that is what they will get.
If you build the correctly formed RFH2 header and the receiver asks for message properties then that is what they will get.
Remove the above mentioned line from your application and your message properties will flow to the receiver.
Upvotes: 1