private IStanSubscription subscribe(string subject, string qgroup, EventHandler <StanMsgHandlerArgs> handler, StanSubscriptionOptions options) { AsyncSubscription sub = new AsyncSubscription(this, options); lock (mu) { if (nc == null) { throw new StanConnectionClosedException(); } // Register the subscription subMap[sub.Inbox] = sub; IConnection localNc = nc; } try { sub.subscribe(subRequests, subject, qgroup, handler); } catch { lock (mu) { subMap.Remove(sub.Inbox); } throw; } return(sub); }
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> /// 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 StanMsg(MsgProto p, AsyncSubscription s) { proto = p; sub = s; }