public static async Task <RabbitMQDelivery> Request(this IRabbitMQChannel channel, IMessageContent content, string exchange = null, string routingKey = null)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            var model = new RequestReplyModel(content);

            await channel.Publish(model, routingKey, exchange);

            return(await model.Context.Task);
        }
        public static async Task <RabbitMQDelivery> Request <TMessage>(this IRabbitMQChannel channel, TMessage message, string exchange = null, string routingKey = null)
        {
            if (channel == null)
            {
                throw new NullReferenceException();
            }

            var formatter = channel as IMessageContentFormatter
                            ?? throw new InvalidOperationException($"The channel type does not implements {nameof(IMessageContentFormatter)}.");

            var content = formatter.FormatMessageContent(message);

            return(await channel.Request(content, exchange, routingKey));
        }
Beispiel #3
0
 public RpcServer(IRabbitMQChannel channel)
 {
     Channel = channel;
 }
Beispiel #4
0
 internal static void Set(this AsyncContextAccessor accessor, IRabbitMQChannel channel)
 => accessor.Set(channel, null);
Beispiel #5
0
 public static Task Publish <TMessage>(this IRabbitMQChannel channel, TMessage message, string routingKey = null, string exchange = null)
 => channel.Publish(message, routingKey, exchange);