コード例 #1
0
        protected override IMessageProducer CreateConsumerEndpoint(IConsumerDestination destination, string group, IConsumerOptions consumerOptions)
        {
            IErrorMessageStrategy errorMessageStrategy = new DefaultErrorMessageStrategy();
            var siBinderInputChannel = ((SpringIntegrationConsumerDestination)destination).Channel;

            var messageListenerContainer = new TestMessageListeningContainer();
            var endpoint = new TestMessageProducerSupportEndpoint(ApplicationContext, messageListenerContainer);

            var groupName           = !string.IsNullOrEmpty(group) ? group : "anonymous";
            var errorInfrastructure = RegisterErrorInfrastructure(destination, groupName, consumerOptions);

            if (consumerOptions.MaxAttempts > 1)
            {
                endpoint.RetryTemplate    = BuildRetryTemplate(consumerOptions);
                endpoint.RecoveryCallback = errorInfrastructure.Recoverer;
            }
            else
            {
                endpoint.ErrorMessageStrategy = errorMessageStrategy;
                endpoint.ErrorChannel         = errorInfrastructure.ErrorChannel;
            }

            endpoint.Init();

            siBinderInputChannel.Subscribe(messageListenerContainer);

            return(endpoint);
        }
コード例 #2
0
        private void DestroyErrorInfrastructure(IConsumerDestination destination, string group, IConsumerOptions options)
        {
            try
            {
                var recoverer = GetErrorRecovererName(destination, group, options);

                DestroyBean(recoverer);

                var errorChannelName        = GetErrorsBaseName(destination, group, options);
                var errorMessageHandlerName = GetErrorMessageHandlerName(destination, group, options);
                var errorBridgeHandlerName  = GetErrorBridgeName(destination, group, options);

                if (_destinationRegistry.Lookup(errorChannelName) is ISubscribableChannel channel)
                {
                    if (_destinationRegistry.Lookup(errorBridgeHandlerName) is IMessageHandler bridgeHandler)
                    {
                        channel.Unsubscribe(bridgeHandler);
                        DestroyBean(errorBridgeHandlerName);
                    }

                    if (_destinationRegistry.Lookup(errorMessageHandlerName) is IMessageHandler handler)
                    {
                        channel.Unsubscribe(handler);
                        DestroyBean(errorMessageHandlerName);
                    }

                    DestroyBean(errorChannelName);
                }
            }
            catch (Exception)
            {
                // Log ... context is shutting down.
            }
        }
コード例 #3
0
 public DefaultPollableChannelBinding(
     AbstractMessageChannelBinder binder,
     string name,
     string group,
     IPollableSource <IMessageHandler> inboundBindTarget,
     ILifecycle lifecycle,
     IConsumerOptions options,
     IConsumerDestination consumerDestination)
     : base(name, group, inboundBindTarget, lifecycle)
 {
     _binder      = binder;
     _options     = options;
     _destination = consumerDestination;
 }
コード例 #4
0
 public DefaultConsumerMessageChannelBinding(
     AbstractMessageChannelBinder binder,
     string name,
     string group,
     IMessageChannel inputChannel,
     ILifecycle lifecycle,
     IConsumerOptions options,
     IConsumerDestination consumerDestination)
     : base(name, group, inputChannel, lifecycle)
 {
     this.binder  = binder;
     this.options = options;
     destination  = consumerDestination;
 }
コード例 #5
0
 public void CleanAutoDeclareContext(IConsumerDestination destination, IConsumerOptions consumerProperties)
 {
     lock (_autoDeclareContext)
     {
         destination.Name.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(name =>
         {
             name = name.Trim();
             RemoveSingleton(name + ".binding");
             RemoveSingleton(name);
             var dlq = name + ".dlq";
             RemoveSingleton(dlq + ".binding");
             RemoveSingleton(dlq);
         });
     }
 }
コード例 #6
0
 public DefaultConsumerMessageChannelBinding(
     AbstractMessageChannelBinder binder,
     string name,
     string group,
     IMessageChannel inputChannel,
     ILifecycle lifecycle,
     IConsumerOptions options,
     IConsumerDestination consumerDestination,
     ILogger logger = null)
     : base(name, group, inputChannel, lifecycle)
 {
     _binder      = binder;
     _options     = options;
     _destination = consumerDestination;
     _logger      = logger;
 }
コード例 #7
0
 protected abstract IMessageProducer CreateConsumerEndpoint(IConsumerDestination destination, string group, IConsumerOptions consumerOptions);
