Пример #1
0
 protected virtual void PostProcessOutputChannel(IMessageChannel outputChannel, IProducerOptions producerOptions)
 {
     // default no-op
 }
Пример #2
0
 public IBinding BindProducer(string name, object outboundTarget, IProducerOptions producerOptions)
 {
     return(null);
 }
Пример #3
0
 protected virtual bool UseNativeEncoding(IProducerOptions producerOptions)
 {
     return(producerOptions.UseNativeEncoding);
 }
        public IProducerDestination ProvisionProducerDestination(string name, IProducerOptions options)
        {
            var producerProperties = Options.GetRabbitProducerOptions(options.BindingName);

            var exchangeName = ApplyPrefix(producerProperties.Prefix, name);
            var exchange     = BuildExchange(producerProperties, exchangeName);

            if (producerProperties.DeclareExchange.Value)
            {
                DeclareExchange(exchangeName, exchange);
            }

            RabbitConfig.IBinding binding = null;
            foreach (var requiredGroupName in options.RequiredGroups)
            {
                var baseQueueName = producerProperties.QueueNameGroupOnly.Value ? requiredGroupName : exchangeName + "." + requiredGroupName;
                if (!options.IsPartitioned)
                {
                    AutoBindDLQ(baseQueueName, baseQueueName, producerProperties);
                    if (producerProperties.BindQueue.Value)
                    {
                        var queue = new Queue(baseQueueName, true, false, false, GetQueueArgs(baseQueueName, producerProperties, false));
                        DeclareQueue(baseQueueName, queue);
                        var routingKeys = BindingRoutingKeys(producerProperties);
                        if (routingKeys == null || routingKeys.Count == 0)
                        {
                            binding = NotPartitionedBinding(exchange, queue, null, producerProperties);
                        }
                        else
                        {
                            foreach (var routingKey in routingKeys)
                            {
                                binding = NotPartitionedBinding(exchange, queue, routingKey, producerProperties);
                            }
                        }
                    }
                }
                else
                {
                    // if the stream is partitioned, create one queue for each target partition for the default group
                    for (var i = 0; i < options.PartitionCount; i++)
                    {
                        var partitionSuffix    = "-" + i;
                        var partitionQueueName = baseQueueName + partitionSuffix;
                        AutoBindDLQ(baseQueueName, baseQueueName + partitionSuffix, producerProperties);
                        if (producerProperties.BindQueue.Value)
                        {
                            var queue = new Queue(partitionQueueName, true, false, false, GetQueueArgs(partitionQueueName, producerProperties, false));
                            DeclareQueue(queue.QueueName, queue);
                            var           prefix      = producerProperties.Prefix;
                            var           destination = string.IsNullOrEmpty(prefix) ? exchangeName : exchangeName.Substring(prefix.Length);
                            List <string> routingKeys = BindingRoutingKeys(producerProperties);
                            if (routingKeys == null || routingKeys.Count == 0)
                            {
                                binding = PartitionedBinding(destination, exchange, queue, null, producerProperties, i);
                            }
                            else
                            {
                                foreach (var routingKey in routingKeys)
                                {
                                    binding = PartitionedBinding(destination, exchange, queue, routingKey, producerProperties, i);
                                }
                            }
                        }
                    }
                }
            }

            return(new RabbitProducerDestination(exchange, binding));
        }
Пример #5
0
        protected override IMessageHandler CreateProducerMessageHandler(IProducerDestination destination, IProducerOptions producerProperties, IMessageChannel errorChannel)
        {
            var handler = new BridgeHandler(ApplicationContext)
            {
                OutputChannel = ((SpringIntegrationProducerDestination)destination).Channel
            };

            return(handler);
        }
        protected override IBinding DoBindProducer(string name, IMessageChannel outboundTarget, IProducerOptions producerOptions)
        {
            if (!(outboundTarget is ISubscribableChannel))
            {
                throw new ArgumentException("Binding is supported only for ISubscribableChannel instances");
            }

            IMessageHandler      producerMessageHandler;
            IProducerDestination producerDestination;

            try
            {
                producerDestination = _provisioningProvider.ProvisionProducerDestination(name, producerOptions);
                var errorChannel = producerOptions.ErrorChannelEnabled ? RegisterErrorInfrastructure(producerDestination) : null;
                producerMessageHandler = CreateProducerMessageHandler(producerDestination, producerOptions, outboundTarget, errorChannel);
            }
            catch (Exception e) when(e is BinderException || e is ProvisioningException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new BinderException("Exception thrown while building outbound endpoint", e);
            }

            if (producerOptions.AutoStartup && producerMessageHandler is ILifecycle producerMsgHandlerLifecycle)
            {
                producerMsgHandlerLifecycle.Start();
            }

            PostProcessOutputChannel(outboundTarget, producerOptions);
            var sendingHandler = new SendingHandler(ApplicationContext, producerMessageHandler, HeaderMode.EmbeddedHeaders.Equals(producerOptions.HeaderMode), _headersToEmbed, UseNativeEncoding(producerOptions));

            sendingHandler.Initialize();
            ((ISubscribableChannel)outboundTarget).Subscribe(sendingHandler);

            IBinding binding = new DefaultProducingMessageChannelBinding(
                this,
                name,
                outboundTarget,
                producerMessageHandler is ILifecycle lifecycle ? lifecycle : null,
                producerOptions,
                producerDestination,
                _logger);

            _producerBindingExist = true;
            return(binding);
        }
 protected virtual void AfterUnbindProducer(IProducerDestination destination, IProducerOptions producerOptions)
 {
 }
 protected abstract IMessageHandler CreateProducerMessageHandler(IProducerDestination destination, IProducerOptions producerProperties, IMessageChannel errorChannel);
 protected virtual IMessageHandler CreateProducerMessageHandler(IProducerDestination destination, IProducerOptions producerProperties, IMessageChannel channel, IMessageChannel errorChannel)
 {
     return(CreateProducerMessageHandler(destination, producerProperties, errorChannel));
 }
Пример #10
0
        protected override IMessageHandler CreateProducerMessageHandler(IProducerDestination destination, IProducerOptions producerProperties, IMessageChannel errorChannel)
        {
            if (producerProperties.HeaderMode == HeaderMode.EmbeddedHeaders)
            {
                throw new InvalidOperationException("The RabbitMQ binder does not support embedded headers since RabbitMQ supports headers natively");
            }

            var extendedProperties = BindingsOptions.GetRabbitProducerOptions(producerProperties.BindingName);
            var prefix             = extendedProperties.Prefix;
            var exchangeName       = destination.Name;
            var destinationName    = string.IsNullOrEmpty(prefix) ? exchangeName : exchangeName[prefix.Length..];