public RabbitMqMoveContext(ReceiveContext context, IBasicProperties properties)
 {
     _context        = context;
     BasicProperties = properties;
     Headers         = new RabbitMqSendHeaders(properties);
     _serializer     = new CopyBodySerializer(context);
 }
 public RabbitMqMoveContext(ReceiveContext context, IBasicProperties properties, string exchange, string routingKey)
 {
     _context        = context;
     BasicProperties = properties;
     Exchange        = exchange;
     RoutingKey      = routingKey;
     AwaitAck        = true;
     Headers         = new RabbitMqSendHeaders(properties);
     _serializer     = new CopyBodySerializer(context);
 }
Пример #3
0
        protected async Task Move(ReceiveContext context, Action <IBasicProperties, SendHeaders> preSend)
        {
            if (!context.TryGetPayload(out ModelContext modelContext))
            {
                throw new ArgumentException("The ReceiveContext must contain a BrokeredMessageContext (from Azure Service Bus)", nameof(context));
            }

            await _topologyFilter.Send(modelContext, Pipe.Empty <ModelContext>()).ConfigureAwait(false);

            IBasicProperties properties;
            string           routingKey = "";

            byte[] body;

            if (context.TryGetPayload(out RabbitMqBasicConsumeContext basicConsumeContext))
            {
                properties = basicConsumeContext.Properties;
                routingKey = basicConsumeContext.RoutingKey;
                body       = basicConsumeContext.Body;
            }
            else
            {
                properties         = modelContext.Model.CreateBasicProperties();
                properties.Headers = new Dictionary <string, object>();

                body = context.GetBody();
            }

            SendHeaders headers = new RabbitMqSendHeaders(properties);

            headers.SetHostHeaders();

            preSend(properties, headers);

            var task = modelContext.BasicPublishAsync(_exchange, routingKey, true, properties, body, true);

            context.AddPendingTask(task);
        }