You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adding raw event subscription alongside CloudEvent subscription (#1617)
* Adding raw event subscription.
Signed-off-by: Artur Ciocanu <artur.ciocanu@gmail.com>
* Use proper method overloads for subscribeToEvents()
Signed-off-by: Artur Ciocanu <artur.ciocanu@gmail.com>
* Updating the examples to use the latest changes.
Signed-off-by: Artur Ciocanu <artur.ciocanu@gmail.com>
* FIx CI failures
Signed-off-by: Artur Ciocanu <artur.ciocanu@gmail.com>
* FIx CI failures, take 2
Signed-off-by: Artur Ciocanu <artur.ciocanu@gmail.com>
---------
Signed-off-by: Artur Ciocanu <artur.ciocanu@gmail.com>
Copy file name to clipboardExpand all lines: examples/src/main/java/io/dapr/examples/pubsub/stream/README.md
+61-20Lines changed: 61 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
In this sample, we'll create a publisher and a subscriber java applications using Dapr, based on the publish-subscribe pattern. The publisher will generate messages of a specific topic, while a subscriber will listen for messages of a specific topic via a bi-directional stream. All is abstracted by the SDK. See the [Dapr Pub-Sub docs](https://docs.dapr.io/developing-applications/building-blocks/pubsub/) to understand when this pattern might be a good choice for your software architecture.
4
4
5
5
Visit [this](https://docs.dapr.io/developing-applications/building-blocks/pubsub/pubsub-overview/) link for more information about Dapr and Pub-Sub.
6
-
6
+
7
7
## Pub-Sub Sample using the Java-SDK
8
8
9
9
This sample shows how the subscription to events no longer requires the application to listen to an HTTP or gRPC port. This example uses Redis Streams (enabled in Redis versions => 5).
@@ -41,45 +41,80 @@ cd examples
41
41
42
42
Run `dapr init` to initialize Dapr in Self-Hosted Mode if it's not already initialized.
43
43
44
-
### Running the subscriber
45
-
46
-
The subscriber uses the `DaprPreviewClient` interface to use a new feature where events are subscribed via a streaming and processed via a callback interface.
44
+
## Running the Subscriber
47
45
46
+
The subscriber uses the `DaprPreviewClient` interface to subscribe to events via streaming and process them using reactive operators.
48
47
48
+
The SDK provides two ways to subscribe to events:
49
49
50
-
The publisher is a simple Java application with a main method that uses the Dapr gRPC Client to publish 10 messages to a specific topic.
50
+
### Option 1: Raw Data Subscription
51
51
52
-
In the `Subscriber.java` file, you will find the `Subscriber` class, containing the main method. The main method declares a `DaprPreviewClient` using the `DaprClientBuilder` class. When invoking `subscribeToEvents`, the method returns a `Flux<CloudEvent<T>>` that can be processed using reactive operators like `doOnNext()` for event handling and `doOnError()` for error handling. The example uses `blockLast()`to keep the subscriber running indefinitely. For production use cases requiring explicit subscription lifecycle control, you can use `.subscribe()` which returns a `Disposable` that can be disposed via `disposable.dispose()`.
52
+
Use `TypeRef.STRING` (or any other type) to receive the deserialized message data directly:
The examples use `blockLast()` to keep the subscriber running indefinitely. For production use cases requiring explicit subscription lifecycle control, you can use `.subscribe()` which returns a `Disposable` that can be disposed via `disposable.dispose()`.
114
+
115
+
## Running the Examples
116
+
117
+
Execute the following command to run the raw data Subscriber example:
83
118
84
119
<!-- STEP
85
120
name: Run Subscriber
@@ -97,6 +132,12 @@ dapr run --resources-path ./components/pubsub --app-id subscriber -- java -jar t
0 commit comments