首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >graphql-redis- Heroku上的订阅不一致

graphql-redis- Heroku上的订阅不一致
EN

Stack Overflow用户
提问于 2019-08-21 03:26:28
回答 1查看 357关注 0票数 1

我们在节点graphql服务器上使用订阅。最近,我添加了集群功能,并将Redis用于pubsub。在我的本地环境中,一切都运行得很好。当我上传到heroku并使用他们的Redis插件时,当我第一次触发一个突变时,我看到它显示了,但下一次它不显示。经过几次尝试后,它再次工作(50%的工作)。

代码语言:javascript
复制
import { RedisPubSub } from 'graphql-redis-subscriptions';
import Redis from 'ioredis';

let REDIS_URL = process.env.REDIS_URL || 'redis://127.0.0.1:6379';

const options = {
  retryStrategy: times => {
    // reconnect after
    return Math.min(times * 50, 2000);
  }
};

const pubsub = new RedisPubSub({
  publisher: new Redis(REDIS_URL, options),
  subscriber: new Redis(REDIS_URL, options)
});

下面是我在日志中得到的错误

代码语言:javascript
复制
Aug 22 16:06:11 service-staging app[web] Error (node:76) UnhandledPromiseRejectionWarning: Error: Connection in subscriber mode, only subscriber commands may be used
Aug 22 16:06:11 service-staging app[web] info     at Redis.sendCommand (/app/node_modules/ioredis/built/redis/index.js:570:24)
Aug 22 16:06:11 service-staging app[web] info     at DatastoreShim.applySegment (/app/node_modules/newrelic/lib/shim/shim.js:1424:20)
Aug 22 16:06:11 service-staging app[web] info     at _applyRecorderSegment (/app/node_modules/newrelic/lib/shim/shim.js:1015:20)
Aug 22 16:06:11 service-staging app[web] info     at Redis._doRecord (/app/node_modules/newrelic/lib/shim/shim.js:994:17)
Aug 22 16:06:11 service-staging app[web] info     at Redis.wrapper [as sendCommand] (/app/node_modules/newrelic/lib/shim/shim.js:965:24)
Aug 22 16:06:11 service-staging app[web] info     at Redis.publish (/app/node_modules/ioredis/built/commander.js:124:21)
Aug 22 16:06:11 service-staging app[web] info     at RedisPubSub.<anonymous> (/app/node_modules/graphql-redis-subscriptions/src/redis-pubsub.ts:64:31)
Aug 22 16:06:11 service-staging app[web] info     at step (/app/node_modules/graphql-redis-subscriptions/dist/redis-pubsub.js:32:23)
Aug 22 16:06:11 service-staging app[web] info     at Object.next (/app/node_modules/graphql-redis-subscriptions/dist/redis-pubsub.js:13:53)
Aug 22 16:06:11 service-staging app[web] info     at /app/node_modules/graphql-redis-subscriptions/dist/redis-pubsub.js:7:71
Aug 22 16:06:11 service-staging app[web] info     at new Promise (<anonymous>)
Aug 22 16:06:11 service-staging app[web] info     at __awaiter (/app/node_modules/graphql-redis-subscriptions/dist/redis-pubsub.js:3:12)
Aug 22 16:06:11 service-staging app[web] info     at RedisPubSub.publish (/app/node_modules/graphql-redis-subscriptions/dist/redis-pubsub.js:76:16)
Aug 22 16:06:11 service-staging app[web] info     at publish (/app/src/resolvers/action.js:435:18)
Aug 22 16:06:11 service-staging app[web] info (node:76) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 9)

当我运行突变时,我应该看到它出现在侦听订阅中。

此外,顺便说一句,如果我将实例数设置为1或2,我总是会得到错误。3或更多,我至少得到了第一个突变和第二个突变的一半。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-23 05:41:56

在经历了许多个人的痛苦和痛苦之后,我让它运行起来。我删除了Heroku Redis插件,并将其替换为Redis Cloud插件。所有工作都和预期的一样!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57580352

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档