Spring 集成 Redis RPOPLPUSH

标签 spring redis spring-integration spring-data-redis

我是 Spring Integration 和 Redis 的新手,如果我犯了一个天真的错误,我深表歉意。

我的要求如下-

  1. 需要实现一个消息队列。用于根据某些事件向用户发送资金。
  2. 队列不应该是易变的并且确保原子性。如果我重新启动服务器或它崩溃了,它不应该丢失事件消息。这也包括当前正在处理的消息。
  3. 队列应该传递授予一次且仅一次的消息。它将是一个多线程( worker )和多服务器环境。

到目前为止,我的进展是 - 在我的 spring 项目中配置了 Spring Integration 和 Spring Integration Redis。我的 Spring Integration 配置如下 -

    <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> 

我阅读了一篇关于类似主题的文章,其中他们为此目的使用了 redis RPOPLPUSH。但我无法弄清楚如何在 Spring Integration 中做到这一点。 该文章的链接是 - https://redis.io/commands/RPOPLPUSH

请建议我重新审视这个。我真的很感激你的帮助。

最佳答案

Spring Integration 没有利用该操作的组件。

要使用它,你应该包装一个 RedisTemplate<int:service-activator/>并调用其中一个 rightPopAndLeftPush()方法。

关于Spring 集成 Redis RPOPLPUSH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55535992/

相关文章:

mysql - spring boot和hibernate mysql数据库连接一直断开

Spring Boot @Autowired by generic 不适用于 @InjectMocks

ruby-on-rails - 在 Rails 中,有没有办法从 rescue_from 中提取 "short-circuit"?

python - 使用 Heroku 安装 Celery 和 Redis

java - 以互操作方式序列化消息的最佳方式是什么?

spring - FTP 出站网关委托(delegate) session 工厂性能

java.lang.AbstractMethodError : org. apache.activemq.ActiveMQConnection.createSession 错误

java - 用于数组验证的 Hibernate ScriptAssert

spring - 无法连接到本地 Spring boot 中 docker 上运行的 redis sentinel

java - JMS 轮询器事务