通过Spring-boot应用程序和生菜库在Redis中听一个队列
我已经根据Spring-Boot,Spring-Cloud和Microservices Architecture开发了不同的服务,我也将以下依赖项(redis-client
>:我
implementation 'io.lettuce:lettuce-core:6.1.5.RELEASE'
定义了redisbean
>) 使用以下依赖关系。在春季如下:
@Configuration
public class RedisBean {
@Bean
public RedisClient redisClientFactory(AppConfig config) {
var client = RedisClient.create(config.getRedis());
client.setDefaultTimeout(Duration.ZERO);
return client;
}
@Bean
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public StatefulRedisConnection<byte[], byte[]> redisConnectionFactory(RedisClient client) {
return client.connect(ByteArrayCodec.INSTANCE);
}
@Bean
public RedisCommands<byte[], byte[]> redisCommands(StatefulRedisConnection<byte[], byte[]> connection) {
return connection.sync();
}
}
我有sso
和Accounting
服务。
在我的sso
服务中,当用户寄存器时,我将在queue
中按照这样的用户名:
@Service
public class AccountingServiceImpl implements AccountingService {
private final RedisCommands<byte[], byte[]> redis;
private final AppConfig appConfig;
public AccountingServiceImpl(AppConfig appConfig, RedisCommands<byte[], byte[]> redis) {
this.redis = redis;
this.appConfig = appConfig;
}
@Override
public void requestCreateDefaultAccount(String username) {
redis.rpush(
appConfig.getCreateAccountQueueName().getBytes(StandardCharsets.UTF_8)
, username.getBytes(StandardCharsets.UTF_8)
);
}
}
现在:现在在Accounting
服务中,我想定期收听已注册的Queue
,并且只要按下用户名,我就会使用它并为用户创建一个默认帐户。
我已经搜索了很多东西,但找不到适合我的要求的解决方案,使用io.lettuce:生菜核
库。
任何帮助将不胜感激!!
I have developed different services based on Spring-boot, Spring-cloud, and microservices architecture, also I am using the following dependency as Redis-client
:
implementation 'io.lettuce:lettuce-core:6.1.5.RELEASE'
I have defined my RedisBean
in Spring as below:
@Configuration
public class RedisBean {
@Bean
public RedisClient redisClientFactory(AppConfig config) {
var client = RedisClient.create(config.getRedis());
client.setDefaultTimeout(Duration.ZERO);
return client;
}
@Bean
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public StatefulRedisConnection<byte[], byte[]> redisConnectionFactory(RedisClient client) {
return client.connect(ByteArrayCodec.INSTANCE);
}
@Bean
public RedisCommands<byte[], byte[]> redisCommands(StatefulRedisConnection<byte[], byte[]> connection) {
return connection.sync();
}
}
I have SSO
and ACCOUNTING
services.
In my SSO
service when a user register, I will push the username in Queue
like this:
@Service
public class AccountingServiceImpl implements AccountingService {
private final RedisCommands<byte[], byte[]> redis;
private final AppConfig appConfig;
public AccountingServiceImpl(AppConfig appConfig, RedisCommands<byte[], byte[]> redis) {
this.redis = redis;
this.appConfig = appConfig;
}
@Override
public void requestCreateDefaultAccount(String username) {
redis.rpush(
appConfig.getCreateAccountQueueName().getBytes(StandardCharsets.UTF_8)
, username.getBytes(StandardCharsets.UTF_8)
);
}
}
Now in the ACCOUNTING
service, I want to regularly listen to the registered Queue
and whenever a username was pushed, I take it and create a default account for the user.
I have searched a lot but couldn't find a suitable solution for my requirements using io.lettuce:lettuce-core
library.
Any help would be appreciated!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论