quantranhong1999 commented on code in PR #2028:
URL: https://github.com/apache/james-project/pull/2028#discussion_r1503637115
##########
event-bus/distributed/src/main/java/org/apache/james/events/KeyRegistrationBinder.java:
##########
@@ -19,36 +19,30 @@
package org.apache.james.events;
+import io.lettuce.core.api.reactive.RedisSetReactiveCommands;
import reactor.core.publisher.Mono;
-import reactor.rabbitmq.BindingSpecification;
-import reactor.rabbitmq.Sender;
-class RegistrationBinder {
- private final NamingStrategy namingStrategy;
- private final Sender sender;
- private final RegistrationQueueName registrationQueue;
+class KeyRegistrationBinder {
+ private final RedisSetReactiveCommands<String, String>
redisSetReactiveCommands;
+ private final RegistrationChannelName registrationChannel;
- RegistrationBinder(NamingStrategy namingStrategy, Sender sender,
RegistrationQueueName registrationQueue) {
- this.namingStrategy = namingStrategy;
- this.sender = sender;
- this.registrationQueue = registrationQueue;
+ KeyRegistrationBinder(RedisSetReactiveCommands<String, String>
redisSetReactiveCommands,
+ RegistrationChannelName registrationChannel) {
+ this.redisSetReactiveCommands = redisSetReactiveCommands;
+ this.registrationChannel = registrationChannel;
}
Mono<Void> bind(RegistrationKey key) {
- return sender.bind(bindingSpecification(key))
+ // Use Redis Set to store 1 registrationKey -> n channel(s) mapping in
Redis
+ RoutingKeyConverter.RoutingKey routingKey =
RoutingKeyConverter.RoutingKey.of(key);
+ return redisSetReactiveCommands.sadd(routingKey.asString(),
registrationChannel.asString())
.then();
}
Mono<Void> unbind(RegistrationKey key) {
- return sender.unbind(bindingSpecification(key))
- .then();
- }
-
- private BindingSpecification bindingSpecification(RegistrationKey key) {
+ // delete the registrationKey -> channel mapping in Redis
RoutingKeyConverter.RoutingKey routingKey =
RoutingKeyConverter.RoutingKey.of(key);
- return BindingSpecification.binding()
- .exchange(namingStrategy.exchange())
- .queue(registrationQueue.asString())
- .routingKey(routingKey.asString());
+ return redisSetReactiveCommands.srem(routingKey.asString(),
registrationChannel.asString())
Review Comment:
Likely we can write a task/cron job to clean up the mappings in that case.
Using Redis `PUBSUB CHANNEL` can list all active channels.
Then scan the mappings and delete the ones that mapped to an unactive
channel.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]