internal void processMsg(object sender, MsgHandlerEventArgs args) { bool isClosed = false; AsyncSubscription sub = null; Msg raw = null; MsgProto mp = new MsgProto(); ProtocolSerializer.unmarshal(args.Message.Data, mp); raw = args.Message; lock (mu) { isClosed = (nc == null); subMap.TryGetValue(raw.Subject, out sub); } if (isClosed || sub == null) { return; } sub.processMsg(mp); }
/// <summary> /// Internal constructor. /// </summary> /// <param name="proto">The message including protocol information.</param> /// <param name="subscription">The subscription.</param> internal StanMsg(MsgProto proto, object subscription) { Covenant.Requires <ArgumentNullException>(proto != null, nameof(proto)); this.proto = proto; this.sub = subscription; }
internal static byte[] createAck(MsgProto mp) { Ack a = new Ack(); a.Subject = mp.Subject; a.Sequence = mp.Sequence; return(a.ToByteArray()); }
/// <summary> /// Constructor for generating a StanMsg object. Used only for application unit testing. /// </summary> /// <remarks> /// Objects of this type are normally generated internally by the NATS streaming client. /// This constructor has been provided to facilitate application unit testing. /// </remarks> /// <param name="data">The message payload.</param> /// <param name="redelivered">True if the message may have been redelivered.</param> /// <param name="subject">Subject of the message</param> /// <param name="timestamp">Message timestamp, nanoseconds since epoch (1/1/1970)</param> /// <param name="sequence">Sequence number of the message.</param> /// <param name="subscription">Subscription of the message. Must be a valid streaming subscription or null.</param> public StanMsg(byte[] data, bool redelivered, string subject, long timestamp, ulong sequence, IStanSubscription subscription) { proto = new MsgProto(); proto.Data = Google.Protobuf.ByteString.CopyFrom(data); proto.Redelivered = redelivered; proto.Subject = subject; proto.Sequence = sequence; proto.Timestamp = timestamp; sub = (AsyncSubscription)subscription; }
internal void processMsg(MsgProto mp) { rwLock.EnterReadLock(); EventHandler <StanMsgHandlerArgs> cb = handler; bool isManualAck = options.manualAcks; string localAckSubject = ackInbox; IStanConnection subsSc = sc; IConnection localNc = null; if (subsSc != null) { localNc = sc.NATSConnection; } rwLock.ExitReadLock(); if (cb != null && subsSc != null) { StanMsgHandlerArgs args = new StanMsgHandlerArgs(new StanMsg(mp, this)); cb(this, args); } if (!isManualAck && localNc != null) { byte[] b = ProtocolSerializer.createAck(mp); try { localNc.Publish(localAckSubject, b); } catch (Exception) { /* * Ignore - subscriber could have closed the connection * or there's been a connection error. The server will * resend the unacknowledged messages. */ } } }
internal StanMsg(MsgProto p, AsyncSubscription s) { proto = p; sub = s; }
/// <summary> /// Constructs an instance from a low-level message and subscription. /// </summary> /// <param name="proto">The message including protocol information.</param> /// <param name="subscription"> /// <para> /// The subscription. /// </para> /// <note> /// This needs to be passed as an <see cref="object"/> because /// <c>STAN.Client.AsyncSubscription</c> is defined as <c>internal</c>. /// </note> /// </param> internal StanMsgHandlerArgs(MsgProto proto, object subscription) { this.Msg = new StanMsg <TMessage>(proto, (IStanSubscription)subscription); }
/// <summary> /// Uses reflection to to construct a new <see cref="StanMsg"/>. /// </summary> /// <param name="proto">The message including protocol information.</param> /// <param name="sub">The subscription.</param> internal static StanMsg NewStanMsg(MsgProto proto, object sub) { return((StanMsg)stanMsgConstructor.Invoke(new object[] { proto, sub })); }