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

Add possibility of catch errors when message broker is down #11913

Open
1 task done
vahidvdn opened this issue Jun 27, 2023 · 6 comments
Open
1 task done

Add possibility of catch errors when message broker is down #11913

vahidvdn opened this issue Jun 27, 2023 · 6 comments
Labels
priority: medium (3) Medium priority issue that needs to be resolved scope: microservices type: enhancement 🐺

Comments

@vahidvdn
Copy link

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

In express based applications, we can catch the broker error as following:

mqttClient.on('reconnect', () => {
    console.log('reconnecting...');
    // notify to sentry
})

While it seems this is not possible in NestJS.

Describe the solution you'd like

I tested the global filters but didn't work. Similar way or any other way could be very nice.

Teachability, documentation, adoption, migration strategy

No idea for now

What is the motivation / use case for changing the behavior?

As I mentioned, I need to send a message to Sentry and log in my system, whenever the broker is down.

@vahidvdn vahidvdn added needs triage This issue has not been looked into type: enhancement 🐺 labels Jun 27, 2023
@kamilmysliwiec
Copy link
Member

kamilmysliwiec commented Jun 28, 2023

So far the only way to accomplish this is to use a custom strategy that extends the built-in transporter. Example:

import { ServerMqtt } from '@nestjs/microservices';
import { MqttClient } from '@nestjs/microservices/external/mqtt-client.interface';

class MyCustomStrategy extends ServerMqtt {
  bindEvents(mqttClient: MqttClient) {
    super.bindEvents(mqttClient);
    mqttClient.on('reconnect', () => console.log('Reconnecting...'));
  }
}

// and later
const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
  strategy: new MyCustomStrategy({
    url: 'mqtt://0.0.0.0:1883',
  }),
});

@vahidvdn
Copy link
Author

vahidvdn commented Jun 28, 2023

Thanks, @kamilmysliwiec
I found something regarding bindEvents in the source code of nest, but was not sure how to use it.

But it would be great if it were mentioned in the docs.

@micalevisk micalevisk removed the needs triage This issue has not been looked into label Jun 29, 2023
@micalevisk
Copy link
Member

micalevisk commented Jun 29, 2023

@vahidvdn feel free to propose an improvement to the docs here: https://github.com/nestjs/docs.nestjs.com via pull request

@vahidvdn
Copy link
Author

@micalevisk I will do it asap. I have a section in my mind in the overview menu right after handling timeouts (maybe called handling events) and refer to Custom transporters menu for more info. Does that work for you?

@kamilmysliwiec
Copy link
Member

Instead of creating a new page, we should add a dedicated section to each transporter as the implementation can vary considerably

@vahidvdn
Copy link
Author

@kamilmysliwiec That makes perfect sense to me. But it would be great if you could mention the overall solution in the overview menu regarding bindEvents. Then based on the underlying package used (e.g. mqtt.js), developers can either go to the dedicated menu for that specific transporter or use the mqtt documents (or their knowledge about that) to see which events is present.

By the way, it was just an idea. I will try to add them to the mqtt secotion at least, and adding some overall information to the overview menu is your call. Thanks

@kamilmysliwiec kamilmysliwiec added scope: microservices priority: medium (3) Medium priority issue that needs to be resolved labels Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium (3) Medium priority issue that needs to be resolved scope: microservices type: enhancement 🐺
Projects
None yet
Development

No branches or pull requests

3 participants