Bull 不会在 localhost:6379 上没有 redis 运行,即使我在不​​同的端口上运行 redis

问题描述

当 hasura 看到表格上的更新并触发电子邮件微服务的有效负载时,我正在使用 Bull 处理发送的邮件

问题是,尽管 hasura 成功发送了有效负载,但如果 redis 未在 localhost:6379 上运行,即使我在 6380 上运行 redis 并在其中指定,控制器也无法对信息进行排队

BullModule.registerQueue({ name: MAIL_QUEUE,redis: {host: 'localhost',port: 6380 })

最重要的是,如果有一个redis实例运行在6379上,那么Bull完全忽略了我在registerQueue里面使用的参数,并以某种方式使用redis 0n 6379顺利运行。

用于复制:

ma​​il.module.ts

@Module({
  imports: [
    BullModule.registerQueue({ name: MAIL_QUEUE,redis: REdis_QUEUE_URL }),UserModule
  ],controllers: [MailController],providers: [MailService,MailProcessor],})
export class MailModule {}

ma​​il.processor.ts

@Processor(MAIL_QUEUE)
export class MailProcessor {
  constructor(
    private readonly mailService: MailService,private readonly userService: UserService,) {}
@Process('mail_principal_on_school_create')
  async mailPrincipalOnSchoolCreate(job: Job) {
    const schoolname = job.data.schoolname;
    const email = job.data.email;
    const firstname = job.data.firstname;
    const lastname = job.data.lastname;

    await this.mailService.sendMail(
      {
        name: `${firstname} ${lastname}`,schoolname: schoolname,email: email,},POSTMARK_MAIL_PRINCIPAL_ON_SCHOOLCREATE_TEMPLATE_ID,);
  }
}

user.service.ts

@Injectable()
export class UserService {
  constructor(
    @InjectQueue(MAIL_QUEUE) private mailQueue: Queue,){}
async mailPrincipalOnSchoolCreate(data) {
    const school_name = data.event.data.new.name;
    const email = data.event.data.new.principal_email;
    const firstname = data.event.data.new.principal_name;
    const lastname = data.event.data.new.principal_surname;

    this.mailQueue.add('mail_principal_on_school_create',{
      email: email,firstname: firstname,lastname: lastname,schoolname: school_name,});
  }
}

所以来自 hasura 的触发器到达 user.service.ts 但永远不会被添加到队列中,除非有一个 redis 实例在 6379 上运行。

顺便说一句,这里是错误

(node:126435) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:126435) 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(). To terminate the node process on unhandled promise rejection,use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:126435) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future,promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:126435) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(node:126435) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:126435) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(node:126435) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
(node:126435) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
(node:126435) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block,use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)

帮助!!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)