Close() публичный Метод

Closes this Subscription, cancelling the consumer record in the server.
public Close ( ) : void
Результат void
 ///<summary>Close the reply subscription associated with this instance, if any.</summary>
 ///<remarks>
 /// Simply delegates to calling Subscription.Close(). Clears
 /// the Subscription property, so that subsequent Call()s, if
 /// any, will re-initialize it to a fresh Subscription
 /// instance.
 ///</remarks>
 public void Close()
 {
     if (Subscription != null)
     {
         Subscription.Close();
         Subscription = null;
     }
 }
Пример #2
0
 ///<summary>Close the reply subscription associated with this instance, if any.</summary>
 ///<remarks>
 /// Simply delegates to calling Subscription.Close(). Clears
 /// the Subscription property, so that subsequent Call()s, if
 /// any, will re-initialize it to a fresh Subscription
 /// instance.
 ///</remarks>
 public void Close()
 {
     if (m_subscription != null)
     {
         m_subscription.Close();
         m_subscription = null;
     }
 }
 public void TestConsumerCancellationNotification()
 {
     var q = Guid.NewGuid().ToString();
     this.Model.QueueDeclare(queue: q, durable: false, exclusive: false, autoDelete: false, arguments: null);
     var sub = new Subscription(this.Model, q);
     var latch = new ManualResetEvent(false);
     sub.Consumer.ConsumerCancelled += (_sender, _args) =>
     {
         sub.Close();
         latch.Set();
         Conn.Close();
     };
     this.Model.QueueDelete(q);
     Wait(latch, TimeSpan.FromSeconds(4));
 }
Пример #4
0
 ///<summary>Shut down the server, causing MainLoop() to return
 ///to its caller.</summary>
 ///<remarks>
 /// Acts by calling Close() on the server's Subscription object.
 ///</remarks>
 public void Close()
 {
     m_subscription.Close();
 }
Пример #5
0
        public void StartListening(Action<byte[], IDictionary<string, object>> onMessage)
        {
            if (this.IsListening)
                throw new InvalidOperationException("Client is already listening for messages");

            Action subscribeAction =
                () =>
                {
                    try
                    {
                        subscriptionLifetimeResetEvent.Reset();
                        Subscription subscriptionHandler = new Subscription(this.Connection.GetModel(), this.QueueName);
                        int waitForMessagesTimeout = 100;

                        this.loopControlResetEvent.Reset();
                        while (!loopControlResetEvent.IsSet)
                        {
                            try
                            {
                                BasicDeliverEventArgs delivery = null;
                                if (subscriptionHandler.Next(waitForMessagesTimeout, out delivery))
                                {
                                    if (delivery == null)
                                        continue;

                                    // Deliver message
                                    var p = CreateProperties(delivery);
                                    onMessage(delivery.Body, p);
                                }

                            }
                            catch (ThreadAbortException)
                            {
                                // Nothing to do, thread is being aborted.
                                // Set the reset event to leave gracefully
                                loopControlResetEvent.Set();
                            }
                            catch (Exception)
                            {
                                // Any other exception should be ignored.
                            }
                        }

                        // Close the subscription if its still open
                        if (subscriptionHandler.Model.IsOpen)
                        {
                            subscriptionHandler.Close();
                        }
                    }
                    finally
                    {
                        subscriptionLifetimeResetEvent.Set();
                    }
                };

            this.currentSubscription = subscribeAction;
        }