我有一个由两部分组成的应用程序:一个使用graphql-subscriptions的 React 前端和一个带有MQTT 代理(及其 Web 套接字处理程序)和一个订阅服务器的 Node.js 应用程序。
如此处所述,我没有使用默认PubSub
实现(正在工作),而是尝试实现外部 PubSub 引擎,为此,我选择了graphql-redis-subscriptions。每当有消息到达服务器时,我都会收到以下错误:
2018-03-27 14:52:03: assert.js:42
throw new errors.AssertionError({
^
AssertionError [ERR_ASSERTION]: undefined == true
at MQEmitterRedis.emit (node_modules/mqemitter/mqemitter.js:98:3)
at handler (node_modules/mqemitter-redis/mqemitter-redis.js:36:12)
at Redis.<anonymous> (node_modules/mqemitter-redis/mqemitter-redis.js:46:5)
at emitThree (events.js:136:13)
at Redis.emit (events.js:217:7)
at Redis.exports.returnReply ( node_modules/ioredis/lib/redis/parser.js:119:14)
at JavascriptRedisParser.returnReply ( node_modules/ioredis/lib/redis/parser.js:27:13)
at JavascriptRedisParser.execute ( node_modules/redis-parser/lib/parser.js:574:12)
at Socket.<anonymous> ( node_modules/ioredis/lib/redis/event_handler.js:107:22)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at Socket.Readable.push (_stream_readable.js:208:10)
at TCP.onread (net.js:594:20)
我无法理解这里发生了什么。通过查看代码,这个断言似乎失败了,因为参数是 undefined。这是PubSub.js
文件的配置,当需要发布某些内容时会导入:
import { RedisPubSub } from 'graphql-redis-subscriptions';
import config from '../config/getConfig';
const { port, host } = config.redisConf;
// Options listed here: https://github.com/luin/ioredis/blob/master/API.md#new_Redis_new
const pubsub = new RedisPubSub({
connection: {
host,
port,
retry_strategy: options => Math.max(options.attempt * 100, 3000),
},
});
export default pubsub;
然后,在另一个文件中,我只是导入import pubSub from '../../helpers/PubSub';
并使用以下代码发布主题:
pubSub.publish(topic, { operation: { ... }});
你能建议我做错什么吗?谢谢