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:
And the Header mapperCode:<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" />
My question: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; }
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:
Could you any idea how can I do it?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); }
Thank you!
Feri


Reply With Quote
