public void PublishMessage(RabbitMessage message)
        {
            Messages.Enqueue(message);

            var matchingBindings = string.IsNullOrWhiteSpace(message.RoutingKey) ?
                                   Bindings.Values :
                                   Bindings.Values.Where(b => matcher.Matches(message.RoutingKey, b.RoutingKey));

            if (matchingBindings.Any())
            {
                foreach (var binding in matchingBindings)
                {
                    binding.Queue.PublishMessage(message);
                }
                return;
            }

            // Alternate Exchange support
            if (Arguments == null)
            {
                return;
            }

            if (!Arguments.TryGetValue("alternate-exchange", out var alternateExchangeName) || alternateExchangeName == null)
            {
                return;
            }

            if (!server.Exchanges.TryGetValue(alternateExchangeName.ToString(), out var alternateExchange))
            {
                return;
            }

            alternateExchange.PublishMessage(message);
        }
示例#2
0
        public void PublishMessage(RabbitMessage message)
        {
            Messages.Enqueue(message);

            if (string.IsNullOrWhiteSpace(message.RoutingKey))
            {
                foreach (var binding in Bindings)
                {
                    binding.Value.Queue.PublishMessage(message);
                }
            }
            else
            {
                var matchingBindings = Bindings.Values.Where(b => matcher.Matches(message.RoutingKey, b.RoutingKey));
                foreach (var binding in matchingBindings)
                {
                    binding.Queue.PublishMessage(message);
                }
            }
        }