【问题标题】:NesJS RabbitMQ with @golevelup/nestjs-rabbitmq no connection when using new connectioninitNesJS RabbitMQ 与 @golevelup/nestjs-rabbitmq 使用新的 connectioninit 时没有连接
【发布时间】:2022-02-21 18:06:52
【问题描述】:

使用@golevelup/nestjs-rabbitmq 我尝试连接管理器不等待连接。根据readme,它可以处理重新连接并等待连接而不会导致应用程序崩溃。但是,当我按照说明使用connectionInitOptions 并将wait 设置为false 时,出现连接错误。当我不使用它时(默认行为设置 waittrue),它会连接到 RabbitMQ 服务器。下面是在 NestJS 模块中导入 RabbitMQModule 的示例。

这工作并连接到 RabbitMQ 服务器

RabbitMQModule.forRoot(RabbitMQModule, {
      exchanges: [{ type: 'topic', name: 'main' }],
      uri: 'amqp://guest:guest@localhost:5672',
    }

这不起作用,无法连接

RabbitMQModule.forRoot(RabbitMQModule, {
      exchanges: [{ type: 'topic', name: 'main' }],
      uri: 'amqp://guest:guest@localhost:5672',
      connectionInitOptions: {
        wait: false,
      },

使用第二个选项我得到以下错误:

Error: AMQP connection is not available
    at AmqpConnection.publish (/home/xxx/node_modules/@golevelup/nestjs-rabbitmq/src/amqp/connection.ts:424:13)
    at BootstrapService.onApplicationBootstrap (/home/xxx/src/bootstrap/bootstrap.service.ts:20:25)
    at MapIterator.iteratee (/home/xxx/node_modules/@nestjs/core/hooks/on-app-bootstrap.hook.js:22:43)
    at MapIterator.next (/home/xxx/node_modules/iterare/src/map.ts:9:39)
    at IteratorWithOperators.next (/home/xxx/node_modules/iterare/src/iterate.ts:19:28)
    at Function.from (<anonymous>)
    at IteratorWithOperators.toArray (/home/xxx/node_modules/iterare/src/iterate.ts:227:22)
    at callOperator (/home/xxx/node_modules/@nestjs/core/hooks/on-app-bootstrap.hook.js:23:10)
    at callModuleBootstrapHook (/home/xxx/node_modules/@nestjs/core/hooks/on-app-bootstrap.hook.js:43:23)
    at NestApplication.callBootstrapHook (/home/xxx/node_modules/@nestjs/core/nest-application-context.js:199:55)
    at NestApplication.init (/home/xxx/node_modules/@nestjs/core/nest-application.js:98:9)
    at NestApplication.listen (/home/xxx/node_modules/@nestjs/core/nest-application.js:155:33)
    at bootstrap (/home/xxx/src/main.ts:12:3)

最后一行 (main.ts:12:3) 是 app.listen(3000) 语句。 您可以使用connectionInitOptionsrejecttimeout)设置其他选项,我已经尝试了这些组合,但仍然没有连接。

RabbitMQ 在 Linux 上的 docker 容器中运行,但这应该没问题。我在 NestJS discord 上发布了同样的问题,但没有得到回复,所以希望 SO 上的人有想法。

知道可能是什么原因吗?

【问题讨论】:

    标签: rabbitmq nestjs


    【解决方案1】:

    发现问题,我在onApplicationBootstrap 方法中使用连接,然后连接显然还不存在。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-21
      • 1970-01-01
      相关资源
      最近更新 更多