There are a number of ways to do this, as can be seen in the spread of comments and answers you have already received. How you do it really depends on you.
As Daniel states you can modify the queue url.
As Morag states you can use MQSC to alter the queue.
You can also do this by code. You haven't provided any code so its not easy to tell you how to do this, but if you cast your destination (queue) to an MQDestination you can exclude the RFH2 headers using the IBM JMS API.
RFH2 will be excluded
import javax.jms.Destination;
import com.ibm.mq.jms.MQDestination;
import com.ibm.msg.client.wmq.WMQConstants;
...
Destination destination = ...
...
MQDestination mqDestination = (MQDestination) destination;
destination.setTargetClient(WMQConstants.WMQ_CLIENT_NONJMS_MQ);
I have this tested with this service in Spring
import com.ibm.mq.jms.MQDestination;
import com.ibm.msg.client.wmq.WMQConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;
import javax.jms.*;
@Service
public class SendMessageNonJmsService {
protected final Log logger = LogFactory.getLog(getClass());
final private JmsTemplate myNonJmsTemplate;
@Autowired
private ConnectionFactory connectionFactory;
SendMessageNonJmsService(JmsTemplate myNonJmsTemplate) {
this.myNonJmsTemplate = myNonJmsTemplate;
}
public void sendAsNonJms(String msg) {
Destination destination = null;
JMSContext context = connectionFactory.createContext();
destination = context.createQueue("queue:///audit");
try {
MQDestination mqDestination = (MQDestination) destination;
mqDestination.setTargetClient(WMQConstants.WMQ_CLIENT_NONJMS_MQ);
}
catch (JMSException ex) {
logger.warn("JMSException preparing message destination : "
+ ex.getErrorCode() + " : "
+ ex.getMessage());
}
myNonJmsTemplate.send(destination, session -> session.createTextMessage(msg));
}
}
As an alternative if you want your sending code to be as simple as
public void sendAsNonJms(String msg) {
myNonJmsTemplate.send("audit", session -> session.createTextMessage(msg));
}
Then you can set a destination resolver on your JmsTemplate
@Bean("myNonJmsTemplate")
public JmsTemplate myNonJmsTemplate() {
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory);
jmsTemplate.setDestinationResolver(new OurDestinationResolver());
return jmsTemplate;
}
where your destination resolver looks something like:
import com.ibm.mq.jms.MQDestination;
import com.ibm.msg.client.wmq.WMQConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.support.destination.DestinationResolver;
import javax.jms.*;
public class OurDestinationResolver implements DestinationResolver {
protected final Log logger = LogFactory.getLog(getClass());
@Autowired
private ConnectionFactory connectionFactory;
@Override
public Destination resolveDestinationName(Session session, String dest, boolean pubSub) throws JMSException {
Destination destination = null;
if (pubSub) {
destination = session.createTopic(dest);
} else {
destination = session.createQueue(dest);
}
MQDestination mqDestination = (MQDestination) destination;
mqDestination.setTargetClient(WMQConstants.WMQ_CLIENT_NONJMS_MQ);
return destination;
}
}
queue:///YOUR.REQ.QUEUE?targetClient=1
to omit the RFH2 header. – Daniel Steinmann