Ejemplo n.º 1
0
        public MQMsgRef receive(int timeout, MQMsgRef mqMsgRef)
        {
            if (cfgReceiveData == null)
            {
                throw new EisException("Fail to init receive queue.");
            }

            MQMessage receiveMsg = getMQMsg(mqMsgRef, timeout);

            if (receiveMsg == null)
            {
                throw new EisException("Fail to get mq msg.");
            }

            byte[] response = MQQueueAccesser.getBytesFromMQMessage(receiveMsg);

            //		logUtil.info("replyToQueueManagerName::" + receiveMsg.replyToQueueManagerName);
            //		if (logUtil.isInfoEnabled()) {
            //			StringBuffer sb;
            //			try {
            //				sb = new StringBuffer().append("receive message:\n").append(new String(response, encoding));
            //				logUtil.info(sb.toString());
            //			} catch (UnsupportedEncodingException e) {
            //				logUtil.error("Exception:", e);
            //			}
            //			sb = null;
            //		}

            MQMsgRef mQMsgRef = new MQMsgRef(receiveMsg.MessageId, response);

            return(mQMsgRef);
        }
Ejemplo n.º 2
0
        public MQMsgRef send(MQMsgRef msg)
        {
            if (cfgSendData == null)
            {
                throw new EisException("Fail to init send queue.");
            }

            if (msg == null || msg.MQMsgBody == null)
            {
                throw new EisException("Error in MQConnection : send message is null.");
            }

            //		if (logUtil.isInfoEnabled()) {
            //			StringBuffer sb;
            //			try {
            //				sb = new StringBuffer().append("send message:\n").append(new String(msg.MQMsgBody, encoding));
            //				logUtil.info(sb.toString());
            //			} catch (UnsupportedEncodingException e) {
            //				logUtil.error("Exception:", e);
            //			}
            //			sb = null;
            //		}

            MQMessage sendMsg = MQQueueAccesser.getMQMessageFromBytes(msg.MQMsgBody);

            //设置消息id
            if (msg != null && msg.MQMsgId != null && msg.MQMsgId.Length > 0)
            {
                sendMsg.MessageId     = msg.MQMsgId;
                sendMsg.CorrelationId = msg.MQMsgId;
            }

            //设置消息队列管理器
            if (msg != null && msg.ReplyToQMgr != null)
            {
                sendMsg.ReplyToQueueManagerName = msg.ReplyToQMgr;
                sendMsg.MessageType             = MQC.MQMT_REPLY;
            }

            //		sendMsg.encoding = cfgSendData.mqParameter.getCcsid();
            sendMsg.CharacterSet = cfgSendData.mqParameter.getCcsid();
            //		sendMsg.format = MQC.MQFMT_STRING;

            Boolean ret = putMQMsg(sendMsg);

            if (!ret)
            {
                throw new EisException("Fail to put mq msg.");
            }

            MQMsgRef mQMsgRef = new MQMsgRef();

            mQMsgRef.MQMsgId = sendMsg.MessageId;

            return(mQMsgRef);
        }
Ejemplo n.º 3
0
        private MQMessage getMQMsg(MQMsgRef mqMsgRef, int timeout)
        {
            MQMessage receiveMsg = null;

            try{
                int i = 0;

                while (true)
                {
                    try{
                        if (cfgReceiveData.qManager == null || cfgReceiveData.queue == null)
                        {
                            initMQConnection();
                        }

                        if (mqMsgRef == null || mqMsgRef.MQMsgId == null || mqMsgRef.MQMsgId.Length <= 0)
                        {
                            receiveMsg = MQQueueAccesser.getMsgFromQueue(null, cfgReceiveData, timeout);
                        }
                        else
                        {
                            receiveMsg = MQQueueAccesser.getMsgFromQueue(mqMsgRef.MQMsgId, cfgReceiveData, timeout);
                        }

                        return(receiveMsg);
                    }catch (MQException mqe) {
                        i++;
                        int ret = MQQueueAccesser.handleMQException(mqe);
                        if (ret == -1)
                        {
                            Boolean isT = initMQConnection();
                            if (!isT)
                            {
                                throw new EisException(MQCException.MQ_CONNECT_ERROR_EXCEPTION_CODE);
                            }
                        }
                        else if (ret == 1)
                        {
                            throw mqe;
                        }

                        if (i > MQQueueAccesser.getConnGetMsgCount())
                        {
                            throw mqe;
                        }
                    }
                }
            }catch (MQException mqe) {
                int ret = MQQueueAccesser.handleMQException(mqe);

                if (ret == 1)
                {
                    throw new EisException(MQCException.MQ_MSG_RECEIVE_GETMSG_TIMEOUT_EXCEPTION_CODE,
                                           MQCException.MQ_MSG_RECEIVE_GETMSG_TIMEOUT_EXCEPTION_DESC);
                }
                else if (ret == -1)
                {
                    throw new EisException(MQCException.MQ_CONNECT_ERROR_EXCEPTION_CODE);
                }
                else
                {
                    throw new EisException(MQCException.MQ_MSG_RECEIVE_GETMSG_ERROR_EXCEPTION_CODE + mqe);
                }
            } catch (Exception e) {
                throw new EisException(MQCException.MQ_MSG_RECEIVE_GETMSG_ERROR_EXCEPTION_CODE, MQCException.MQ_MSG_RECEIVE_GETMSG_ERROR_EXCEPTION_DESC);
            }
        }