我是 Spring Integration 和 Redis 的新手,如果我犯了一个天真的错误,我深表歉意。
我的要求如下-
- 需要实现一个消息队列。用于根据某些事件向用户发送资金。
- 队列不应该是易变的并且确保原子性。如果我重新启动服务器或它崩溃了,它不应该丢失事件消息。这也包括当前正在处理的消息。
- 队列应该传递授予一次且仅一次的消息。它将是一个多线程( 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/