Class NtfyClientFactory

java.lang.Object
io.github.pimak.ntfy.micronaut.NtfyClientFactory

@Factory public class NtfyClientFactory extends Object
Exposes the injectable NtfyClient bean, built from the bound NtfyConfiguration.

Unconditional by design. The client is a plain HTTP publisher for ad-hoc notifications from application code; it does not touch a logging framework, so it is contributed whatever SLF4J backend the application binds and even when ntfy.url/ntfy.topic are unset (an inactive configuration simply publishes nothing). Only the appender install in NtfyLogbackInstaller is Logback-specific. The Spring starter originally gated its whole auto-configuration on Logback being present and lost the client bean along with the appender on a Log4j2 classpath; that mistake is not repeated here — no Logback type appears anywhere in this class or in the signatures the container introspects on it.

  • Constructor Details

    • NtfyClientFactory

      public NtfyClientFactory()
  • Method Details

    • ntfyClient

      @Singleton @Bean(preDestroy="close") public NtfyClient ntfyClient(NtfyConfiguration configuration)
      Builds the singleton NtfyClient.

      preDestroy = "close" hands the client's lifecycle to the container: NtfyClient is AutoCloseable and owns an async delivery worker, so the context shutdown must close it or the worker outlives the application.

      Two builder names deliberately differ from the configuration property names, mirroring the Spring starter: ntfy.actions maps onto NtfyConfig.Builder.actionsHeader(String) (the value is a raw ntfy Actions header, not a parsed action list) and ntfy.async maps onto NtfyConfig.Builder.asyncEnabled(boolean). A third, ntfy.include-mdc-keys, maps onto NtfyConfig.Builder.includeMdcKeysCsv(String) — the comma-separated form, since the property binds as a single String.

      Every bound property must be forwarded here. This method and NtfyLogbackInstaller are two independent apply sites for one configuration, so a key wired into only one of them produces a client whose config silently disagrees with the appender's — with nothing failing to announce it. include-mdc-keys was exactly that omission until it was added here; the warn-* level-routing keys are forwarded for the same reason.

      Parameters:
      configuration - the bound ntfy.* configuration
      Returns:
      a client bean the container closes on shutdown