Пример #1
0
        public Task Run(string endpointName, string?errorQueue, string?auditQueue, IEnumerable <string> instanceDiscriminators, CancellationToken cancellationToken = default)
        {
            console.WriteLine("Connecting to broker");

            using var connection = connectionFactory.CreateAdministrationConnection();
            using var channel    = connection.CreateModel();

            console.WriteLine("Checking for delay infrastructure v2");

            try
            {
                channel.ExchangeDeclarePassive(DelayInfrastructure.DeliveryExchange);
            }
            catch (OperationInterruptedException)
            {
                console.Error.Write("Fail: Delay infrastructure v2 not found.\n");
                throw;
            }

            console.WriteLine($"Creating queues");

            var receivingAddresses = new List <string>()
            {
                endpointName
            };

            if (instanceDiscriminators.Any())
            {
                receivingAddresses.AddRange(instanceDiscriminators.Select(discriminator => $"{endpointName}-{discriminator}"));
            }

            var sendingAddresses = new List <string>();

            if (!string.IsNullOrWhiteSpace(errorQueue))
            {
                sendingAddresses.Add(errorQueue);
            }

            if (!string.IsNullOrWhiteSpace(auditQueue))
            {
                sendingAddresses.Add(auditQueue);
            }

            routingTopology.Initialize(channel, receivingAddresses, sendingAddresses);

            foreach (var receivingAddress in receivingAddresses)
            {
                routingTopology.BindToDelayInfrastructure(channel, receivingAddress, DelayInfrastructure.DeliveryExchange, DelayInfrastructure.BindingKey(receivingAddress));
            }

            console.WriteLine($"Completed successfully");

            return(Task.CompletedTask);
        }
        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);
        }
        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));
                    }
                }
        }
        void CreateQueueIfNecessary(IModel channel, string receivingAddress)
        {
            channel.QueueDeclare(receivingAddress, durableMessagesEnabled, false, false, null);

            routingTopology.Initialize(channel, receivingAddress);
        }