コード例 #1
0
 /// <summary>
 /// Creates a new broker queue.
 /// </summary>
 /// <param name="broker">The broker.</param>
 /// <param name="queue">The queue name.</param>
 /// <param name="consumerTag">The consumer tag.</param>
 /// <param name="consumer">The consumer.</param>
 internal BrokerQueue(Broker broker, string queue, string consumerTag, ObservableConsumer consumer)
 {
     _broker      = broker;
     _queue       = queue;
     _consumer    = consumer;
     _consumerTag = consumerTag;
 }
コード例 #2
0
        /// <summary>
        /// Creates a new queue on this broker.
        /// </summary>
        /// <param name="name">The queue name.</param>
        /// <param name="durable">If the queue is durable.</param>
        /// <param name="exclusive">If the queue is exclusive.</param>
        /// <param name="exchange">The exchange.</param>
        /// <param name="routingKey">The routing key.</param>
        /// <param name="autoDelete">If to auto delete when all consumers unbind.</param>
        /// <param name="autoAck">If to automatically acknowledge envelopes.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>The broker queue.</returns>
        public async Task <BrokerQueue> CreateQueueAsync(string name = "", bool durable = false, bool exclusive = true, string exchange = "", string routingKey = "", bool autoDelete = true, bool autoAck = false, IDictionary <string, object> arguments = null)
        {
            // declare queue
            QueueDeclareOk ok = await _ctx.AskWork <QueueDeclareOk>(delegate() {
                return(_channel.QueueDeclare(name, durable, exclusive, autoDelete, arguments ?? new Dictionary <string, object>(StringComparer.CurrentCultureIgnoreCase)));
            }).ConfigureAwait(false);

            // create consumer
            ObservableConsumer consumer = new ObservableConsumer(this);

            // consume queue
            string consumerTag = null;

            try {
                consumerTag = (string)await _ctx.AskWork(delegate() {
                    return(_channel.BasicConsume(name, autoAck, "", false, exclusive, null, consumer));
                }).ConfigureAwait(false);
            } catch (Exception) {
                throw;
            }

            // create queue object
            BrokerQueue queue = new BrokerQueue(this, ok.QueueName, consumerTag, consumer);

            // bind to exchange
            if (exchange != "" && routingKey != "")
            {
                await queue.BindAsync(exchange, routingKey).ConfigureAwait(false);
            }

            return(queue);
        }
コード例 #3
0
 /// <summary>
 /// Cancels the broker queue.
 /// </summary>
 /// <returns></returns>
 public Task CancelAsync()
 {
     _consumer = null;
     return(_broker.Context.AskWork(() => {
         _broker.Channel.BasicCancel(_consumerTag);
         return null;
     }));
 }
コード例 #4
0
 public SubscribedObserverDisposer(ObservableConsumer consumer, int id)
 {
     ID       = id;
     Consumer = consumer;
 }