【发布时间】:2019-08-27 09:26:07
【问题描述】:
我是 Spring Integration 和 Redis 的新手,所以如果我犯了一个幼稚的错误,我深表歉意。
我的要求如下-
- 需要实现一个消息队列。用于根据某些事件向用户分配资金。
- 队列不应该是易变的并且保证原子性。如果我重新启动服务器或它崩溃了,它不应该丢失事件消息。这也包括当前正在处理的消息。
- 队列应传递一次且仅一次授予的消息。这将是一个多线程(工作者)和多服务器环境。
到目前为止,我的进展是 - 在我的 spring 项目中配置了 Spring Integration 和 Spring Integration Redis。我的 Spring 集成配置如下 -
<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 redis spring-integration spring-data-redis