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;
 }
예제 #2
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.");
            }
        }