public void Put1InQueue_Ok() { string message = "Put1InQueue"; using (var broker = MQQueueManager.Connect(QueueManagerName, 0, Channel, ConnectionInfo)) { var outgoing = new MQMessage() { CharacterSet = MQC.CODESET_UTF, Encoding = MQC.MQENC_NORMAL }; outgoing.WriteString(message); var od = new MQObjectDescriptor { ObjectType = MQC.MQOT_Q, ObjectName = QueueName }; broker.Put1(od, outgoing, new MQPutMessageOptions()); using (var q = broker.AccessQueue(QueueName, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING)) { var incoming = new MQMessage(); MQGetMessageOptions gmo = new MQGetMessageOptions(); gmo.WaitInterval = (int)TimeSpan.FromSeconds(30).TotalMilliseconds; //MQC.MQWI_UNLIMITED; gmo.Options |= MQC.MQGMO_WAIT; gmo.Options |= MQC.MQGMO_SYNCPOINT; q.Get(incoming, gmo); Assert.AreEqual(message, incoming.ReadString(incoming.DataLength)); } } }
/// <summary> /// 向消息队列推送一条消息 /// </summary> /// <param name="msg">消息内容</param> /// <param name="queueName">队列名称</param> public void PushMsgToQueue1(string msg, string queueName) { try { using (var mqmgr = MQQueueManager.Connect(IBMWMQConfig.QUEUE_MGR_NAME, MQC.MQCO_NONE, IBMWMQConfig.CHANNEL, IBMWMQConfig.CONNECTION_INFO)) { if (mqmgr.IsConnected) { var outgoing = new MQMessage() { CharacterSet = MQC.CODESET_UTF, Encoding = MQC.MQENC_NORMAL }; outgoing.WriteString(msg); var od = new MQObjectDescriptor { ObjectType = MQC.MQOT_Q, ObjectName = queueName }; mqmgr.Put1(od, outgoing, new MQPutMessageOptions()); } } } catch (MQException e) { Trace.WriteLine(e.ToString()); } }
private void InitializeTransactionRecovery() { uint method = 0x52a; this.TrEntry(method); try { if (this.recoveryHconn.XARecoveryBridge == null) { MQObjectDescriptor mqod = new MQObjectDescriptor(); mqod.ObjectType = 1; mqod.ObjectName = "SYSTEM.DOTNET.XARECOVERY.QUEUE"; if (this.recoveryHconn.Name != null) { mqod.ObjectQMgrName = this.recoveryHconn.Name; } int compCode = 0; int reason = 0; this.recoveryHobj = new Phobj(base.env); this.recoveryHconn.Session.MQFap.MQOPEN(this.recoveryHconn, ref mqod, this.recoveryQueueOpenOpts, ref this.recoveryHobj, out compCode, out reason, null); if (compCode != 0) { base.throwNewMQException(compCode, reason); } this.recoveryHconn.XARecoveryBridge = this; this.hostAndUser = Environment.MachineName + ", " + Environment.UserName; } } finally { base.TrExit(method); } }
public MQObjectDescriptor NewMQOD() { uint method = 0x2e9; this.TrEntry(method); MQObjectDescriptor result = new MQObjectDescriptor(); base.TrExit(method, result); return(result); }
public static void Put(this IMQQueueManager @this, string queueName, MQMessage message, MQPutMessageOptions pmo) { var od = new MQObjectDescriptor { ObjectType = MQC.MQOT_Q, ObjectName = queueName }; @this.Put1(od, message, pmo); }
public static void Publish(this IMQQueueManager @this, string topicName, MQMessage message, MQPutMessageOptions pmo) { var od = new MQObjectDescriptor { ObjectType = MQC.MQOT_TOPIC, ObjectName = string.Empty, Version = MQC.MQOD_VERSION_4 }; od.ObjectString.VSString = topicName; @this.Put1(od, message, pmo); }
public ManagedHobj(NmqiEnvironment env, int hobjInteger, MQProxyQueue proxyQueue, string objectName, int objectType, int openOptions, int defaultPersistence, int defaultPutReponseType, int defaultReadAhead, int defaultPropertyControl, MQObjectDescriptor objectDescriptor) : base(env) { base.TrConstructor("%Z% %W% %I% %E% %U%", new object[] { env, hobjInteger, proxyQueue, objectName, objectType, openOptions, defaultPersistence, defaultPutReponseType, defaultReadAhead, defaultPropertyControl, objectDescriptor }); this.value_ = hobjInteger; this.proxyQueue = proxyQueue; this.objectName = objectName; this.objectType = objectType; this.openOptions = openOptions; this.defaultPersistence = defaultPersistence; this.defaultPutResponseType = defaultPutReponseType; this.defaultReadAhead = defaultReadAhead; this.objectDescriptor = objectDescriptor; this.defaultPropertyControl = defaultPropertyControl; }
public static QueueManagerInfo GetQueueManagerInfo(NmqiEnvironment env, NmqiMQ mq, Hconn hconn) { QueueManagerInfo info = env.NewQueueManagerInfo(); MQObjectDescriptor pObjDesc = env.NewMQOD(); pObjDesc.ObjectType = 5; int options = 0x20; Phobj pHobj = env.NewPhobj(); int pCompCode = 0; int pReason = 0; mq.MQOPEN(hconn, ref pObjDesc, options, pHobj, out pCompCode, out pReason); if (pReason == 0) { Hobj hOBJ = pHobj.HOBJ; int[] pSelectors = new int[] { 0x1f, 0x20, 2, 0x7df, 0x7f0 }; int[] pIntAttrs = new int[3]; byte[] pCharAttrs = new byte[0x60]; mq.MQINQ(hconn, hOBJ, pSelectors.Length, pSelectors, pIntAttrs.Length, pIntAttrs, pCharAttrs.Length, pCharAttrs, out pCompCode, out pReason); if (pReason == 0) { info.CommandLevel = pIntAttrs[0]; info.Platform = pIntAttrs[1]; info.Ccsid = pIntAttrs[2]; Encoding dotnetEncoding = MQCcsidTable.GetDotnetEncoding(info.Ccsid); info.Name = dotnetEncoding.GetString(pCharAttrs, 0, 0x30); info.Uid = dotnetEncoding.GetString(pCharAttrs, 0x30, 0x30); } else { NmqiException exception = new NmqiException(env, 0x253a, null, pCompCode, pReason, null); env.LastException = exception; throw exception; } mq.MQCLOSE(hconn, pHobj, 0, out pCompCode, out pReason); return(info); } NmqiException exception2 = new NmqiException(env, 0x2525, null, pCompCode, pReason, null); env.LastException = exception2; throw exception2; }
public bool Reconnect(ManagedHconn remoteHconn) { uint method = 0x4c3; this.TrEntry(method, new object[] { remoteHconn }); int compCode = 0; int reason = 0; try { Phconn pHconn = base.env.NewPhconn(); remoteHconn.UnsetStarted(); remoteHconn.GlobalMessageIndex = 0; base.TrText(method, string.Concat(new object[] { "Hconn : ", remoteHconn.Value, " ReconnectionID : ", remoteHconn.ConnectionId })); remoteHconn.NmqiConnectionOptions.ReconnectionID = remoteHconn.ConnectionId; try { remoteHconn.DriveEventsEH(0, 0x9f0); } catch (Exception exception) { base.TrException(method, exception); } try { if (remoteHconn.NmqiConnectionOptions.RemoteQmidAsString == null) { remoteHconn.NmqiConnectionOptions.RemoteQmidAsString = remoteHconn.Uid; } base.TrText(method, string.Concat(new object[] { "Hconn : ", remoteHconn.Value, " RemoteQmidAsString : ", remoteHconn.NmqiConnectionOptions.RemoteQmidAsString })); } catch (NmqiException exception2) { base.TrException(method, exception2, 1); remoteHconn.SetReconnectionFailure(2, 0x9f4, exception2); return(false); } string name = null; try { name = remoteHconn.OriginalQueueManagerName; base.TrText(method, string.Concat(new object[] { "Hconn : ", remoteHconn.Value, " OriginalQueueManagerName : ", name })); } catch (NmqiException exception3) { base.TrException(method, exception3, 2); } MQFAP getMQFAP = remoteHconn.GetMQFAP; try { getMQFAP.NmqiConnect(name, remoteHconn.NmqiConnectionOptions, remoteHconn.ConnectionOptions, remoteHconn.Parent, pHconn, out compCode, out reason, remoteHconn); base.TrText(method, string.Concat(new object[] { "NmqiConnect during reconnect completed with CompCode = ", compCode, " Reason = ", reason })); if (compCode != 0) { return(false); } } catch (MQException exception4) { base.TrException(method, exception4, 3); if ((exception4.CompCode != 0) && (exception4.Reason == 0x9f2)) { remoteHconn.SetReconnectionFailure(2, 0x9f2, null); } return(false); } catch (Exception exception5) { base.TrException(method, exception5, 4); return(false); } if (remoteHconn.InTransaction()) { remoteHconn.SetTransactionDoomed(); } remoteHconn.UnSetQuiescing(); foreach (ManagedHobj hobj in remoteHconn.Hobjs) { if (hobj.ParentHsub == null) { Phobj manHobj = base.env.NewPhobj(); MQObjectDescriptor mqod = hobj.Mqod; Hobj hOBJ = manHobj.HOBJ; SpiOpenOptions spiOpenOpts = hobj.SpiOpenOpts; base.TrText(method, "Reopening " + mqod.ObjectName); base.TrText(method, "Original name " + hobj.OriginalObjectName); getMQFAP.nmqiOpen(remoteHconn, ref mqod, ref spiOpenOpts, hobj.OpenOptions, ref manHobj, out compCode, out reason, hobj.SpiCall, hobj); base.TrText(method, string.Concat(new object[] { "MQOPEN during reconnect completed with CompCode = ", compCode, " Reason = ", reason })); if (((reason == 0x825) || (reason == 0x827)) && !hobj.OriginalObjectName.Equals(mqod.ObjectName)) { string objectName = mqod.ObjectName; string dynamicQName = mqod.DynamicQName; compCode = 0; reason = 0; mqod.ObjectName = hobj.OriginalObjectName; mqod.DynamicQName = objectName; getMQFAP.MQOPEN(remoteHconn, ref mqod, hobj.OpenOptions, manHobj, out compCode, out reason, hobj); base.TrText(method, string.Concat(new object[] { "MQOPEN during reconnect completed with CompCode = ", compCode, " Reason = ", reason })); mqod.ObjectName = objectName; mqod.DynamicQName = dynamicQName; } if (reason != 0) { remoteHconn.SetReconnectionFailure(2, 0x9f4, new NmqiException(base.env, -1, null, compCode, reason, null)); return(false); } if (hobj.IsCallbackRegistered) { int operationP = 0x100; if (hobj.IsCallbackSuspended) { operationP |= 0x10000; } MQCBD callbackDescriptor = hobj.CallbackDescriptor; Hobj hobjP = hobj; MQMessageDescriptor callbackMessageDescriptor = hobj.CallbackMessageDescriptor; MQGetMessageOptions callbackGetMessageOptions = hobj.CallbackGetMessageOptions; getMQFAP.MQCB(remoteHconn, operationP, callbackDescriptor, hobjP, callbackMessageDescriptor, callbackGetMessageOptions, out compCode, out reason); base.TrText(method, string.Concat(new object[] { "MQCB during reconnect completed with CompCode = ", compCode, " Reason = ", reason })); if (reason != 0) { remoteHconn.SetReconnectionFailure(2, 0x9f4, new NmqiException(base.env, -1, null, compCode, reason, null)); return(false); } } } } foreach (ManagedHsub hsub in remoteHconn.Hsbjs) { int options = hsub.Mqsd.Options; if ((options & 1) != 0) { options |= 2; } if ((options & 0x20) == 0) { options |= 0x400000; } if (((options & 8) != 0) && ((options & 6) != 0)) { options |= 6; } hsub.Mqsd.Options = options; Phobj pHsub = base.env.NewPhobj(); Phobj pHobj = base.env.NewPhobj(); if (hsub.Mqsd.SubExpiry != -1) { hsub.Mqsd.SubExpiry = hsub.GeExpiryRemainder(); } getMQFAP.nmqiSubscribe(remoteHconn, hsub.Mqsd, ref pHobj, ref pHsub, out compCode, out reason, hsub.SpiSD, hsub.SpiCall, hsub); base.TrText(method, string.Concat(new object[] { "MQSUB during reconnect completed with CompCode = ", compCode, " Reason = ", reason })); if (reason != 0) { if (!ManagedHconn.IsReconnectableReasonCode(reason) && (reason != 0x97d)) { remoteHconn.SetReconnectionFailure(2, 0x9f4, new NmqiException(base.env, -1, null, compCode, reason, null)); } return(false); } ManagedHobj hobj3 = hsub.Hobj; if (((hobj3 != null) && (hobj3.ProxyQueue != null)) && hobj3.IsCallbackRegistered) { int num6 = 0x100; if (hobj3.IsCallbackSuspended) { num6 |= 0x10000; } MQCBD pCallbackDesc = hobj3.CallbackDescriptor; Hobj hobj4 = hobj3; MQMessageDescriptor pMsgDescP = hobj3.CallbackMessageDescriptor; MQGetMessageOptions getMsgOptsP = hobj3.CallbackGetMessageOptions; getMQFAP.MQCB(remoteHconn, num6, pCallbackDesc, hobj4, pMsgDescP, getMsgOptsP, out compCode, out reason); base.TrText(method, string.Concat(new object[] { "MQCB during reconnect completed with CompCode = ", compCode, " Reason = ", reason })); if (reason != 0) { remoteHconn.SetReconnectionFailure(2, 0x9f4, new NmqiException(base.env, -1, null, compCode, reason, null)); return(false); } } } if (remoteHconn.IsEventRegistered) { int num7 = 0x100; if (remoteHconn.IsEventSuspended) { num7 |= 0x10000; } getMQFAP.MQCB(remoteHconn, num7, remoteHconn.GetEventDescriptor(), base.env.NewPhobj().HOBJ, null, null, out compCode, out reason); base.TrText(method, string.Concat(new object[] { "MQCB during reconnect completed with CompCode = ", compCode, " Reason = ", reason })); if (reason != 0) { if (!ManagedHconn.IsReconnectableReasonCode(reason)) { remoteHconn.SetReconnectionFailure(2, 0x9f4, new NmqiException(base.env, -1, null, compCode, reason, null)); } return(false); } } if (remoteHconn.IsCallbackStarted()) { MQCTLO pControlOpts = base.env.NewMQCTLO(); getMQFAP.MQCTL(remoteHconn, 1, pControlOpts, out compCode, out reason); base.TrText(method, string.Concat(new object[] { "MQCTL during reconnect completed with CompCode = ", compCode, " Reason = ", reason })); if (reason != 0) { if (!ManagedHconn.IsReconnectableReasonCode(reason)) { remoteHconn.SetReconnectionFailure(2, 0x9f4, new NmqiException(base.env, -1, null, compCode, reason, null)); } return(false); } if (remoteHconn.IsCallbackSuspended()) { getMQFAP.MQCTL(remoteHconn, 0x10000, pControlOpts, out compCode, out reason); if (reason != 0) { if (!ManagedHconn.IsReconnectableReasonCode(reason)) { remoteHconn.SetReconnectionFailure(2, 0x9f4, new NmqiException(base.env, -1, null, compCode, reason, null)); } return(false); } } remoteHconn.WakeDispatchThread(); } } finally { base.TrExit(method, true, 11); } return(true); }