Beispiel #1
0
        private Boolean putMQMsg(MQMessage sendMsg)
        {
            try
            {
                int i = 0;

                //			while(true){
                //				try{
                //					if (cfgSendData.qManager == null || cfgSendData.queue == null) {
                //						initMQConnection();
                //					}
                //					return MQQueueAccesser.putMsgToQueue(cfgSendData, sendMsg);
                //				}catch(MQException mqe){
                //					i ++;
                //					int retInt = MQQueueAccesser.handleMQException(mqe);
                //					if (retInt == -1){
                //						boolean isT = initMQConnection();
                //						if (!isT)
                //							throw new EisException(MQCException.MQ_CONNECT_ERROR_EXCEPTION_CODE);
                //
                //					}
                //
                //					if (i > MQQueueAccesser.getConnPutMsgCount()){
                //						throw mqe;
                //					}
                //				}
                //			}

                while (true)
                {
                    try
                    {
                        if (cfgSendData.qManager == null || cfgSendData.queue == null)
                        {
                            initMQConnection();
                        }
                        return(MQQueueAccesser.putMsgToQueue(cfgSendData, sendMsg));
                    }
                    catch (MQException mqe)
                    {
                        LogUtil.Error("putMQMsg error", mqe);
                        int retInt = MQQueueAccesser.handleMQException(mqe);
                        if (retInt == MQQueueAccesser.MQ_CONNECTION_BROKER || retInt == MQQueueAccesser.MQ_UNKNOW_EXCEPTION || retInt == MQQueueAccesser.MQ_CONNECTION_BROKEN_2009)
                        {
                            Boolean isT = initMQConnection();
                            if (!isT)
                            {
                                throw new EisException(MQCException.MQ_CONNECT_ERROR_EXCEPTION_CODE);
                            }
                        }
                        else
                        {
                            throw mqe;
                        }
                        //对于2009类型的错误因为消息已经发出,所以如果接收到此错误则只是初始化连接,但不重发消息
                        if (retInt == MQQueueAccesser.MQ_CONNECTION_BROKEN_2009)
                        {
                            throw mqe;
                        }
                        i++;
                        if (i > MQQueueAccesser.getConnPutMsgCount())
                        {
                            throw mqe;
                        }
                    }
                }
            }
            catch (MQException mqe)
            {
                int retInt = MQQueueAccesser.handleMQException(mqe);

                if (retInt == 1)
                {
                    throw new EisException(MQCException.MQ_MSG_SEND_PUTMSG_ERROR_EXCEPTION_CODE, MQCException.MQ_MSG_SEND_PUTMSG_ERROR_EXCEPTION_DESC);
                }
                else if (retInt == -1)
                {
                    throw new EisException(MQCException.MQ_CONNECT_ERROR_EXCEPTION_CODE, MQCException.MQ_CONNECT_ERROR_EXCEPTION_DESC);
                }
                else if (retInt == -2)
                {
                    throw new EisException(MQCException.MQ_MSG_SEND_PUTMSG_ERROR_EXCEPTION_CODE, MQCException.MQ_MSG_SEND_PUTMSG_ERROR_EXCEPTION_DESC + mqe);
                }
                else
                {
                    throw new EisException(MQCException.MQ_MSG_SEND_PUTMSG_ERROR_EXCEPTION_CODE,
                                           MQCException.MQ_MSG_SEND_PUTMSG_ERROR_EXCEPTION_DESC
                                           + mqe);
                }
            }
            catch (Exception e)
            {
                throw new EisException(MQCException.MQ_MSG_SEND_PUTMSG_ERROR_EXCEPTION_CODE, MQCException.MQ_MSG_SEND_PUTMSG_ERROR_EXCEPTION_DESC);
            }
        }
Beispiel #2
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);
            }
        }