Open silloy opened 4 years ago
How to use redisson:
@Component
@Slf4j
public class ServerRunner implements CommandLineRunner, ApplicationListener<ContextClosedEvent> {
private SocketIOServer server;
@Autowired
private RedissonStoreFactory redissonStoreFactory;
@Bean
public SocketIOServer socketIOServer() {
Configuration config = new Configuration();
config.setPort("9090");
config.setStoreFactory(redissonStoreFactory);
server = new SocketIOServer(config);
return server;
}
@Bean
public SpringAnnotationScanner springAnnotationScanner(SocketIOServer socketServer) {
return new SpringAnnotationScanner(socketServer);
}
@Override
public void run(String... args) {
server.start();
}
@Override
public void onApplicationEvent(ContextClosedEvent event) {
server.stop();
}
}
Then let clients join the same room on different JVMs.
client1.joinRoom("roomName");
client2.joinRoom("roomName");
When you send message,you can use the sendEvent() method:
server.getRoomOperations("roomName").sendEvent("eventName",message);
The client will subscribe the dispatch event ,and when you invoke the sendEvent() method ,netty-socketio will publish a dispatch event,detials in BroadcastOperation#dispatch(Packet packet).
I hope this can help you .
How to use redisson:
@Component @Slf4j public class ServerRunner implements CommandLineRunner, ApplicationListener<ContextClosedEvent> { private SocketIOServer server; @Autowired private RedissonStoreFactory redissonStoreFactory; @Bean public SocketIOServer socketIOServer() { Configuration config = new Configuration(); config.setPort("9090"); config.setStoreFactory(redissonStoreFactory); server = new SocketIOServer(config); return server; } @Bean public SpringAnnotationScanner springAnnotationScanner(SocketIOServer socketServer) { return new SpringAnnotationScanner(socketServer); } @Override public void run(String... args) { server.start(); } @Override public void onApplicationEvent(ContextClosedEvent event) { server.stop(); } }
Then let clients join the same room on different JVMs.
client1.joinRoom("roomName"); client2.joinRoom("roomName");
When you send message,you can use the sendEvent() method:
server.getRoomOperations("roomName").sendEvent("eventName",message);
The client will subscribe the dispatch event ,and when you invoke the sendEvent() method ,netty-socketio will publish a dispatch event,detials in BroadcastOperation#dispatch(Packet packet).
I hope this can help you .
server.getRoomOperations("roomName").sendEvent("eventName",message);
how to receive this message?
I hava two server use same redis instance, server1 and server2, client has connect to server1, how Can I send message to client from server2?
server2 code:
client is none, I want to know why? I have use the redis