Class NtfyClient

java.lang.Object
io.github.pimak.ntfy.core.NtfyClient
All Implemented Interfaces:
AutoCloseable

public final class NtfyClient extends Object implements AutoCloseable
Generic, standalone ntfy notification client — the "send an arbitrary notification" surface, independent of AlertEngine's log-alert lifecycle. Builds its own HttpClient, NtfyPublisher, and AuthMode from the supplied NtfyConfig and publishes to that config's url/topic.

Not thread-lifecycle managed the way the engine is: construct it, call notify(java.lang.String, java.lang.String) as needed, and close() it to release the underlying HTTP client. Because it implements AutoCloseable, it can be managed with a try-with-resources block for guaranteed disposal. AutoCloseable does not mandate closing, so a long-lived, container-managed instance (e.g. a Spring/Quarkus bean) may be kept open for the application's lifetime — any IDE resource-leak inspection flagging such a bean is a false positive. Publishing never throws — every outcome is reported through the returned PublishResult.

  • Constructor Details

    • NtfyClient

      public NtfyClient(NtfyConfig config)
  • Method Details

    • notify

      public PublishResult notify(String title, String message)
      Publishes title/message to the configured topic with no Priority/ Tags headers. The configured clickUrl (if any) is sent as the Click header.
      Returns:
      the publish outcome; never throws
    • notify

      public PublishResult notify(String title, String message, String priority, String tags)
      Publishes title/message to the configured topic, forwarding priority and tags as ntfy's Priority and Tags headers (blank/null values send no corresponding header). The configured clickUrl and actions (if any) are sent as the Click/Actions headers.
      Returns:
      the publish outcome; never throws
    • notify

      public PublishResult notify(String title, String message, String priority, String tags, String click)
      Publishes title/message to the configured topic, forwarding priority, tags and click as ntfy's Priority, Tags and Click headers (blank/null values send no corresponding header). click overrides the configured clickUrl for this call; the configured actions (if any) are still sent as the Actions header.
      Returns:
      the publish outcome; never throws
    • notify

      public PublishResult notify(String title, String message, List<NtfyAction> actions)
      Publishes title/message to the configured topic with the given action buttons, serialized to ntfy's Actions header (ntfy caps a notification at three actions; extras and null elements are dropped). actions overrides the configured actions for this call; the configured clickUrl (if any) is still sent as the Click header.
      Returns:
      the publish outcome; never throws
    • close

      public void close()
      Releases the underlying HttpClient (Java 21+ deterministic shutdown). May be invoked automatically via a try-with-resources block, and is safe to call more than once.
      Specified by:
      close in interface AutoCloseable