How to set ApplicationIdData using MQQueueConnecti

2019-02-28 07:41发布

问题:

Trying to figure out the camel/Spring configuration to set ApplicationIdData using JMS.

I know the java way to do it as below, I set MQOO_SET_IDENTITY_CONTEXT using below

int putOptions =  MQConstants.MQPMO_SET_IDENTITY_CONTEXT;
pmo.options =putOptions;

and then i set applicationIdData as:

MQMessage msg = new MQMessage();
msg.applicationIdData = "SomeId";
msg.writeString(qmessage);

queue.put(msg, pmo);

Question is, How do I set applicationIdData using JMS/camel/Spring configuration. Below is my current camel configuration.

<bean class="org.apache.camel.component.jms.JmsComponent" id="jmsConnection">
        <property name="connectionFactory" ref="mqConnectionFactoryWrapper" />
        <property name="acknowledgementModeName" value="AUTO_ACKNOWLEDGE" />
    </bean>

    <bean id="connectionFactory" class="com.ibm.mq.jms.MQQueueConnectionFactory">
        <property name="hostName" value="${HOSTMNAME}" />
        <property name="port" value="${PORT}" />
        <property name="queueManager" value="${MQ_QMNAME}" />
        <property name="channel" value="${MQ_INTERNAL_CHANNEL}" />
        <property name="transportType" value="1" />

        <!-- Transport type 1 means pure TCP/IP without any local client -->
    </bean>

    <bean id="mqConnectionFactoryWrapper"
        class="org.springframework.jms.connection.CachingConnectionFactory">
        <property name="targetConnectionFactory" ref="connectionFactory" />
        <property name="sessionCacheSize" value="500" />
    </bean>

    <bean id="jmsTransactionManager"
        class="org.springframework.jms.connection.JmsTransactionManager">
        <property name="connectionFactory" ref="mqConnectionFactoryWrapper" />
    </bean>

    <bean id="PROPAGATION_REQUIRES_NEW" 
class="org.apache.camel.spring.spi.SpringTransactionPolicy">
        <property name="transactionManager" ref="jmsTransactionManager" />
        <property name="propagationBehaviorName" value="PROPAGATION_REQUIRES_NEW" />
    </bean>

I have gone through below links, couldnt find the right answer

http://forum.spring.io/forum/spring-projects/integration/jms/97168-how-to-set-wmqconstants-wmq-mqmd-read-enabled-in-spring

http://www.ibm.com/support/knowledgecenter/SSFKSJ_7.0.1/com.ibm.mq.csqzaw.doc/jm41030_.htm

https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_9.0.0/com.ibm.mq.dev.doc/q032010_.htm

回答1:

All I needed to find a way in camel config to set some properties in the destination and set some header. I set destination in the header as

<setHeader headerName="CamelJmsDestinationName"> queue:///Q_Name?targetClient=1&mdWri‌​teEnabled=true&a‌​mp;mdMessageContext=‌​1</setHeader>

Note: Setting mdWri‌​teEnabled=true is equal to

 // Enable MQMD write
  dest.setBooleanProperty(WMQConstants.WMQ_MQMD_WRITE_ENABLED, true);

Setting mdMessageContext=‌​1 is equal to

// Optionally, set a message context if applicable for this MD field
  dest.setIntProperty(WMQConstants.WMQ_MQMD_MESSAGE_CONTEXT, 
    WMQConstants.WMQ_MDCTX_SET_IDENTITY_CONTEXT);

Then set ApplicationIdData as <setHeader headerName="JMS_IBM_MQMD_ApplIdentityData" > BSI_XML_CANADA_ACK BSI_XML_CANADA_ACK </setHeader>

Complete code:

<route id="ValidateAndAck" streamCache="true">
            <from uri="sql:{{ValidateCDMsg}}" />
            <setHeader headerName="CamelJmsDestinationName"> <constant>queue:///Q_Name?targetClient=1&amp;mdWriteEnabled=true&amp;mdMessageContext=1</constant></setHeader> 
            <setHeader headerName="mdWriteEnabled">  <simple>true</simple></setHeader> <!-- This may be redundant-->
            <setHeader headerName="mdMessageContext">  <simple>2</simple></setHeader> <!-- This may be redundant--> 
            <setHeader headerName="JMS_IBM_MQMD_ApplIdentityData" >
                <simple>APP_ID_NAME</simple>
            </setHeader>
            <setHeader headerName="JMS_IBM_MQMD_ApplOriginData" >
                <simple>APP_ID_NAME</simple>
             </setHeader> 
            <to uri="bean:ProcessBean?method=setProcessId" />

I am not sure that JMS_IBM_MQMD_ApplOriginData is required.