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

Event connection listeners using mqttClient automatically generated using by micronaut #422

Open
tomgeek27 opened this issue Jun 28, 2024 · 0 comments
Labels
info: good first issue Good for newcomers

Comments

@tomgeek27
Copy link

Feature description

I'm defining a subscriber using @MqttSubscriber and therefore I can only configure it by the application.yml file. The problem is that some configurations are limited, for example event connection listeners.

It would be interesting to have a way to define a custom listener related to connection events using the MqttClient injectable by micronaut. For instance, I would like to log something when the client connects to or disconnects from the broker.

This could be a way to implement but due to immutable list it's not possible to add elements to the connected/disconnected listeners list:

@Slf4j
@Singleton
public class StartupListener implements ApplicationEventListener<ApplicationStartupEvent> {

  @Inject
  MqttClient mqttClient;

  @Override
  public void onApplicationEvent(ApplicationStartupEvent event) {
    mqttClient.getConfig().getConnectedListeners().add(
            mqttClientConnectedContext -> log.debug("LOGGING SOMETHING USEFUL...")
    );

    log.debug("Starting up service");
  }
}
@graemerocher graemerocher added the info: good first issue Good for newcomers label Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info: good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants