Package io.github.pimak.ntfy.core
Class NtfyClient
java.lang.Object
io.github.pimak.ntfy.core.NtfyClient
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases the underlyingHttpClient(Java 21+ deterministic shutdown).Publishestitle/messageto the configured topic with noPriority/Tagsheaders.Publishestitle/messageto the configured topic, forwardingpriorityandtagsas ntfy'sPriorityandTagsheaders (blank/null values send no corresponding header).Publishestitle/messageto the configured topic, forwardingpriority,tagsandclickas ntfy'sPriority,TagsandClickheaders (blank/null values send no corresponding header).notify(String title, String message, List<NtfyAction> actions) Publishestitle/messageto the configured topic with the given action buttons, serialized to ntfy'sActionsheader (ntfy caps a notification at three actions; extras andnullelements are dropped).
-
Constructor Details
-
NtfyClient
-
-
Method Details
-
notify
Publishestitle/messageto the configured topic with noPriority/Tagsheaders. The configuredclickUrl(if any) is sent as theClickheader.- Returns:
- the publish outcome; never throws
-
notify
Publishestitle/messageto the configured topic, forwardingpriorityandtagsas ntfy'sPriorityandTagsheaders (blank/null values send no corresponding header). The configuredclickUrlandactions(if any) are sent as theClick/Actionsheaders.- Returns:
- the publish outcome; never throws
-
notify
public PublishResult notify(String title, String message, String priority, String tags, String click) Publishestitle/messageto the configured topic, forwardingpriority,tagsandclickas ntfy'sPriority,TagsandClickheaders (blank/null values send no corresponding header).clickoverrides the configuredclickUrlfor this call; the configuredactions(if any) are still sent as theActionsheader.- Returns:
- the publish outcome; never throws
-
notify
Publishestitle/messageto the configured topic with the given action buttons, serialized to ntfy'sActionsheader (ntfy caps a notification at three actions; extras andnullelements are dropped).actionsoverrides the configuredactionsfor this call; the configuredclickUrl(if any) is still sent as theClickheader.- Returns:
- the publish outcome; never throws
-
close
public void close()Releases the underlyingHttpClient(Java 21+ deterministic shutdown). May be invoked automatically via a try-with-resources block, and is safe to call more than once.- Specified by:
closein interfaceAutoCloseable
-