Class AbstractMessageChannelBinder<C extends ConsumerProperties,​P extends ProducerProperties,​PP extends ProvisioningProvider<C,​P>>

    • Constructor Detail

      • AbstractMessageChannelBinder

        public AbstractMessageChannelBinder​(String[] headersToEmbed,
                                            PP provisioningProvider)
    • Method Detail

      • getApplicationEventPublisher

        protected org.springframework.context.ApplicationEventPublisher getApplicationEventPublisher()
      • setApplicationEventPublisher

        public void setApplicationEventPublisher​(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
        Specified by:
        setApplicationEventPublisher in interface org.springframework.context.ApplicationEventPublisherAware
      • setConsumerEndpointCustomizer

        public void setConsumerEndpointCustomizer​(@Nullable
                                                  ConsumerEndpointCustomizer<? extends org.springframework.integration.core.MessageProducer> endpointCustomizer)
        Configure an optional ConsumerEndpointCustomizer for further configuration of consumer MessageProducer instances created by the binder.
        Parameters:
        endpointCustomizer - the ConsumerEndpointCustomizer to use.
        Since:
        3.0
      • useNativeEncoding

        protected boolean useNativeEncoding​(P producerProperties)
        Whether the producer for the destination being created should be configured to use native encoding which may, or may not, be determined from the properties. For example, a transactional kafka binder uses a common producer for all destinations. The default implementation returns ProducerProperties.isUseNativeEncoding().
        Parameters:
        producerProperties - the properties.
        Returns:
        true to use native encoding.
      • postProcessOutputChannel

        protected void postProcessOutputChannel​(org.springframework.messaging.MessageChannel outputChannel,
                                                P producerProperties)
        Allows subclasses to perform post processing on the channel - for example to add more interceptors.
        Parameters:
        outputChannel - the channel.
        producerProperties - the producer properties.
      • createProducerMessageHandler

        protected org.springframework.messaging.MessageHandler createProducerMessageHandler​(ProducerDestination destination,
                                                                                            P producerProperties,
                                                                                            org.springframework.messaging.MessageChannel channel,
                                                                                            org.springframework.messaging.MessageChannel errorChannel)
                                                                                     throws Exception
        Create a MessageHandler with the ability to send data to the target middleware. If the returned instance is also a Lifecycle, it will be stopped automatically by the binder.

        In order to be fully compliant, the MessageHandler of the binder must observe the following headers:

        Parameters:
        destination - the name of the target destination.
        producerProperties - the producer properties.
        channel - the channel to bind.
        errorChannel - the error channel (if enabled, otherwise null). If not null, the binder must wire this channel into the producer endpoint so that errors are forwarded to it.
        Returns:
        the message handler for sending data to the target middleware
        Throws:
        Exception - when producer messsage handler failed to be created
      • createProducerMessageHandler

        protected abstract org.springframework.messaging.MessageHandler createProducerMessageHandler​(ProducerDestination destination,
                                                                                                     P producerProperties,
                                                                                                     org.springframework.messaging.MessageChannel errorChannel)
                                                                                              throws Exception
        Create a MessageHandler with the ability to send data to the target middleware. If the returned instance is also a Lifecycle, it will be stopped automatically by the binder.

        In order to be fully compliant, the MessageHandler of the binder must observe the following headers:

        Parameters:
        destination - the name of the target destination
        producerProperties - the producer properties
        errorChannel - the error channel (if enabled, otherwise null). If not null, the binder must wire this channel into the producer endpoint so that errors are forwarded to it.
        Returns:
        the message handler for sending data to the target middleware
        Throws:
        Exception - upon failure to create the producer message handler
      • afterUnbindProducer

        protected void afterUnbindProducer​(ProducerDestination destination,
                                           P producerProperties)
        Invoked after the unbinding of a producer. Subclasses may override this to provide their own logic for dealing with unbinding.
        Parameters:
        destination - the bound destination
        producerProperties - the producer properties
      • getPolledConsumerRecoveryCallback

        protected org.springframework.retry.RecoveryCallback<Object> getPolledConsumerRecoveryCallback​(AbstractMessageChannelBinder.ErrorInfrastructure errorInfrastructure,
                                                                                                       C properties)
        Implementations can override the default ErrorMessageSendingRecoverer.
        Parameters:
        errorInfrastructure - the infrastructure.
        properties - the consumer properties.
        Returns:
        the recoverer.
      • createConsumerEndpoint

        protected abstract org.springframework.integration.core.MessageProducer createConsumerEndpoint​(ConsumerDestination destination,
                                                                                                       String group,
                                                                                                       C properties)
                                                                                                throws Exception
        Creates MessageProducer that receives data from the consumer destination. will be started and stopped by the binder.
        Parameters:
        group - the consumer group
        destination - reference to the consumer destination
        properties - the consumer properties
        Returns:
        the consumer endpoint.
        Throws:
        Exception - when consumer endpoint creation failed.
      • afterUnbindConsumer

        protected void afterUnbindConsumer​(ConsumerDestination destination,
                                           String group,
                                           C consumerProperties)
        Invoked after the unbinding of a consumer. The binder implementation can override this method to provide their own logic (e.g. for cleaning up destinations).
        Parameters:
        destination - the consumer destination
        group - the consumer group
        consumerProperties - the consumer properties
      • registerErrorInfrastructure

        protected final AbstractMessageChannelBinder.ErrorInfrastructure registerErrorInfrastructure​(ConsumerDestination destination,
                                                                                                     String group,
                                                                                                     C consumerProperties)
        Build an errorChannelRecoverer that writes to a pub/sub channel for the destination when an exception is thrown to a consumer.
        Parameters:
        destination - the destination.
        group - the group.
        consumerProperties - the properties.
        Returns:
        the ErrorInfrastructure which is a holder for the error channel, the recoverer and the message handler that is subscribed to the channel.
      • registerErrorInfrastructure

        protected final AbstractMessageChannelBinder.ErrorInfrastructure registerErrorInfrastructure​(ConsumerDestination destination,
                                                                                                     String group,
                                                                                                     C consumerProperties,
                                                                                                     boolean polled)
        Build an errorChannelRecoverer that writes to a pub/sub channel for the destination when an exception is thrown to a consumer.
        Parameters:
        destination - the destination.
        group - the group.
        consumerProperties - the properties.
        polled - true if this is for a polled consumer.
        Returns:
        the ErrorInfrastructure which is a holder for the error channel, the recoverer and the message handler that is subscribed to the channel.
      • getErrorMessageHandler

        protected org.springframework.messaging.MessageHandler getErrorMessageHandler​(ConsumerDestination destination,
                                                                                      String group,
                                                                                      C consumerProperties)
        Binders can return a message handler to be subscribed to the error channel. Examples might be if the user wishes to (re)publish messages to a DLQ.
        Parameters:
        destination - the destination.
        group - the group.
        consumerProperties - the properties.
        Returns:
        the handler (may be null, which is the default, causing the exception to be rethrown).
      • getPolledConsumerErrorMessageHandler

        protected org.springframework.messaging.MessageHandler getPolledConsumerErrorMessageHandler​(ConsumerDestination destination,
                                                                                                    String group,
                                                                                                    C consumerProperties)
        Binders can return a message handler to be subscribed to the error channel. Examples might be if the user wishes to (re)publish messages to a DLQ.
        Parameters:
        destination - the destination.
        group - the group.
        consumerProperties - the properties.
        Returns:
        the handler (may be null, which is the default, causing the exception to be rethrown).
      • getDefaultErrorMessageHandler

        protected org.springframework.messaging.MessageHandler getDefaultErrorMessageHandler​(org.springframework.cloud.stream.binder.LastSubscriberAwareChannel errorChannel,
                                                                                             boolean defaultErrorChannelPresent)
        Return the default error message handler, which throws the error message payload to the caller if there are no user handlers subscribed. The handler is ordered so it runs after any user-defined handlers that are subscribed.
        Parameters:
        errorChannel - the error channel.
        defaultErrorChannelPresent - true if the context has a default 'errorChannel'.
        Returns:
        the handler.
      • getErrorMessageStrategy

        protected org.springframework.integration.support.ErrorMessageStrategy getErrorMessageStrategy()
        Binders can return an ErrorMessageStrategy for building error messages; binder implementations typically might add extra headers to the error message.
        Returns:
        the implementation - may be null.