Esempio n. 1
0
        public async Task <IActiveConsumer> StartListeningQueueAsync <T>(string queueName, ConsumerOptions <T> consumerOptions, ProcessorMessageDelegate <T> messageProcessor) where T : class
        {
            var activeMessageProcessorCanceller = new ActiveMessageProcessorCanceller();

            const string consumerTagKey = "consumerTag";
            var          pipeContext    = new ClientPipeContextAction((channel, context) =>
            {
                var consumerTag = BeginConsumeQueue(channel, queueName, consumerOptions, messageProcessor, activeMessageProcessorCanceller);
                context.Items[consumerTagKey] = consumerTag;
                return(Task.CompletedTask);
            });
            await ClientPipe.ExecutePipelineAsync(pipeContext, _consumerPipeline.Value);

            return(new ActiveConsumer(pipeContext.GetItemValue <string>(consumerTagKey), pipeContext.ChannelContainer !, activeMessageProcessorCanceller));
        }
Esempio n. 2
0
        public async Task <long> GetMessageCountInQueueAsync(string queueName)
        {
            const string messageCountKey   = "messageCount";
            var          pipeContextAction = new ClientPipeContextAction((channel, context) =>
            {
                try
                {
                    context.Items[messageCountKey] = (long)channel.QueueDeclarePassive(queueName).MessageCount;
                }
                catch (OperationInterruptedException ex) when(ex.ShutdownReason.ReplyCode == 404)
                {
                    context.Items[messageCountKey] = -1L;
                }

                return(Task.CompletedTask);
            });
            await ClientPipe.ExecutePipelineAsync(pipeContextAction, _actionPipeline.Value);

            return(pipeContextAction.GetItemValue <long>(messageCountKey));
        }
 public Task ProcessAsync(ClientPipeContextAction clientPipeContextAction, ReadOnlyMemory <IClientPipe> pipeline)
 {
     return(clientPipeContextAction.Action(clientPipeContextAction.Channel !, clientPipeContextAction));
 }