GCT1015
最近有WSQ库解决了通过 websocket 连接与 NSQ 通信的任务。它允许在 Websocket 和 NSQ 端分别定义消息编码/解码逻辑。此外,WSQ 支持注入认证和授权逻辑,控制用户订阅和发布主题的权限,以及基于消息内容的传入消息过滤。创建 WSQ 服务器示例:// Create the default configwsqConfig := wsq.NewConfig()// Configure Websocket CheckOrigin callback to bypass any checks.// Don't do it in production!wsqConfig.SetWSCheckOrigin(wsq.CheckOriginBypass)// Create the server instance specifying message and user types to use.server := wsq.NewServer[message, *wsq.AnonymousUser]( // Address (optional) and port to listen on ":9980", // WSQ Config instance wsqConfig, // NSQ Config instance nsq.NewConfig(), // WSQ Transformer struct providing encoders/decoders for NSQ and Websocket sides respectivly &wsq.Transformer[message]{NSQEnDec: &nsqEnDec{}, WSEnDec: &wsEnDec{}}, // Authentication controller &wsq.NoAuthentication,)server.Run()