12. Standalone node

Nikita Koksharov edited this page Sep 29, 2018 · 44 revisions

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.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.

12.2.2. Configuration. JSON and YAML config format

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

{
   "clusterServersConfig":{
      "nodeAddresses":[
         "//127.0.0.1:7004",
         "//127.0.0.1:7001",
         "//127.0.0.1:7000"
      ],
   },
   "threads":0,

   "executorServiceWorkers": {"myExecutor1":3, "myExecutor2":5},
   "redissonNodeInitializer": {"class":"org.mycompany.MyRedissonNodeInitializer"}
}

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

---
clusterServersConfig:
  nodeAddresses:
  - "//127.0.0.1:7004"
  - "//127.0.0.1:7001"
  - "//127.0.0.1:7000"
  scanInterval: 1000
threads: 0

executorServiceWorkers:
  myService1: 123
  myService2: 421
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.

public class MyRedissonNodeInitializer implements RedissonNodeInitializer {

    @Override
    public void onStartup(RedissonNode redissonNode) {
        RMap<String, Integer> map = redissonNode.getRedisson().getMap("myMap");
        // ...
        // or
        redisson.getRemoteService("myRemoteService").register(MyRemoteService.class, new MyRemoteServiceImpl(...));
        // or
        reidsson.getTopic("myNotificationTopic").publish("New node has joined. id:" + redissonNode.getId() + " remote-server:" + redissonNode.getRemoteAddress());
    }

}

12.4. How to run as embedded node

Redisson node can be embedded into your application:

// Redisson config
Config config = ...
// Redisson Node config
RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config);
Map<String, Integer> workers = new HashMap<String, Integer>();
workers.put("test", 1);
nodeConfig.setExecutorServiceWorkers(workers);

// create Redisson node
RedissonNode node = RedissonNode.create(nodeConfig);
// or create Redisson node with existing Redisson instance
RedissonNode node = RedissonNode.create(nodeConfig, redisson);

node.start();

//...

node.shutdown();

12.5. How to run from command-line

  1. Download Redisson node jar
  2. Create json or yaml configuration file
  3. Run node using follow command line:
    java -jar redisson-all.jar config.json
    or
    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 or JSON 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 or JSON configuration of Redisson Node <java-opts> - JVM params

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.