2

当 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 顺利工作。

用于繁殖:

邮件模块.ts

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

邮件处理器.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,
    );
  }
}

用户服务.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, 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: 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, 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: 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, 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: 4)

帮助!!

4

0 回答 0