public IStanSubscription Subscribe(string subject, string qgroup, StanSubscriptionOptions options, EventHandler <StanMsgHandlerArgs> handler)
        {
            if (subject == null)
            {
                throw new ArgumentNullException("subject");
            }
            if (qgroup == null)
            {
                throw new ArgumentNullException("qgroup");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }

            return(subscribe(subject, qgroup, handler, options));
        }
        internal StanSubscriptionOptions(StanSubscriptionOptions opts)
        {
            if (opts == null)
            {
                return;
            }

            ackWait = opts.ackWait;

            if (opts.durableName != null)
            {
                durableName = StanOptions.DeepCopy(opts.durableName);
            }

            manualAcks        = opts.manualAcks;
            maxInFlight       = opts.maxInFlight;
            startAt           = opts.startAt;
            startSequence     = opts.startSequence;
            useStartTimeDelta = opts.useStartTimeDelta;
            startTime         = opts.startTime;
            startTimeDelta    = opts.startTimeDelta;
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
 /// <summary>
 /// Subscribe will create an Asynchronous Subscriber with
 /// interest in a given subject, assign the handler, and immediately
 /// start receiving messages.
 /// </summary>
 /// <typeparam name="TMessage">The message type.</typeparam>
 /// <param name="connection">The conmnection.</param>
 /// <param name="subject">Subject of interest.</param>
 /// <param name="qgroup">Name of the queue group.</param>
 /// <param name="options">SubscriptionOptions used to create the subscriber.</param>
 /// <param name="handler">A message handler to process messages.</param>
 /// <returns>A new subscription.</returns>
 public static IStanSubscription Subscribe <TMessage>(this IStanConnection connection, string subject, string qgroup, StanSubscriptionOptions options, EventHandler <StanMsgHandlerArgs <TMessage> > handler)
     where TMessage : class, IRoundtripData, new()
 {
     return(connection.Subscribe(subject, qgroup, options,
                                 (sender, args) =>
     {
         handler?.Invoke(sender, args.Message.ToHandler <TMessage>());
     }));
 }