示例#1
0
        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;
            }

            StanMsg msg = new StanMsg(mp, sub);

            sub.processMsg(mp);
        }
示例#2
0
        internal void manualAck(StanMsg m)
        {
            if (m == null)
            {
                return;
            }

            rwLock.EnterReadLock();

            string     localAckSubject = ackInbox;
            bool       localManualAck  = options.manualAcks;
            Connection sc = this.sc;

            rwLock.ExitReadLock();

            if (localManualAck == false)
            {
                throw new StanManualAckException();
            }

            if (sc == null)
            {
                throw new StanBadSubscriptionException();
            }

            byte[] b = ProtocolSerializer.createAck(m.proto);
            sc.NATSConnection.Publish(localAckSubject, b);
        }
示例#3
0
 /// <summary>
 /// Constructor for generating a StanMsgHandlerArgs object.  Used for application unit testing.
 /// </summary>
 /// <param name="m">A NATS streaming message.</param>
 public StanMsgHandlerArgs(StanMsg m)
 {
     msg = m;
 }
示例#4
0
 /// <summary>
 ///  Constructor for generating a StanMsgHandlerArgs object.  Used 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 StanMsgHandlerArgs(byte[] data, bool redelivered, string subject, long timestamp, ulong sequence, IStanSubscription subscription)
 {
     msg = new StanMsg(data, redelivered, subject, timestamp, sequence, subscription);
 }
示例#5
0
 /// <summary>
 /// Converts a base <see cref="StanMsg"/> into a <see cref="StanMsgHandlerArgs{TMessage}"/>
 /// for the message.
 /// </summary>
 /// <typeparam name="TMessage">The message type.</typeparam>
 /// <param name="message">The base message.</param>
 /// <returns>The new <see cref="StanMsg{TMessage}"/></returns>
 private static StanMsgHandlerArgs <TMessage> ToHandler <TMessage>(this StanMsg message)
     where TMessage : class, IRoundtripData, new()
 {
     return(new StanMsgHandlerArgs <TMessage>(message.GetProto(), message.GetSubscription()));
 }
示例#6
0
 /// <summary>
 /// Returns the <c>private</c> <see cref="AsyncSubscription "/> from a <see cref="StanMsg"/>.
 /// </summary>
 /// <param name="message">The message.</param>
 /// <returns>The <see cref="AsyncSubscription "/>.</returns>
 /// <remarks>
 /// <note>
 /// We need to return the <c>STAN.Client.AsyncScription</c> as the <see cref="object"/>
 /// type because it it defined as internal (grrrr....).
 /// </note>
 /// </remarks>
 internal static object GetSubscription(this StanMsg message)
 {
     return(stanMsgSubscriptionField.GetValue(message));
 }
示例#7
0
        //---------------------------------------------------------------------
        // StanMsg extensions

        /// <summary>
        /// Returns the <c>internal</c> <see cref="MsgProto"/> from a <see cref="StanMsg"/>.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>The <see cref="MsgProto"/>.</returns>
        internal static MsgProto GetProto(this StanMsg message)
        {
            return((MsgProto)stanMsgProtoField.GetValue(message));
        }
 internal StanMsgHandlerArgs(StanMsg m)
 {
     msg = m;
 }
示例#9
0
 /// <summary>
 /// Uses reflection to call the <c>internal IAsyncSubscription.manualAck(StanMsg)</c> method.
 /// </summary>
 /// <param name="subscription">The subscription.</param>
 /// <param name="msg">The message being acknowledged.</param>
 internal static void ManualAck(this object subscription, StanMsg msg)
 {
     subscriptionManualAckMethod.Invoke(subscription, new object[] { msg });
 }