Announcement Announcement Module
Collapse
No announcement yet.
Send WebSphere MQ specific message Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Send WebSphere MQ specific message

    I have to send group message to an WebSphere MQ queue. I use Spring Integration. I did the connection factory, and other needed definition.
    To set up the header properties a header-enricher.
    I take here my config:
    Code:
    	<int:channel id="outMessSend" />
    	<int:channel id="outMessSendHeader" />
    
    	<bean id="mqConnFact" class="com.ibm.mq.jms.MQQueueConnectionFactory"> 
    		<property name="hostName" value="${MQ_HOST}" />
    		<property name="port" value="${MQ_PORT}" />
    		<property name="queueManager" value="${MQ_QUEUE_MANAGGER}" />
    		<property name="CCSID" value="${MQ_CCSID}" />
     		<property name="channel" value="${MQ_CHANNEL}" />
    		<property name="transportType">
    			<util:constant static-field="com.ibm.mq.jms.JMSC.MQJMS_TP_CLIENT_MQ_TCPIP" />
    		</property>
    	</bean>
    
            <bean id="jmsTrnManager" class="org.springframework.jms.connection.JmsTransactionManager">
                    <property name="connectionFactory" ref="mqConnFact" />
            </bean>
    
            <bean id="myHeaderMapper" class="MyHeaderMapper">
    		<property name="ccsId" value="${MQ_CCSID}" />
            </bean>
    
    	<bean id="inputDestination" class="com.ibm.mq.jms.MQQueue">
    		<constructor-arg value="${MQ_REPLAY_QUEUE}" />
    	</bean>
    
    	<bean id="outputDestination" class="com.ibm.mq.jms.MQQueue">
    		<constructor-arg value="${MQ_OUTPUT_QUEUE}" />
    		<property name="targetClient">
    			<util:constant static-field="com.ibm.mq.jms.JMSC.MQJMS_CLIENT_JMS_COMPLIANT" />
    		</property>
    	</bean>
    
    	<int:header-enricher input-channel="outMessSend" output-channel="outMessSendHeader">
    		<int:header name="SOURCE" value="${MQ_SOURCE}" />
    		<int:header name="DESTINATION" value="${MQ_DEST}" />
    	</int:header-enricher>
    
    	<jms:outbound-channel-adapter id="sendMessage"
    		connection-factory="mqConnFact" destination="outputDestination"
    		channel="outMessSendHeader" header-mapper="myHeaderMapper" />
    And the Header mapper
    Code:
    import java.text.DecimalFormat;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    
    import javax.jms.Message;
    import javax.jms.Queue;
    
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.integration.MessageHeaders;
    import org.springframework.integration.jms.DefaultJmsHeaderMapper;
    
    import com.ibm.mq.MQC;
    
    public class MyHeaderMapper extends DefaultJmsHeaderMapper
    {
        private static String lastId = "";
        private static int counter = 0;
    
        String Source;
        String Destination;
        String JmsType;
        String CcsId;
    
        @Autowired
        @Qualifier("inputDestination")
        Queue ReplyDest;
    
        @Override
        public void fromHeaders(MessageHeaders headers, Message jmsMessage)
        {
            Source = (String) headers.get("SOURCE");
            Destination = (String) headers.get("DESTINATION");
            //        JmsType = (String) headers.get("MQ_JMS_TYPE");
    
            //        headers.remove("MQ_JMS_TYPE");
    
            int lCcsId = 912;
            //        SplittedMessage splMess;  = new SplittedMessage(jmsMessage.getp);
            int actMsgNum;
            String messageId;
    
            super.fromHeaders(headers, jmsMessage);
    
            try
            {
                jmsMessage.setIntProperty("JMS_IBM_Feedback", 0);
    
                jmsMessage.setJMSReplyTo(ReplyDest);
    
                jmsMessage.setJMSDeliveryMode(MQC.MQPER_PERSISTENT);
    
                if (getCcsId() != null && getCcsId().matches("^\\d+$"))
                {
                    lCcsId = new Integer(getCcsId()).intValue();
                }
    
                jmsMessage.setIntProperty("JMS_IBM_Character_Set", lCcsId);
    
                jmsMessage.setStringProperty("JMS_IBM_Format", "MQRFH2");
    
                jmsMessage.setJMSPriority(5);
    
                jmsMessage.setIntProperty("JMS_IBM_MsgType", 1);
    
                // PERSISTENCE
                jmsMessage.setJMSDeliveryMode(MQC.MQPER_PERSISTENT);
    
                // Rto
                jmsMessage.setStringProperty("Rto", Source);
    
                // mqrfh2 <mcd>  //
                jmsMessage.setJMSType("mcd://none//BUSTYPE");
    
                //            splMess = jmsMessage.get
                messageId = getMessageId();
                jmsMessage.setJMSMessageID(messageId);
                jmsMessage.setJMSCorrelationID(messageId);
    
                jmsMessage.setIntProperty("Pmo", 1);
    
                // GroupID
                jmsMessage.setStringProperty("JMSXGroupID", messageId);
    
                // GroupCount
                actMsgNum = 1;
                jmsMessage.setIntProperty("JMSXGroupSeq", actMsgNum);
    
                // LastMsgMarker
                jmsMessage.setBooleanProperty("JMS_IBM_Last_Msg_In_Group", true);
    
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
    
        }
    
        public String getCcsId()
        {
            return CcsId;
        }
    
        public void setCcsId(String ccsId)
        {
            CcsId = ccsId;
        }
    
        public String getJmsType()
        {
            return JmsType;
        }
    
        public void setJmsType(String jmsType)
        {
            JmsType = jmsType;
        }
    
        private String getMessageId()
        {
            SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
            String messageId = sf.format(Calendar.getInstance().getTime());
            String addedValue;
    
            if (lastId.equals(messageId))
            {
                counter++;
                addedValue = new DecimalFormat("000").format(counter);
            }
            else
            {
                lastId = messageId;
                counter = 0;
                addedValue = "000";
            }
    
            messageId += addedValue;
    
            return messageId;
        }
    My question:
    I have to set up such parameters what don't part of header. I found some example (it use WSMQ API.), but this parameter is parameter of message put function. I have to fill the MQPutMessageOptions class options attribute.
    Here is the direct call example:
    Code:
    public void SendMsg(String Source, String Destination, String msgStr, String addInfo) throws MQException,
                                                                                                     IOException {
     
            MQPutMessageOptions putMsgOpt = new MQPutMessageOptions();
            putMsgOpt.options = MQC.MQPMO_SYNCPOINT | MQC.MQGMO_FAIL_IF_QUIESCING | MQC.MQPMO_DEFAULT_CONTEXT;
     
            MQMessage mBuf = new MQMessage();
            mBuf.clearMessage();
            mBuf.format = MQC.MQFMT_RF_HEADER_2;
            mBuf.messageType = MQC.MQMT_DATAGRAM;
            mBuf.correlationId = MQC.MQCI_NONE;
            mBuf.characterSet = 819;
     
            String msgId = CreateMsgId(); // if MQMI not set, so everyone can use the queue
            mBuf.messageId = msgId.getBytes();
            messageID = msgId;
     
            mBuf.writeString(MQC.MQRFH_STRUC_ID); //length 4 byte
            mBuf.writeInt4(MQC.MQRFH_VERSION_2);
     
            String nameValueData1 = "<mcd><Msd>none</Msd><Set></Set><Type>" + MsgType + "</Type><Fmt></Fmt></mcd>";
            while (nameValueData1.length() % 4 != 0) {
                nameValueData1 += " ";
            }
            String nameValueData2 =
                "<usr><ROUTING><SOURCE>" + Source + "</SOURCE><DESTINATION>" + Destination + "</DESTINATION></ROUTING>";
            nameValueData2 += "<MSGLINEDELIMITER>" + newLineStr + "</MSGLINEDELIMITER>";
            nameValueData2 += "<ADDITIONALINFO>" + addInfo + "</ADDITIONALINFO></usr>";
            while (nameValueData2.length() % 4 != 0) {
                nameValueData2 += " ";
            }
     
            mBuf.writeInt4(MQC.MQRFH_STRUC_LENGTH_FIXED_2 + nameValueData1.length() + nameValueData2.length() + 8);
            mBuf.writeInt4(MQC.MQENC_NATIVE);
            mBuf.writeInt4(912);
            mBuf.writeString(MQC.MQFMT_NONE); //length 8 byte
            mBuf.writeInt4(MQC.MQRFH_NO_FLAGS);
            mBuf.writeInt4(1208);
            mBuf.writeInt4(nameValueData1.length());
            mBuf.writeString(nameValueData1);
            mBuf.writeInt4(nameValueData2.length());
            mBuf.writeString(nameValueData2);
            mBuf.write(msgStr.getBytes("ISO-8859-2"));
            queue.put(mBuf, putMsgOpt);
    }
    Could you any idea how can I do it?

    Thank you!
    Feri
    Last edited by take5; Mar 11th, 2013, 02:57 PM.

  • #2
    This is the native MQ API; not JMS - therefore you can't use the JMS adapters.

    If you need to use the native MQ APIs, simply invoke that code using a <service-activator/> instead.

    Comment


    • #3
      Hi Gary,
      Thank you your answer.
      Yes, the last code, what I sent, is MQ API. I'm looking for something, what help to set up parameters in SI.
      My solution is ready, as you see, but the other side couldn't read my message. If possible, I would use the SI, because this is teh base of the development.

      Do you have any idea?
      Thx
      Feri

      Comment


      • #4
        Hi!

        Why do you use direct WebSphere MQ API? How about to use WebSphere MQ JMS implementation: http://publib.boulder.ibm.com/infoce...2Fjm10120_.htm

        HTH,
        Artem

        Comment


        • #5
          Hi Artem,

          It is a misunderstanding. I don't use Ws MQ API. The inserted source only an example, what contains that property what I want to set, (putMsgOprion variable - underscored) and I don't know haw can I do that.

          Do you have any idea?
          Thx
          Feri

          Comment


          • #6
            Hi,

            So, I'm sorry, it was my mistake. I read, and I found that, if I use JMS, then I don't need this property. Every other property, what I need, I can set up.

            Thank you your attention.
            Feri

            Comment

            Working...
            X