public async Task CreateProducer(ProducerInfo producerInfo)
        {
            var amqpProducer = new AmqpProducer(this, producerInfo);
            await amqpProducer.Attach();

            producers.TryAdd(producerInfo.Id, amqpProducer);
        }
 public Task Send(OutboundMessageDispatch envelope)
 {
     AmqpSession session = connection.GetSession(envelope.ProducerInfo.SessionId);
     AmqpProducer producer = session.GetProducer(envelope.ProducerId);
     producer.Send(envelope);
     envelope.Message.IsReadOnly = false;
     return Task.CompletedTask;
 }
Esempio n. 3
0
        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.");
            }
        }