qQuarkus

netty-socket-io.hostname=localhost
netty-socket-io.port=9092
netty-socket-io.ping-timeout=60000
netty-socket-io.ping-interval=25000

主应用程序

@ApplicationScoped
public class QuarkusMainApplication {
    
    @Inject
    SocketIOServer server;
    
    void onStart(@Observes StartupEvent ev) {
        // 添加事件监听器
        server.addEventListener("chatevent", ChatMessage.class, (client, data, ackRequest) -> {
            server.getBroadcastOperations().sendEvent("chatevent", data);
        });
        
        server.start();
        log.info("Socket.IO server started on port {}", server.getConfiguration().getPort());
    }
    
    void onStop(@Observes ShutdownEvent ev) {
        server.stop();
    }
}

事件处理程序

完整示例

在以下位置查看完整示例 netty-socketio-examples-quarkus-basearrow-up-right 模块。

最后更新于

这有帮助吗?