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.
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.
---
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
- Download Redisson node jar
- Create yaml configuration file
- 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
- Run Redis
docker run -d --name redis-node redis
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
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