Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-20812

Notification service for every node of a cluster

    XMLWordPrintable

    Details

      Description

      In cluster mode, it might be useful, for every node to be able to register to a notification channel, in order to be able to broadcast messages.

      Connect cluster has implemented a Redis Pub/Sub channel, for such notification, see GitCacheServiceCluster class.
      It is based on:

      • Nuxeo RedisExecutor class, to benefit from Nuxeo interface to the Redis server.
      • Subscription to the channel:
            protected void subscribeToRedis(RedisExecutor redisExecutor) {
                try {
                    log.info("Subscribing to Redis channel: " + CHANNEL);
                    redisExecutor.execute(new RedisCallable<Object>() {
                        @Override
                        public Object call(Jedis jedis) throws Exception {
                            jedis.subscribe(new JedisPubSub() {
        
                                @Override
                                public void onSubscribe(String channel, int subscribedChannels) {
                                    super.onSubscribe(channel, subscribedChannels);
                                    if (subscribtionLatch != null) {
                                        subscribtionLatch.countDown();
                                    }
                                }
        
                                @Override
                                public void onMessage(String channel, String message) {
                                    if (CHANNEL.equals(channel)) {
                                        log.debug("Receive message: " + message);
                                        GitCacheServiceClusterEvent event;
                                        try {
                                            event = GitCacheServiceClusterEvent.fromJSON(message);
                                            log.debug("Event read: " + event);
                                            handleRedisEvent(event);
                                        } catch (IOException e) {
                                            log.error("Error while parsing the message", e);
                                        }
                                    }
                                }
        
                            }, CHANNEL);
                            return null;
                        }
                    });
        
      • Publishing a message
        RedisExecutor redisExecutor = Framework.getService(RedisExecutor.class);
                    redisExecutor.execute(new RedisCallable<Object>() {
                        @Override
                        public Object call(Jedis jedis) throws Exception {
                            String json = event.toJSON();
                            return jedis.publish(CHANNEL, json);
                        }
                    });
        

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: