ITeye博客

MQ 前端在某银行系统的调用

dmwdmc · 2013-06-17 11:12 · 消息服务 · 企业架构 · Markdown

这里说明下ibm mq在前端的调用, 后台mq怎么建立,怎么设管道,怎么管理,我不太清楚。 因为工作涉及到的只是前台。

想知道mq的线程安全和大对象问题,有知道的人帮忙给我留言。

在某银行系统里。 我们要发MQ到server端,然后从server端收response MQ. 配置文件定义。



首先我们要建立。 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);

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。