コード例 #8
0
 protected override IMessageHandler GetErrorMessageHandler(IConsumerDestination destination, string group, IConsumerOptions consumerOptions)
 {
     return(new ErrorMessageHandler(this));
 }
コード例 #9
0
 protected virtual string GetErrorMessageHandlerName(IConsumerDestination destination, string group, IConsumerOptions consumerOptions)
 {
     return(GetErrorsBaseName(destination, group, consumerOptions) + ".handler");
 }
コード例 #10
0
 protected virtual string GetErrorRecovererName(IConsumerDestination destination, string group, IConsumerOptions consumerOptions)
 {
     return(GetErrorsBaseName(destination, group, consumerOptions) + ".recoverer");
 }
コード例 #11
0
 protected virtual IMessageHandler GetPolledConsumerErrorMessageHandler(IConsumerDestination destination, string group, IConsumerOptions consumerProperties)
 {
     return(null);
 }
コード例 #12
0
        protected virtual ErrorInfrastructure RegisterErrorInfrastructure(IConsumerDestination destination, string group, IConsumerOptions consumerOptions, bool polled)
        {
            var errorMessageStrategy = GetErrorMessageStrategy();

            var errorChannelName = GetErrorsBaseName(destination, group, consumerOptions);
            ISubscribableChannel errorChannel;
            var errorChannelObject = _destinationRegistry.Lookup(errorChannelName);

            if (errorChannelObject != null)
            {
                if (!(errorChannelObject is ISubscribableChannel))
                {
                    throw new ArgumentException("Error channel '" + errorChannelName + "' must be a ISubscribableChannel");
                }

                errorChannel = (ISubscribableChannel)errorChannelObject;
            }
            else
            {
                errorChannel = new BinderErrorChannel(ServiceProvider, errorChannelName);
                _destinationRegistry.Register(errorChannelName, errorChannel);
            }

            ErrorMessageSendingRecoverer recoverer;

            if (errorMessageStrategy == null)
            {
                recoverer = new ErrorMessageSendingRecoverer(ServiceProvider, errorChannel);
            }
            else
            {
                recoverer = new ErrorMessageSendingRecoverer(ServiceProvider, errorChannel, errorMessageStrategy);
            }

            var recovererBeanName = GetErrorRecovererName(destination, group, consumerOptions);

            _destinationRegistry.Register(recovererBeanName, recoverer);

            IMessageHandler handler;

            if (polled)
            {
                handler = GetPolledConsumerErrorMessageHandler(destination, group, consumerOptions);
            }
            else
            {
                handler = GetErrorMessageHandler(destination, group, consumerOptions);
            }

            var defaultErrorChannel = (IMessageChannel)_destinationRegistry.Lookup(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);

            if (handler == null && errorChannel is ILastSubscriberAwareChannel)
            {
                handler = GetDefaultErrorMessageHandler((ILastSubscriberAwareChannel)errorChannel, defaultErrorChannel != null);
            }

            var errorMessageHandlerName = GetErrorMessageHandlerName(destination, group, consumerOptions);

            if (handler != null)
            {
                if (IsSubscribable(errorChannel))
                {
                    var errorHandler = handler;
                    _destinationRegistry.Register(errorMessageHandlerName, errorHandler);
                    errorChannel.Subscribe(handler);
                }
                else
                {
                    // this.logger.warn("The provided errorChannel '" + errorChannelName
                    //        + "' is an instance of DirectChannel, "
                    //        + "so no more subscribers could be added which may affect DLQ processing. "
                    //        + "Resolution: Configure your own errorChannel as "
                    //        + "an instance of PublishSubscribeChannel");
                }
            }

            if (defaultErrorChannel != null)
            {
                if (IsSubscribable(errorChannel))
                {
                    var errorBridge = new BridgeHandler(ServiceProvider)
                    {
                        OutputChannel = defaultErrorChannel
                    };
                    errorChannel.Subscribe(errorBridge);

                    var errorBridgeHandlerName = GetErrorBridgeName(destination, group, consumerOptions);
                    _destinationRegistry.Register(errorBridgeHandlerName, errorBridge);
                }
                else
                {
                    // this.logger.warn("The provided errorChannel '" + errorChannelName
                    //        + "' is an instance of DirectChannel, "
                    //        + "so no more subscribers could be added and no error messages will be sent to global error channel. "
                    //        + "Resolution: Configure your own errorChannel as "
                    //        + "an instance of PublishSubscribeChannel");
                }
            }

            return(new ErrorInfrastructure(errorChannel, recoverer, handler));
        }
