1. 程式人生 > >create a cluster of netty socketio servers for broadcasting messages

create a cluster of netty socketio servers for broadcasting messages

// Instantiate Redisson configuration
Config redissonConfig = new Config();
redissonConfig.useSingleServer().setAddress("127.0.0.1:6379");

// Instantiate Redisson connection
RedissonClient redisson = Redisson.create(redissonConfig);

// Instantiate RedissonClientStoreFactory
RedissonStoreFactory redisStoreFactory = new RedissonStoreFactory(redisson);

// Instantiate SocketIO Configuration
Configuration config = new Configuration();
config.setHostname("localhost");
config.setPort(9092);
config.setStoreFactory(redisStoreFactory);

// Instantiate SocketIO Server
SocketIOServer server = new SocketIOServer(config);

 

SocketIOClient serialization 

 

You don't need to serialize SocketIOClient object. Store its id to Redis:

UUID id = SocketIOClient.getSessionId();

and then get it again by id:

SocketIOServer doesnot  has  namespace

SocketIOClient client = SocketIOServer.getClient(id);

SocketIOServer  has  namespace 

 

 SocketIONamespace socketIONamespace = server.getNamespace(UkConstant.NOTICE_SPACE);
 SocketIOClient client = socketIONamespace.getClient(UUID.fromString(uuid));