Class ReactiveRedisStreamMessageProducer

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.endpoint.AbstractEndpoint
org.springframework.integration.endpoint.MessageProducerSupport
org.springframework.integration.redis.inbound.ReactiveRedisStreamMessageProducer
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle, org.springframework.integration.context.ExpressionCapable, org.springframework.integration.core.MessageProducer, org.springframework.integration.IntegrationPattern, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.IntegrationInboundManagement, org.springframework.integration.support.management.IntegrationManagement, org.springframework.integration.support.management.ManageableLifecycle, org.springframework.integration.support.management.ManageableSmartLifecycle, org.springframework.integration.support.management.TrackableComponent

public class ReactiveRedisStreamMessageProducer extends org.springframework.integration.endpoint.MessageProducerSupport
A MessageProducerSupport for reading messages from a Redis Stream and publishing them into the provided output channel. By default this adapter reads message as a standalone client XREAD (Redis command) but can be switched to a Consumer Group feature XREADGROUP by setting consumerName field. By default the Consumer Group name is the id of this bean IntegrationObjectSupport.getBeanName().
Since:
5.4
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement

    org.springframework.integration.support.management.IntegrationManagement.ManagementOverrides
  • Field Summary

    Fields inherited from class org.springframework.integration.endpoint.AbstractEndpoint

    lifecycleCondition, lifecycleLock

    Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport

    EXPRESSION_PARSER, logger

    Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement

    METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME

    Fields inherited from interface org.springframework.context.SmartLifecycle

    DEFAULT_PHASE
  • Constructor Summary

    Constructors
    Constructor
    Description
    ReactiveRedisStreamMessageProducer(org.springframework.data.redis.connection.ReactiveRedisConnectionFactory reactiveConnectionFactory, String streamKey)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
     
    protected void
     
    void
    setAutoAck(boolean autoAck)
    Set whether or not acknowledge message read in the Consumer Group.
    void
    setBatchSize(int recordsPerPoll)
    Configure a batch size for the COUNT option during reading.
    void
    setConsumerGroup(String consumerGroup)
    Set the name of the Consumer Group.
    void
    setConsumerName(String consumerName)
    Set the name of the consumer.
    void
    setCreateConsumerGroup(boolean createConsumerGroup)
    Create the Consumer Group if and only if it does not exist.
    void
    setExtractPayload(boolean extractPayload)
    Configure this channel adapter to extract or not value from the Record.
    void
    setObjectMapper(org.springframework.data.redis.hash.HashMapper<?,?,?> hashMapper)
    Configure a hash mapper.
    void
    setOnErrorResume(Function<? super Throwable,? extends org.reactivestreams.Publisher<Void>> resumeFunction)
    Configure a resume Function to resume the main sequence when polling the stream fails.
    void
    setPollTimeout(Duration pollTimeout)
    Configure a poll timeout for the BLOCK option during reading.
    void
    setReadOffset(org.springframework.data.redis.connection.stream.ReadOffset readOffset)
    Define the offset from which we want to read message.
    void
    setSerializer(org.springframework.data.redis.serializer.RedisSerializationContext.SerializationPair<?> pair)
    Configure a key, hash key and hash value serializer.
    void
    setStreamReceiverOptions(org.springframework.data.redis.stream.StreamReceiver.StreamReceiverOptions<String,?> streamReceiverOptions)
    Set ReactiveStreamOperations used to customize the StreamReceiver.
    void
    setTargetType(Class<?> targetType)
    Configure a hash target type.

    Methods inherited from class org.springframework.integration.endpoint.MessageProducerSupport

    afterSingletonsInstantiated, buildErrorMessage, doStop, getErrorChannel, getErrorMessageAttributes, getErrorMessageStrategy, getIntegrationPatternType, getMessagingTemplate, getOutputChannel, isObserved, registerObservationRegistry, sendErrorMessageIfNecessary, sendMessage, setErrorChannel, setErrorChannelName, setErrorMessageStrategy, setObservationConvention, setOutputChannel, setOutputChannelName, setSendTimeout, setShouldTrack, subscribeToPublisher

    Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint

    destroy, doStop, getPhase, getRole, isActive, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, start, stop, stop

    Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport

    afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement

    destroy, getManagedName, getManagedType, getOverrides, getThisAs, isLoggingEnabled, registerMetricsCaptor, setLoggingEnabled, setManagedName, setManagedType

    Methods inherited from interface org.springframework.integration.support.context.NamedComponent

    getBeanName, getComponentName
  • Constructor Details

    • ReactiveRedisStreamMessageProducer

      public ReactiveRedisStreamMessageProducer(org.springframework.data.redis.connection.ReactiveRedisConnectionFactory reactiveConnectionFactory, String streamKey)
  • Method Details

    • setReadOffset

      public void setReadOffset(org.springframework.data.redis.connection.stream.ReadOffset readOffset)
      Define the offset from which we want to read message. By default the ReadOffset.latest() is used. ReadOffset.latest() is equal to '$', which is the Id used with XREAD to get new data added to the stream. Note that when switching to the Consumer Group feature, we set it to ReadOffset.lastConsumed() if it is still equal to ReadOffset.latest().
      Parameters:
      readOffset - the desired offset
    • setExtractPayload

      public void setExtractPayload(boolean extractPayload)
      Configure this channel adapter to extract or not value from the Record.
      Parameters:
      extractPayload - default true
    • setAutoAck

      public void setAutoAck(boolean autoAck)
      Set whether or not acknowledge message read in the Consumer Group. true by default.
      Parameters:
      autoAck - the acknowledge option.
    • setConsumerGroup

      public void setConsumerGroup(@Nullable String consumerGroup)
      Set the name of the Consumer Group. It is possible to create that Consumer Group if desired, see: createConsumerGroup. If not set, the defined bean name IntegrationObjectSupport.getBeanName() is used.
      Parameters:
      consumerGroup - the Consumer Group on which this adapter should register to listen messages.
    • setConsumerName

      public void setConsumerName(@Nullable String consumerName)
      Set the name of the consumer. When a consumer name is provided, this adapter is switched to the Consumer Group feature. Note that this value should be unique in the group.
      Parameters:
      consumerName - the consumer name in the Consumer Group
    • setCreateConsumerGroup

      public void setCreateConsumerGroup(boolean createConsumerGroup)
      Create the Consumer Group if and only if it does not exist. During the creation we also create the stream, see MKSTREAM.
      Parameters:
      createConsumerGroup - specify if we should create the Consumer Group, false by default
    • setStreamReceiverOptions

      public void setStreamReceiverOptions(@Nullable org.springframework.data.redis.stream.StreamReceiver.StreamReceiverOptions<String,?> streamReceiverOptions)
      Set ReactiveStreamOperations used to customize the StreamReceiver. It provides a way to set the polling timeout and the serialization context. By default the polling timeout is set to infinite and StringRedisSerializer is used. Mutually exclusive with 'pollTimeout', 'batchSize', 'onErrorResume', 'serializer', 'targetType', 'objectMapper'.
      Parameters:
      streamReceiverOptions - the desired receiver options
    • setPollTimeout

      public void setPollTimeout(Duration pollTimeout)
      Configure a poll timeout for the BLOCK option during reading. Mutually exclusive with setStreamReceiverOptions(StreamReceiver.StreamReceiverOptions).
      Parameters:
      pollTimeout - the timeout for polling.
      Since:
      5.5
      See Also:
      • StreamReceiver.StreamReceiverOptionsBuilder.pollTimeout(Duration)
    • setBatchSize

      public void setBatchSize(int recordsPerPoll)
      Configure a batch size for the COUNT option during reading. Mutually exclusive with setStreamReceiverOptions(StreamReceiver.StreamReceiverOptions).
      Parameters:
      recordsPerPoll - must be greater zero.
      Since:
      5.5
      See Also:
      • StreamReceiver.StreamReceiverOptionsBuilder.batchSize(int)
    • setOnErrorResume

      public void setOnErrorResume(Function<? super Throwable,? extends org.reactivestreams.Publisher<Void>> resumeFunction)
      Configure a resume Function to resume the main sequence when polling the stream fails. Mutually exclusive with setStreamReceiverOptions(StreamReceiver.StreamReceiverOptions). By default this function extract the failed Record and sends an ErrorMessage to the provided MessageProducerSupport.setErrorChannel(org.springframework.messaging.MessageChannel). The failed message for this record may have a IntegrationMessageHeaderAccessor.ACKNOWLEDGMENT_CALLBACK header when manual acknowledgment is configured for this message producer.
      Parameters:
      resumeFunction - must not be null.
      Since:
      5.5
      See Also:
      • StreamReceiver.StreamReceiverOptionsBuilder.onErrorResume(Function)
    • setSerializer

      public void setSerializer(org.springframework.data.redis.serializer.RedisSerializationContext.SerializationPair<?> pair)
      Configure a key, hash key and hash value serializer. Mutually exclusive with setStreamReceiverOptions(StreamReceiver.StreamReceiverOptions).
      Parameters:
      pair - must not be null.
      Since:
      5.5
      See Also:
      • StreamReceiver.StreamReceiverOptionsBuilder.serializer(RedisSerializationContext)
    • setTargetType

      public void setTargetType(Class<?> targetType)
      Configure a hash target type. Changes the emitted Record type to ObjectRecord. Mutually exclusive with setStreamReceiverOptions(StreamReceiver.StreamReceiverOptions).
      Parameters:
      targetType - must not be null.
      Since:
      5.5
      See Also:
      • StreamReceiver.StreamReceiverOptionsBuilder.targetType(Class)
    • setObjectMapper

      public void setObjectMapper(org.springframework.data.redis.hash.HashMapper<?,?,?> hashMapper)
      Configure a hash mapper. Mutually exclusive with setStreamReceiverOptions(StreamReceiver.StreamReceiverOptions).
      Parameters:
      hashMapper - must not be null.
      Since:
      5.5
      See Also:
      • StreamReceiver.StreamReceiverOptionsBuilder.objectMapper(HashMapper)
    • getComponentType

      public String getComponentType()
      Specified by:
      getComponentType in interface org.springframework.integration.support.context.NamedComponent
      Overrides:
      getComponentType in class org.springframework.integration.context.IntegrationObjectSupport
    • onInit

      protected void onInit()
      Overrides:
      onInit in class org.springframework.integration.endpoint.MessageProducerSupport
    • doStart

      protected void doStart()
      Overrides:
      doStart in class org.springframework.integration.endpoint.MessageProducerSupport