I am using This for socketio setup.
I have 2 different socketio server(let say server1 and server2) running in cluster with using of RedissonStoreFactory
My issue is, If any client connects with server1, then server2 has no information if connected client.
ie. If 2 clients connect with server1 and If I execute server.getAllClients()
on server2 it returns the empty list instead of the list with 2 counts.
Here is my code running on 2 different machines.
@SpringBootApplication
public class Application {
private static final Logger LOGGER = Logger.getLogger(Application.class);
@Value("${test.socketio.hostName}")
private String socketIOHostName;
@Value("${test.socketio.port}")
private Integer socketIOport;
@Value("${test.dedisson.redissonAddress}")
private String redissonAddress;
@Autowired
private RedissonClient redissonClient;
@Bean
public SocketIOServer socketIOServer() {
LOGGER.info("Socket server starting on host=" + socketIOHostName + ", port=" + socketIOport);
Configuration config = new Configuration();
config.setHostname(socketIOHostName);
config.setPort(socketIOport);
StoreFactory redissonStoreFactory = new RedissonStoreFactory(redissonClient);
config.setStoreFactory(redissonStoreFactory);
SocketIOServer server = new SocketIOServer(config);
server.start();
LOGGER.info( "Socket server started");
return server;
}
/**
*
* @return
*/
@Bean
public RedissonClient getRedissonClient(){
LOGGER.info("creatting redisson client on redissonAddress="+redissonAddress);
Config config = new Config();
config.useSingleServer().setAddress(redissonAddress);
RedissonClient redisson = Redisson.create(config);
LOGGER.info("redisson client connected");
return redisson;
}
public Application() {
//Nothing to be done here
}
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);
}
@Bean
public SpringAnnotationScanner springAnnotationScanner(SocketIOServer ssrv) {
return new SpringAnnotationScanner(ssrv);
}
}
I prefer 2 instances for failover condition.If server1 is down then server2 will send the notification to connected clients, but in my case, server2 has no idea of the connected client with server1.