这里说明下ibm mq在前端的调用, 后台mq怎么建立,怎么设管道,怎么管理,我不太清楚。
因为工作涉及到的只是前台。
想知道mq的线程安全和大对象问题,有知道的人帮忙给我留言。
在某银行系统里。
我们要发MQ到server端,然后从server端收response MQ.
配置文件定义。
[quote]<connector name="IbmMqConnector"
type="com.IbmMqConnector">
<property name="Gateway" value="u33.apac.ourcorp.com"/>
<property name="Port" value="1426"/>
<property name="Channel" value="CHANEL.HAHAECSID"/>
<property name="QueueManager" value="HAHA_QM.UAT"/>
<property name="SenderOptions" value="MQC.MQOO_OUTPUT"/>
<property name="ReceiverOptions" value="MQC.MQOO_INPUT_AS_Q_DEF"/>
<property name="SenderQueueName" value="ICRD.ID.TO_HAHAECS_REQ_M1.REMOTE"/>
<property name="ReceiverQueueName" value="ECS.ID.TO_HAHAICRD_RPL_M1.LISTEN"/>
<property name="WaitTime" value="30000"/>
<property name="Charset" value="037"/>
<property name="CodePage" value="IBM837"/>
<property name="TranID" value="MQII"/>
</connector>[/quote]
首先我们要建立。
MQQueueManager
这里我们看到 MQSimpleConnectionManager 里设置了timeout时间,容器大小,和发送方式。
然后我们可以建立发送队列。
建立这个发送对面,我们需要它的senderQueueName和senderOptions,他们分别是string ,int 类型,并且定义在配置文件中,表示目标服务端的机器名和发送选择。
然后我们在建立接收队列。
receiverQueueName,receiverOptions他们分别是string ,int 类型,并且定义在配置文件中,表示目标服务端的机器名和接收选择。
然后我们把前端收集的request里的所有值序列化成byte
bytesMessage是request的所有值。
然后把得出的bos转化string, codePage 从配置文件里去。
然后再把它放在putMessage里。
最后
把putMessage通过senderQueue发送出去了。
接收端原理雷同。
因为工作涉及到的只是前台。
想知道mq的线程安全和大对象问题,有知道的人帮忙给我留言。
在某银行系统里。
我们要发MQ到server端,然后从server端收response MQ.
配置文件定义。
[quote]<connector name="IbmMqConnector"
type="com.IbmMqConnector">
<property name="Gateway" value="u33.apac.ourcorp.com"/>
<property name="Port" value="1426"/>
<property name="Channel" value="CHANEL.HAHAECSID"/>
<property name="QueueManager" value="HAHA_QM.UAT"/>
<property name="SenderOptions" value="MQC.MQOO_OUTPUT"/>
<property name="ReceiverOptions" value="MQC.MQOO_INPUT_AS_Q_DEF"/>
<property name="SenderQueueName" value="ICRD.ID.TO_HAHAECS_REQ_M1.REMOTE"/>
<property name="ReceiverQueueName" value="ECS.ID.TO_HAHAICRD_RPL_M1.LISTEN"/>
<property name="WaitTime" value="30000"/>
<property name="Charset" value="037"/>
<property name="CodePage" value="IBM837"/>
<property name="TranID" value="MQII"/>
</connector>[/quote]
首先我们要建立。
MQQueueManager
MQQueueManager qManager=new MQQueueManager(QueueManagerName,(Port,Channel and so on),new MQSimpleConnectionManager(timeout,ini_poolsize,maxipoolsize,mode))
这里我们看到 MQSimpleConnectionManager 里设置了timeout时间,容器大小,和发送方式。
然后我们可以建立发送队列。
MQQueue senderQueue=qManager.accessQueue(senderQueueName, senderOptions);
建立这个发送对面,我们需要它的senderQueueName和senderOptions,他们分别是string ,int 类型,并且定义在配置文件中,表示目标服务端的机器名和发送选择。
然后我们在建立接收队列。
MQQueue receiverQueue = qManager.accessQueue(receiverQueueName, receiverOptions, QueueManagerName, "*", null);
receiverQueueName,receiverOptions他们分别是string ,int 类型,并且定义在配置文件中,表示目标服务端的机器名和接收选择。
然后我们把前端收集的request里的所有值序列化成byte
ByteArrayOutputStreambos = new ByteArrayOutputStream();
bos.write(bytesMessage, 0, bytesMessage.length);
bytesMessage是request的所有值。
然后把得出的bos转化string, codePage 从配置文件里去。
String string = bos.toString(codePage);
然后再把它放在putMessage里。
MQMessage putMessage = new MQMessage();
putMessage.clearMessage();
putMessage.messageId = MQC.MQMI_NONE;
putMessage.correlationId = MQC.MQCI_NONE;
putMessage.replyToQueueName = receiverQueue.name;
putMessage.format = MQC.MQFMT_STRING;
putMessage.messageType = MQC.MQMT_REQUEST;
putMessage.putApplicationType = MQC.MQAT_JAVA;
putMessage.expiry = ((waitTime / 1000) + 1) * 10; // set the expiry time as tenths of a second
putMessage.writeString(string);
最后
MQPutMessageOptions pmo = new MQPutMessageOptions();
senderQueue.put(putMessage, pmo);
把putMessage通过senderQueue发送出去了。
接收端原理雷同。
getMessage = new MQMessage();
getMessage.messageId = putMessage.messageId;
getMessage.correlationId = putMessage.correlationId;
receiverQueue.get(getMessage, gmo);
String responseMessage = null;
if (multipleByteReading) {
int msgLength = getMessage.getMessageLength();
byte byteArray[] = new byte[msgLength];
getMessage.readFully(byteArray);
responseMessage = new String(byteArray,codePage);
} else
responseMessage = getMessage.readLine();
byte[] response = responseMessage.getBytes(codePage);