@@ -65,6 +65,14 @@ Abstraction over a WebSocket connection to a relay.
6565``` java
6666< T extends BaseMessage > List<String > send(T eventMessage) throws IOException
6767List<String > send(String json) throws IOException
68+ AutoCloseable subscribe(String requestJson,
69+ Consumer<String > messageListener,
70+ Consumer<Throwable > errorListener,
71+ Runnable closeListener) throws IOException
72+ < T extends BaseMessage > AutoCloseable subscribe(T eventMessage,
73+ Consumer<String > messageListener,
74+ Consumer<Throwable > errorListener,
75+ Runnable closeListener) throws IOException
6876void close() throws IOException
6977```
7078
@@ -75,6 +83,10 @@ Spring `TextWebSocketHandler` based implementation of `WebSocketClientIF`.
7583public StandardWebSocketClient(String relayUri)
7684public < T extends BaseMessage > List<String > send(T eventMessage) throws IOException
7785public List<String > send(String json) throws IOException
86+ public AutoCloseable subscribe(String requestJson,
87+ Consumer<String > messageListener,
88+ Consumer<Throwable > errorListener,
89+ Runnable closeListener) throws IOException
7890public void close() throws IOException
7991```
8092
@@ -84,6 +96,14 @@ Wrapper that adds retry logic around a `WebSocketClientIF`.
8496``` java
8597public List<String > send(BaseMessage eventMessage) throws IOException
8698public List<String > send(String json) throws IOException
99+ public AutoCloseable subscribe(BaseMessage requestMessage,
100+ Consumer<String > messageListener,
101+ Consumer<Throwable > errorListener,
102+ Runnable closeListener) throws IOException
103+ public AutoCloseable subscribe(String json,
104+ Consumer<String > messageListener,
105+ Consumer<Throwable > errorListener,
106+ Runnable closeListener) throws IOException
87107public List<String > recover(IOException ex, String json) throws IOException
88108public void close() throws IOException
89109```
@@ -95,12 +115,24 @@ High level client coordinating multiple relay connections and signing.
95115public NostrIF setRelays(Map<String ,String > relays)
96116public List<String > sendEvent(IEvent event)
97117public List<String > sendRequest(List<Filters > filters, String subscriptionId)
118+ public AutoCloseable subscribe(Filters filters, String subscriptionId, Consumer<String > listener)
119+ public AutoCloseable subscribe(Filters filters,
120+ String subscriptionId,
121+ Consumer<String > listener,
122+ Consumer<Throwable > errorListener)
98123public NostrIF sign(Identity identity, ISignable signable)
99124public boolean verify(GenericEvent event)
100125public Map<String ,String > getRelays()
101126public void close()
102127```
103128
129+ ` subscribe ` opens a dedicated WebSocket per relay, returns immediately, and streams raw relay
130+ messages to the provided listener. The returned ` AutoCloseable ` sends a ` CLOSE ` command and releases
131+ resources when invoked. Because callbacks execute on the WebSocket thread, delegate heavy
132+ processing to another executor to avoid stalling inbound traffic. The
133+ [ ` SpringSubscriptionExample ` ] ( ../../nostr-java-examples/src/main/java/nostr/examples/SpringSubscriptionExample.java )
134+ demonstrates how to open a subscription and close it after a fixed duration.
135+
104136### Configuration
105137- ` RetryConfig ` – enables Spring Retry support.
106138- ` RelaysProperties ` – maps relay names to URLs via configuration properties.
0 commit comments