【发布时间】:2019-05-20 05:39:07
【问题描述】:
我正在使用基于 Redis 的出色 Bull.js 作为 Kubernetes 上的作业队列。
它被配置为一个集群:
当 Kubernetes 在部署时重新启动时,我遇到了以下错误:
BRPOPLPUSH { ReplyError: MOVED 2651 <IP_ADDRESS>:6379
at parseError (/usr/src/app/node_modules/ioredis/node_modules/redis-parser/lib/parser.js:179:12)
at parseType (/usr/src/app/node_modules/ioredis/node_modules/redis-parser/lib/parser.js:302:14)
command:
{ name: 'brpoplpush',
args:
[ '{slack}:slack notifications:wait',
'{slack}:slack notifications:active',
'5' ] } }
<IP_ADDRESS> 在哪里,我认为集群 IP?我没有配置这个,但我正在尝试调试它。我想知道是否需要为 Bull.js 启用集群模式,或者这是否是 Bull.js 项目之外的配置问题?
还是 K8s 的网络问题?
启用:https://github.com/OptimalBits/bull#cluster-support 会是解决方案吗?这是正确的方法吗?
这是我的代码:
import Queue from 'bull';
import config from 'config';
import { run as slackRun } from './tasks/send-slack-message';
import { run as emailRun } from './tasks/send-email';
const redisConfig = {
redis: {
host: config.redis.host,
port: config.redis.port
}
};
const slackQueue = new Queue('slack notifications', { ...redisConfig, ...{ prefix: '{slack}' } });
const emailQueue = new Queue('email notifications', { ...redisConfig, ...{ prefix: '{email}' } });
slackQueue.process(slackRun);
emailQueue.process(emailRun);
emailQueue.on('completed', (job, result) => {
job.remove();
});
export { emailQueue, slackQueue };
import { emailQueue, slackQueue } from 'worker/worker';
const queueOptions = {
attempts: 2,
removeOnComplete: true,
backoff: {
type: 'exponential',
delay: 60 * 1000
}
};
emailQueue.add(
{
params: {
from: email,
fromname: name,
text: body
}
},
queueOptions
);
slackQueue.add(
{
channelId: SLACK_CHANNELS.FEEDBACK,
attachments: [
{
text: req.body.body
}
]
},
queueOptions
);
这是配置图:
Name: redis-cluster-config
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
update-node.sh:
----
#!/bin/sh
REDIS_NODES="/data/nodes.conf"
sed -i -e "/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${POD_IP}/" ${REDIS_NODES}
exec "$@"
redis.conf:
----
cluster-enabled yes
cluster-require-full-coverage no
cluster-node-timeout 15000
cluster-config-file nodes.conf
cluster-migration-barrier 1
appendonly yes
# Other cluster members need to be able to connect
protected-mode no
Events: <none>
【问题讨论】:
-
你在使用 helm chart 来设置 redis 吗?
-
不使用舵图。
-
@bob_cobb,我敢打赌这是 ioredis 问题。所以值得尝试使用主从设置。
标签: kubernetes redis bull.js