通过Spring-boot应用程序和生菜库在Redis中听一个队列

发布于 2025-02-05 19:04:35 字数 1891 浏览 1 评论 0原文

我已经根据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();
    }
}

我有ssoAccounting服务。

在我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文