0
votes

I have used non-JMS java code to publish messages to IBM MQ and specifying various MQPutMessage Options to set the Identity Context

    public com.ibm.mq.MQQueue publishMQQueue() {
        MQQueueManager mqManager = null;
        com.ibm.mq.MQQueue mqQueue = null;
        try {
            MQEnvironment.hostname = pubHost;
            MQEnvironment.channel = pubChannel;
            MQEnvironment.port = pubPort;
            mqManager = new MQQueueManager(pubQmgr);
            int openOptions = CMQC.MQOO_OUTPUT | CMQC.MQOO_FAIL_IF_QUIESCING | CMQC.MQOO_SET_IDENTITY_CONTEXT;
            mqQueue = mqManager.accessQueue(pubQueue, openOptions);
        } catch (MQException e) {
            e.printStackTrace();
        }
        return mqQueue;
    }

Now to send a message

    public void sendMessage(Message m) {
        MQPutMessageOptions pmo = new MQPutMessageOptions();
        pmo.options = CMQC.MQPMO_SET_IDENTITY_CONTEXT | CMQC.MQPMO_SYNCPOINT;
        try {
            MQMessage mqMessage = new MQMessage();
            mqMessage.characterSet = 819;

            mqMessage.writeString(m.getPayload().toString());
            mqMessage.applicationIdData = "Test";
            mqMessage.format = "MQSTR";

            // ODSLogger.log(Level.FINE,"Sending light event...");
            mqQueue.put(mqMessage, pmo);
            mqQueue.connectionReference.commit();
        } catch (Exception e) {

        }
    }

When I try to use JMS template and added all the MQ put option, the message is getting published but the applicationIdentity context is not getting published to the queue

    public MQQueue publishMQQueue() {
        MQQueue mqQueue = null;
        try {
            mqQueue = new MQQueue(pubQmgr, pubQueue);
            mqQueue.setBooleanProperty(WMQConstants.WMQ_MQMD_WRITE_ENABLED, true);
            mqQueue.setIntProperty(WMQConstants.WMQ_MQMD_MESSAGE_CONTEXT, WMQConstants.WMQ_MDCTX_SET_ALL_CONTEXT);
            mqQueue.setMQMDWriteEnabled(true);
            mqQueue.setBooleanProperty(WMQConstants.WMQ_MQMD_READ_ENABLED, true);
        } catch (JMSException e) {
            logger.error("IngestionConfig::publishMQQueueConnectionFactory():Error in publishMQQueueConnectionFactory "
                    + e.getCause());
        }
        return mqQueue;
    }

    @Bean(name = "jmsTemplate")
    public JmsTemplate getJmsSendTemplate() {

        JmsTemplate jmsTemplate = new JmsTemplate();
        jmsTemplate.setConnectionFactory((ConnectionFactory) singleMQConnectionQueueFactory());
        jmsTemplate.setDefaultDestination((Destination) publishMQQueue());
        // jmsTemplate.setPubSubDomain(true);
        // jmsTemplate.setSessionAcknowledgeModeName("AUTO_ACKNOWLEDGE");
        // logger.debug("Queue for publishing is connected...");
        return jmsTemplate;
    }

JMS Send method -

    public void sendMessage(String message) {
        logger.info("MQMessageProcessor::sendMessage(): " + message + "  ::  " + publishQueue);
        try {
            jmsTemplate.send(publishQueue, new MessageCreator() {
                @Override
                public Message createMessage(Session session) throws JMSException {
                    TextMessage txtMsg = session.createTextMessage(message);
                    txtMsg.setStringProperty(JmsConstants.JMS_IBM_MQMD_APPLIDENTITYDATA, "Test")
                    return txtMsg;
                }
            });

        } catch (Exception jmsEx) {
            logger.info("MQMessageProcessor::sendMessage()::Exception:" + jmsEx.getMessage());
        }

    }

Am i doing something wrong

1
I "think" this it should be txtMsg.setStringProperty("JMS_IBM_MQMD_ApplIdentityData", "Test"). Note I think Case matters here. If that works I can write up a quick answer.JoshMc
I tried but it didn't worksam
Can you confirm you did use the mixed case?JoshMc
@sam: First of all, careful: You are using WMQ_MDCTX_SET_ALL_CONTEXT value in JMS code (as opposed to the plain code), this means Put Date and friends are not set.Daniel Steinmann
@sam: I tried your code on my machine and it works (Windows, MQ Client com.ibm.mq.allclient-9.1.4.0.jar, MQ Server 9.1.4.0). What are you using?Daniel Steinmann

1 Answers

0
votes

The JMS API does not expose all of the function in the underlying MQI. For context setting to work, the queue must first be opened with the appropriate MQOO values as you have in your first fragment. And the MQPUT uses MQPMO values to indicate that MQMD fields should be respected.

But those flags are not set by the JMS layer, so context cannot be set regardless of MQMD values.