コード例 #13
0
 protected virtual ErrorInfrastructure RegisterErrorInfrastructure(IConsumerDestination destination, string group, IConsumerOptions consumerOptions)
 {
     return(RegisterErrorInfrastructure(destination, group, consumerOptions, false));
 }
コード例 #14
0
 protected virtual void AfterUnbindConsumer(IConsumerDestination destination, string group, IConsumerOptions consumerOptions)
 {
 }
コード例 #15
0
 protected virtual PolledConsumerResources CreatePolledConsumerResources(string name, string group, IConsumerDestination destination, IConsumerOptions consumerOptions)
 {
     throw new InvalidOperationException("This binder does not support pollable consumers");
 }
コード例 #16
0
 protected virtual string GetErrorsBaseName(IConsumerDestination destination, string group, IConsumerOptions consumerOptions)
 {
     return(destination.Name + "." + group + ".errors");
 }
コード例 #17
0
 protected virtual string GetErrorBridgeName(IConsumerDestination destination, string group, IConsumerOptions consumerOptions)
 {
     return(GetErrorsBaseName(destination, group, consumerOptions) + ".bridge");
 }
コード例 #18
0
 protected override PolledConsumerResources CreatePolledConsumerResources(string name, string group, IConsumerDestination destination, IConsumerOptions consumerOptions)
 {
     return(new PolledConsumerResources(MessageSourceDelegate, RegisterErrorInfrastructure(destination, group, consumerOptions)));
 }
コード例 #19
0
        protected virtual ErrorInfrastructure RegisterErrorInfrastructure(IConsumerDestination destination, string group, IConsumerOptions consumerOptions, bool polled, ILogger logger)
        {
            var errorMessageStrategy = GetErrorMessageStrategy();

            var errorChannelName = GetErrorsBaseName(destination, group, consumerOptions);

            var errorChannel = GetErrorChannel(logger, errorChannelName);

            var recoverer = new ErrorMessageSendingRecoverer(ApplicationContext, errorChannel, errorMessageStrategy);

            var recovererBeanName = GetErrorRecovererName(destination, group, consumerOptions);

            ApplicationContext.Register(recovererBeanName, recoverer);

            IMessageHandler handler;

            if (polled)
            {
                handler = GetPolledConsumerErrorMessageHandler(destination, group, consumerOptions);
            }
            else
            {
                handler = GetErrorMessageHandler(destination, group, consumerOptions);
            }

            var defaultErrorChannel = ApplicationContext.GetService <IMessageChannel>(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);

            if (handler == null && errorChannel is ILastSubscriberAwareChannel channel)
            {
                handler = GetDefaultErrorMessageHandler(channel, defaultErrorChannel != null);
            }

            var errorMessageHandlerName = GetErrorMessageHandlerName(destination, group, consumerOptions);

            if (handler != null)
            {
                handler.ServiceName = errorMessageHandlerName;
                if (IsSubscribable(errorChannel))
                {
                    var errorHandler = handler;
                    ApplicationContext.Register(errorMessageHandlerName, errorHandler);
                    errorChannel.Subscribe(handler);
                }
                else
                {
                    _logger?.LogWarning("The provided errorChannel '" + errorChannelName
                                        + "' is an instance of DirectChannel, "
                                        + "so no more subscribers could be added which may affect DLQ processing. "
                                        + "Resolution: Configure your own errorChannel as "
                                        + "an instance of PublishSubscribeChannel");
                }
            }

            if (defaultErrorChannel != null)
            {
                if (IsSubscribable(errorChannel))
                {
                    var errorBridge = new BridgeHandler(ApplicationContext)
                    {
                        OutputChannel = defaultErrorChannel
                    };
                    errorChannel.Subscribe(errorBridge);

                    var errorBridgeHandlerName = GetErrorBridgeName(destination, group, consumerOptions);
                    errorBridge.ServiceName = errorBridgeHandlerName;
                    ApplicationContext.Register(errorBridgeHandlerName, errorBridge);
                }
                else
                {
                    _logger?.LogWarning("The provided errorChannel '" + errorChannelName
                                        + "' is an instance of DirectChannel, "
                                        + "so no more subscribers could be added and no error messages will be sent to global error channel. "
                                        + "Resolution: Configure your own errorChannel as "
                                        + "an instance of PublishSubscribeChannel");
                }
            }

            return(new ErrorInfrastructure(errorChannel, recoverer, handler));
        }