Open vahidvdn opened 1 year ago
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',
}),
});
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.
@vahidvdn feel free to propose an improvement to the docs here: https://github.com/nestjs/docs.nestjs.com via pull request
@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?
Instead of creating a new page, we should add a dedicated section to each transporter as the implementation can vary considerably
@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
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
In express based applications, we can catch the broker error as following:
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.