Setting ApplIdentityData on a Liberty Profile defined queue

Setting the necessary properties on the Java Client for MQ libraries in order to pass the ApplIdentityData is quiet simple, as mentioned in this stackoverflow post:
MQDestination queue;
//...
queue.setBooleanProperty(WMQConstants.WMQ_MQMD_WRITE_ENABLED, true);
queue.setBooleanProperty(WMQConstants.WMQ_MQMD_READ_ENABLED, true);
queue.setIntProperty(WMQConstants.WMQ_MQMD_MESSAGE_CONTEXT, WMQConstants.WMQ_MDCTX_SET_ALL_CONTEXT);
javax.jms.Message message;
//...
message.setStringProperty(JmsConstants.JMS_IBM_MQMD_APPLIDENTITYDATA, "....");

The meaning of the properties is listed in the documentation: Destination object properties.

If using Websphere Application Server, you can define a Jms Queue as a Resource which can be intern looked up via JNDI. IBM has a pretty good summary of the different methods.
How to read and write fields from the MQMD via WebSphere MQ Classes for JMS Version 7: direct, using JNDI and using WebSphere Application Server.

To set it up in WAS7 for instance:
  • From the admin console
  • Resources/JMS/Queues
  • Select the scope you want to use from the drop down (i.e. Cluster=MYCLUSTER)
  • New
  • "WebSphere MQ messaging provider"
  • Name: any name you want
    JNDI Name: the jndi path you'll look it up via, i.e. jms/SendQ
    Queue name: the name of the queue on the queue manager
  • Apply
  • Advanced properties
    Uncheck "Append RFH version 2 headers to messages sent to this destination" to send raw MQ messages instead of JMS messages (with a JMS header)
  • Custom properties
    • Add name=MDR value=YES Description=WMQ_MQMD_READ_ENABLED Type=String
    • Add name=MDW value=YES Description=WMQ_MQMD_WRITE_ENABLED Type=String
    • Add name=MDCTX value=SET_IDENTITY_CONTEXT Description=WMQ_MQMD_MESSAGE_CONTEXT Type=String
  • Save
However in Websphere Liberty Profile the options are different. Here is a sample server.xml:
<server description="Sample MQ Server">

 <!-- Enable features -->
 <featuremanager onerror="WARN">
  <feature>jsp-2.2</feature>
  <feature>localConnector-1.0</feature>
  <feature>jndi-1.0</feature>
  <feature>jdbc-4.0</feature>
  <feature>webProfile-6.0</feature>
  <feature>wasJmsClient-1.1</feature>
    </featuremanager>

 <jmsqueueconnectionfactory jndiname="jms/qcf">
  <properties.wmqjms channel="MYCHANNEL" hostname="THEHOST" queuemanager="THEQUEUEMANAGER" transporttype="CLIENT"/>
 </jmsqueueconnectionfactory> 

 <jmsqueue id="qSend" jndiname="jms/SendQ">
  <properties.wmqjms arbitraryproperties='MDR="YES", MDW="YES", MDCTX="2"' basequeuename="MESSAGE.OUTBOUND" targetclient="MQ"/>
 </jmsqueue>

 <variable name="wmqJmsClient.rar.location" value="${shared.resource.dir}/wmq/wmq.jmsra.rar"/>

 <!-- http://pic.dhe.ibm.com/infocenter/wasinfo/v8r5/index.jsp?topic=%2Fcom.ibm.websphere.wlp.nd.doc%2Fae%2Ftwlp_servlet_load.html -->
 <webcontainer deferservletload="false"/>
</server>
If your using camel you would wire it up thus:
<beans xmlns:jee="http://www.springframework.org/schema/jee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <jee:jndi-lookup id="connectionFactory" jndi-name="jms/qcf"/>

    <bean class="org.apache.camel.component.jms.JmsComponent" id="jms">
        <property name="connectionFactory" ref="connectionFactory"/>
        <property name="destinationResolver" ref="jmsDestinationResolver"/>
    </bean>

    <bean class="org.springframework.jms.support.destination.JndiDestinationResolver" id="jmsDestinationResolver">
        <property name="jndiTemplate" ref="jndiTemplate"/>
    </bean>

    <bean class="org.springframework.jndi.JndiTemplate" id="jndiTemplate"/>

</beans>
And finally the route:
from("file:inputdir")
        .convertBodyTo(String.class)
        .setHeader("JMS_IBM_MQMD_ApplIdentityData", constant("USERNAMEPASSWORD"))
        .to("jms:queue:jms/SendQ");

Comments

Post a Comment