12.1. Overview

Redisson offers ability to run as standalone node and participate in distributed computing. Such Nodes are used to run MapReduce, ExecutorService, ScheduledExecutorService tasks or RemoteService services. All tasks are kept in Redis until their execution moment.

Packaged as a single jar and could be downloaded.

12. Standalone node - 图1

12.2. Configuration

12.2.1. Configuration. Settings

Redisson node uses same configuration as Redisson framework with additional settings. Threads amount available for ExecutorService set through threads setting

mapReduceWorkers

Default value: 0

MapReduce workers amount. 0 = current_processors_amount

executorServiceWorkers

Default value: null

Map with key as service name and value as workers amount.

redissonNodeInitializer

Default value: null

Listener runs during Redisson node startup.

beanFactory

Default value: null

Defines Spring Bean Factory instance to execute tasks with Spring’s ‘@Autowired’, ‘@Value’ or JSR-330’s ‘@Inject’ annotation. Please refer to documentation for ExecutorService and [ScheduledExecutorService]

12.2.2. Configuration. YAML config format

Below is the configuration example for cluster mode with appended Redisson node settings in YAML format.

  1. ---
  2. clusterServersConfig:
  3. nodeAddresses:
  4. - "//127.0.0.1:7004"
  5. - "//127.0.0.1:7001"
  6. - "//127.0.0.1:7000"
  7. scanInterval: 1000
  8. threads: 0
  9. executorServiceWorkers:
  10. myService1: 123
  11. myService2: 421
  12. redissonNodeInitializer: !<org.mycompany.MyRedissonNodeInitializer> {}

12.3. Initialization listener

Redisson node allows to execute initialization logic during startup via RedissonNodeInitializer listener. It allows, for example, register your remote service implementations which should be available in Redisson node’s classpath, or execute other useful logic. For example, notify all subscribers about new Redisson node is available.

  1. public class MyRedissonNodeInitializer implements RedissonNodeInitializer {
  2. @Override
  3. public void onStartup(RedissonNode redissonNode) {
  4. RMap<String, Integer> map = redissonNode.getRedisson().getMap("myMap");
  5. // ...
  6. // or
  7. redisson.getRemoteService("myRemoteService").register(MyRemoteService.class, new MyRemoteServiceImpl(...));
  8. // or
  9. reidsson.getTopic("myNotificationTopic").publish("New node has joined. id:" + redissonNode.getId() + " remote-server:" + redissonNode.getRemoteAddress());
  10. }
  11. }

12.4. How to run as embedded node

Redisson node can be embedded into your application:

  1. // Redisson config
  2. Config config = ...
  3. // Redisson Node config
  4. RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config);
  5. Map<String, Integer> workers = new HashMap<String, Integer>();
  6. workers.put("test", 1);
  7. nodeConfig.setExecutorServiceWorkers(workers);
  8. // create Redisson node
  9. RedissonNode node = RedissonNode.create(nodeConfig);
  10. // or create Redisson node with existing Redisson instance
  11. RedissonNode node = RedissonNode.create(nodeConfig, redisson);
  12. node.start();
  13. //...
  14. node.shutdown();

12.5. How to run from command-line

  1. Download Redisson node jar
  2. Create yaml configuration file
  3. Run node using follow command line:
    java -jar redisson-all.jar config.yaml

don’t forget to add -Xmx and -Xms params

12.6. How to run using Docker

with Redis instance

  1. Run Redis
    docker run -d --name redis-node redis
  2. Redisson Node
    docker run -d --network container:redis-node -e JAVA_OPTS="<java-opts>" -v <path-to-config>:/opt/redisson-node/redisson.conf redisson/redisson-node

    <path-to-config> - path to YAML configuration of Redisson Node <java-opts> - JVM params

without Redis instance

  1. Redisson Node
    docker run -d -e JAVA_OPTS="<java-opts>" -v <path-to-config>:/opt/redisson-node/redisson.conf redisson/redisson-node

    <path-to-config> - path to YAML configuration of Redisson Node <java-opts> - JVM params