0

I am new to Spring Integration & Redis, So my apology if I am making a naive mistake.

My requirement is as below -

  1. Need to implement a message queue. For dispatching money to the user based on some events.
  2. The queue should not be volatile and Ensuring Atomicity. If I restarted the server or it crashed it should not lose the event message. This also includes messages which are currently in progress.
  3. The queue should deliver the message granted once and only once. It will be a multithreaded(workers) and multi-server environment.

My progress till now is - configured Spring Integration and Spring Integration Redis in my spring project. My Spring Integration config as below -

    <int-redis:queue-outbound-channel-adapter
           id="event-outbound-channel-adapter"
           channel="eventChannelJson"
           serializer="serializer"
           auto-startup="true" connection-factory="redisConnectionFactory"
           queue="my-event-queue" />

    <int:gateway id="eventChannelGateway"
                service-interface="com.test.RedisChannelGateway"
                error-channel="errorChannel" default-request-channel="eventChannel">
       <int:default-header name="topic" value="queue"/>
    </int:gateway>

    <int:channel id="eventChannelJson"/>
    <int:channel id="eventChannel">
       <int:queue/>
    </int:channel>


    <bean id="serializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/>

    <int:object-to-json-transformer input-channel="eventChannel"
                                   output-channel="eventChannelJson"/>


    <int-redis:queue-inbound-channel-adapter id="event-inbound-channel-adapter"
                                            channel="eventChannelJson" queue="my-event-queue"
                                            serializer="serializer" auto-startup="true"
                                            connection-factory="redisConnectionFactory"/>

    <bean id="serializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/>

    <int:json-to-object-transformer input-channel="eventChannelJson"
                                   output-channel="eventChannel"
                                   type="com.test.PostPublishedEvent"/>

    <int:service-activator input-channel="eventChannel" ref="RedisEventProcessingService"
                          method="process">
       <int:poller fixed-delay="10" time-unit="SECONDS" max-messages-per-poll="500"/>
    </int:service-activator> 

I read an article on similar topic where they were using redis RPOPLPUSH for this purpose. But I am unable too figure out how to do it in Spring Integration. Link for the article is - https://redis.io/commands/RPOPLPUSH

Please advise me regading this. I will realy appricate your help.

Krishnendu
  • 1,289
  • 18
  • 26

1 Answers1

0

Spring integration does not have a component that utilizes that operation.

To use it, you should wrap a RedisTemplate in a <int:service-activator/> and call one of its rightPopAndLeftPush() methods.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • According to the *Reliable queue* description we should consider to utilize such a feature for retries/redeliveries in case of errors. You can do that yourself, though, still using that ``, but with additional logic on the `error-channel` to `rightPush()` message to the queue back. – Artem Bilan Apr 05 '19 at 15:22