public async Task CreateConsumer(ConsumerInfo consumerInfo)
        {
            AmqpConsumer amqpConsumer = new AmqpConsumer(this, consumerInfo);
            await amqpConsumer.Attach();

            consumers.TryAdd(consumerInfo.Id, amqpConsumer);
        }
 public Task Acknowledge(InboundMessageDispatch envelope, AckType ackType)
 {
     AmqpSession session = connection.GetSession(envelope.ConsumerInfo.SessionId);
     AmqpConsumer consumer = session.GetConsumer(envelope.ConsumerId);
     consumer.Acknowledge(envelope, ackType);
     return Task.CompletedTask;
 }
 public Task StartResource(ResourceInfo resourceInfo)
 {
     switch (resourceInfo)
     {
         case ConsumerInfo consumerInfo:
             AmqpSession session = connection.GetSession(consumerInfo.SessionId);
             AmqpConsumer amqpConsumer = session.GetConsumer(consumerInfo.Id);
             amqpConsumer.Start();
             return Task.CompletedTask;
         default:
             throw new ArgumentOutOfRangeException(nameof(resourceInfo), "Not supported resource type.");
     }
 }
        public Task DestroyResource(ResourceInfo resourceInfo)
        {
            switch (resourceInfo)
            {
            case SessionInfo sessionInfo:
            {
                AmqpSession session = connection.GetSession(sessionInfo.Id);
                session.Close();
                return(Task.CompletedTask);
            }

            case ConsumerInfo consumerInfo:
            {
                AmqpSession  session  = connection.GetSession(consumerInfo.SessionId);
                AmqpConsumer consumer = session.GetConsumer(consumerInfo.Id);
                consumer.Close();
                session.RemoveConsumer(consumerInfo.Id);
                return(Task.CompletedTask);
            }

            case ProducerInfo producerInfo:
            {
                AmqpSession  session  = connection.GetSession(producerInfo.SessionId);
                AmqpProducer producer = session.GetProducer(producerInfo.Id);
                producer.Close();
                session.RemoveProducer(producerInfo.Id);
                return(Task.CompletedTask);
            }

            case NmsTemporaryDestination temporaryDestination:
            {
                AmqpTemporaryDestination amqpTemporaryDestination = connection.GetTemporaryDestination(temporaryDestination);
                if (amqpTemporaryDestination != null)
                {
                    amqpTemporaryDestination.Close();
                    connection.RemoveTemporaryDestination(temporaryDestination.Id);
                }
                else
                {
                    Tracer.Debug($"Could not find temporary destination {temporaryDestination.Id} to delete.");
                }

                return(Task.CompletedTask);
            }

            default:
                throw new ArgumentOutOfRangeException(nameof(resourceInfo), "Not supported resource type.");
            }
        }
示例#5
0
 public void RegisterTxConsumer(AmqpConsumer consumer)
 {
     this.txConsumers[consumer.ConsumerId] = consumer;
 }