public Task SendMessage(string address, OutgoingMessage message, IBasicProperties properties) { Task task; if (usePublisherConfirms) { task = GetConfirmationTask(); properties.SetConfirmationId(channel.NextPublishSeqNo); } else { task = TaskEx.CompletedTask; } if (properties.Headers.TryGetValue(DelayInfrastructure.DelayHeader, out var delayValue)) { var routingKey = DelayInfrastructure.CalculateRoutingKey((int)delayValue, address, out var startingDelayLevel); routingTopology.BindToDelayInfrastructure(channel, address, DelayInfrastructure.DeliveryExchange, DelayInfrastructure.BindingKey(address)); channel.BasicPublish(DelayInfrastructure.LevelName(startingDelayLevel), routingKey, true, properties, message.Body); } else { routingTopology.Send(channel, address, message, properties); } return(task); }
public Task CreateQueueIfNecessary(QueueBindings queueBindings, string identity) { using (var connection = connectionFactory.CreateAdministrationConnection()) using (var channel = connection.CreateModel()) { DelayInfrastructure.Build(channel); routingTopology.Initialize(channel, queueBindings.ReceivingAddresses, queueBindings.SendingAddresses); foreach (var receivingAddress in queueBindings.ReceivingAddresses) { routingTopology.BindToDelayInfrastructure(channel, receivingAddress, DelayInfrastructure.DeliveryExchange, DelayInfrastructure.BindingKey(receivingAddress)); } } return(TaskEx.CompletedTask); }
public Task CreateQueueIfNecessary(QueueBindings queueBindings, string identity) { using (var connection = connectionFactory.CreateAdministrationConnection()) using (var channel = connection.CreateModel()) { DelayInfrastructure.Build(channel); var queueDeclaringTopology = routingTopology as IDeclareQueues; if (queueDeclaringTopology != null) { queueDeclaringTopology.DeclareAndInitialize(channel, queueBindings.ReceivingAddresses, queueBindings.SendingAddresses); } else { foreach (var receivingAddress in queueBindings.ReceivingAddresses) { CreateQueueIfNecessary(channel, receivingAddress); } foreach (var sendingAddress in queueBindings.SendingAddresses) { CreateQueueIfNecessary(channel, sendingAddress); } } var delayTopology = routingTopology as ISupportDelayedDelivery; if (delayTopology != null) { foreach (var receivingAddress in queueBindings.ReceivingAddresses) { delayTopology.BindToDelayInfrastructure(channel, receivingAddress, DelayInfrastructure.DeliveryExchange, DelayInfrastructure.BindingKey(receivingAddress)); } } } return(TaskEx.CompletedTask); }
internal void SetupInfrastructure(string[] sendingQueues) { using (var connection = connectionFactory.CreateAdministrationConnection()) using (var channel = connection.CreateModel()) { DelayInfrastructure.Build(channel); var receivingQueues = Receivers.Select(r => r.Value.ReceiveAddress).ToArray(); routingTopology.Initialize(channel, receivingQueues, sendingQueues); foreach (string receivingAddress in receivingQueues) { routingTopology.BindToDelayInfrastructure(channel, receivingAddress, DelayInfrastructure.DeliveryExchange, DelayInfrastructure.BindingKey(receivingAddress)); } } }