Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rmq socket options not passed correctly when creating a microservice #7317

Closed
alexreal1314 opened this issue Jun 28, 2021 · 4 comments
Closed
Labels
needs triage This issue has not been looked into

Comments

@alexreal1314
Copy link
Contributor

alexreal1314 commented Jun 28, 2021

Bug Report

Current behavior

When creating a RMQ microservice and passing socketOptions object it is not passed correctly to amqpb-connection-manager library. I saw the PR that was made #5790 but it did not resolve the issue.
The documentation listed in https://www.npmjs.com/package/amqp-connection-manager suggest that the following params:
options.heartbeatIntervalInSeconds and options.reconnectTimeInSeconds are passed directly to the library options.

Input Code

  const options: MicroserviceOptions = {
    transport: Transport.RMQ,
    options: {
      urls: [app.get('ConfigService').get('rabbit.hostname')],
      queue: app.get('ConfigService').get('rabbit.autopsyQueue'),
      prefetchCount: 1,
      noAck: false,
      queueOptions: {
        durable: true,
      },
      socketOptions: {
        heartbeatIntervalInSeconds: 6000,
        reconnectTimeInSeconds: 10
      }
    }
  }

//microservices/server.rmq.js
    createClient() {
        const socketOptions = this.getOptionsProp(this.options, 'socketOptions');
        return rqmPackage.connect(this.urls, { connectionOptions: socketOptions });
    }

//output of the server object
this.server  AmqpConnectionManager {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: 0,
  _channels: [],
  _currentUrl: 0,
  connectionOptions: { heartbeatIntervalInSeconds: 6000, reconnectTimeInSeconds: 10 },
  heartbeatIntervalInSeconds: 5,
  reconnectTimeInSeconds: 5,
  _findServers: [Function (anonymous)],
  _connectPromise: Promise { <pending> },
  [Symbol(kCapture)]: false
}

Expected behavior

pass the heartbeatIntervalInSeconds and reconnectTimeInSeconds as parameters when creating a connection.

Possible Solution

public createClient<T = any>(): T {
    const socketOptions = this.getOptionsProp(this.options, 'socketOptions');
    return rqmPackage.connect(this.urls, { 
        connectionOptions: socketOptions,
        heartbeatIntervalInSeconds: socketOptions.heartbeatIntervalInSeconds,
        reconnectTimeInSeconds: socketOptions.reconnectTimeInSeconds
    });
  }

Environment


Nest version: 7.6.0
amqp-connection-manager: "^3.2.2"

 
For Tooling issues:
- Node version: v14.16.0  
- Platform:Linux  

Others:

@alexreal1314 alexreal1314 added the needs triage This issue has not been looked into label Jun 28, 2021
@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

@alexreal1314
Copy link
Contributor Author

yes, I'll open a PR

@kamilmysliwiec
Copy link
Member

Let's track this here #7345

@luigi-13
Copy link

Hello,

maybe forgive my misunderstanding, but dont we have the same problem with the /microservices/client/client-rmq.js file ?

Indeed, with @nestjs/microservices@9.1.2 this working for my microservice app, the heartbeat is updated but not when using with ClientsModule/ClientProxy on another app with same version.

So

const queue: ClientProviderOptions = {
  ...rmqOptions,
  // injection token for our RabbitMQ client
  name: queueName,
  options: {
    ...rmqOptions.options,
    // actual RabbitMQ queue name
    queue: queueName,
    // require explicit acknowledgement of messages
    noAck: false,
    prefetchCount:200,
    queueOptions: {
      // setup the dead letter exchange to point to the default exchange
      deadLetterExchange: '',
      // all dead letters should be routed to our recoveryQueue
      deadLetterRoutingKey: recoveryQueue,
      // set message time to live to 4s
      messageTtl: 3600000,
    },
    socketOptions: {
      heartbeatIntervalInSeconds: 20,
      reconnectTimeInSeconds: 5,
    },
  },
  
};
const microservice = await app.connectMicroservice(queue);

heartbeat is updated on this microservice app.

But
ClientsModule.register([queue]) on another app not update the heartbeat for this connection

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

No branches or pull requests

3 participants