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
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
+
5
+
Visit [this](https://docs.dapr.io/developing-applications/building-blocks/pubsub/pubsub-overview/) link for more information about Dapr and Pub-Sub.
6
+
7
+
## Pub-Sub Sample using the Java-SDK
8
+
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).
*[Apache Maven](https://maven.apache.org/install.html) version 3.x.
18
+
19
+
### Checking out the code
20
+
21
+
Clone this repository:
22
+
23
+
```sh
24
+
git clone https://github.com/dapr/java-sdk.git
25
+
cd java-sdk
26
+
```
27
+
28
+
Then build the Maven project:
29
+
30
+
```sh
31
+
# make sure you are in the `java-sdk` directory.
32
+
mvn install
33
+
```
34
+
35
+
Then get into the examples directory:
36
+
37
+
```sh
38
+
cd examples
39
+
```
40
+
### Initialize Dapr
41
+
42
+
Run `dapr init` to initialize Dapr in Self-Hosted Mode if it's not already initialized.
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.
47
+
48
+
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.
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 subscriber provides an implementation of the `SubscriptionListener` interface, receiving a `Subscription` object. The `Subscription` object implements the `Closeable` interface and the `close()` method must be used to stop the subscription.
*[Apache Maven](https://maven.apache.org/install.html) version 3.x.
21
21
22
22
### Checking out the code
@@ -54,8 +54,8 @@ Those examples contain the following workflow patterns:
54
54
5.[Sub-workflow Pattern](#sub-workflow-pattern)
55
55
56
56
### Chaining Pattern
57
-
In the chaining pattern, a sequence of activities executes in a specific order.
58
-
In this pattern, the output of one activity is applied to the input of another activity.
57
+
In the chaining pattern, a sequence of activities executes in a specific order.
58
+
In this pattern, the output of one activity is applied to the input of another activity.
59
59
The chaining pattern is useful when you need to execute a sequence of activities in a specific order.
60
60
61
61
The first Java class is `DemoChainWorker`. Its job is to register an implementation of `DemoChainWorkflow` in Dapr's workflow runtime engine. In the `DemoChainWorker.java` file, you will find the `DemoChainWorker` class and the `main` method. See the code snippet below:
@@ -149,6 +149,7 @@ Execute the following script in order to run DemoChainWorker:
0 commit comments