我正在尝试设置一个 Bull Board 以查看我的 Redis 队列,但是当我访问时我总是收到“页面地址无效”0.0.0.0:8000/admin/queues
我正在关注 Bull Board文档中的 Hello World 示例。
我的 Express 服务器正在运行0.0.0.0:8000
我的 Redis 服务器正在运行http://0.0.0.0:6379
,我能够成功添加和运行作业(使用 测试redis-cli
)。
问题:
- 文档说要安装
rpm i @bull-board/express
,但 Hello World 示例使用了该@bull-board/api
软件包,因此我在调试时也安装了该软件包。我应该这样做吗?
任何人都可以在这里看到我哪里出错了吗?
代码:
包.json
"dependencies": {
"@bull-board/api": "^3.7.0",
"@bull-board/express": "^3.7.0",
"bull": "^4.1.1",
...other packages
}
Redis 配置
module.exports = {
port: process.env.REDIS_PORT || 6379,
host: process.env.REDIS_HOST || '0.0.0.0',
};
Redis 报告通知队列
const Bull = require('bull')
const redisConfig = require('../config');
// Create Queue
const reportNotificationsQueue = new Bull('reportNotifications', {
redis: redisConfig
})
// Producer: adds job to queue
const addReportNotification = (data) => {
reportNotificationsQueue.add(data)
}
// Consumer: function to run
const sendReportNotification = async (job) => {
console.log('Job Data',job.data)
// ... job logic
}
// Process Queue
reportNotificationsQueue.process(sendReportNotification)
module.exports = {
reportNotificationsQueue,
addReportNotification
}
快速服务器设置
/* IMPORTS */
const redis = require('redis');
const redisConfig = require('../redis/config');
const { createBullBoard } = require('@bull-board/api')
const { BullAdapter } = require('@bull-board/api/bullAdapter')
const { ExpressAdapter } = require('@bull-board/express')
const { reportNotificationsQueue } = require('../redis/queues/reportNotifications')
...more express configurations
/* Redis: client */
const redisClient = redis.createClient(redisConfig);
redisClient.on('connect', () => {
console.log(`Redis Connection Established: http://${redisConfig.host}:${redisConfig.port}`);
});
redisClient.on('error', () => {
console.error('Redis Failed To Establish Connection');
});
/* Redis: bull board */
const serverAdapter = new ExpressAdapter();
const { addQueue, removeQueue, setQueues, replaceQueues } = createBullBoard({
queues: [
new BullAdapter(reportNotificationsQueue),
],
serverAdapter: serverAdapter
})
serverAdapter.setBasePath('/admin/queues')
app.use('/admin/queues', serverAdapter.getRouter());
...more express configurations