Files
ProjectOctopus/server/src/main/java/io/wdd/pusher/example/StreamingExample.java
2024-04-23 11:45:32 +08:00

28 lines
900 B
Java

package io.wdd.pusher.example;
import io.wdd.pusher.core.exception.NtfyStreamingException;
import io.wdd.pusher.core.model.StreamRequest;
import io.wdd.pusher.core.stream.StreamingService;
public class StreamingExample {
public static void main(String[] args) throws NtfyStreamingException {
StreamRequest request = new StreamRequest();
request.setHost("ntfy.sh");
request.setTopic("test_ntfy2");
StreamingService streamingConnection = new StreamingService(request);
streamingConnection.setDataListener(data -> {
// Process the incoming data here
System.out.println("Received data: " + data);
});
// Start the streaming connection
streamingConnection.start();
// Keep the connection open and receive data indefinitely
// To stop the connection, call streamingConnection.stop()
}
}