Skip to content

Commit

Permalink
Added Pubsub support for Go, Java
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Yuknewicz <[email protected]>
  • Loading branch information
Paul Yuknewicz authored and Paul Yuknewicz committed Sep 4, 2023
1 parent 2fb9d15 commit 3dc9e44
Show file tree
Hide file tree
Showing 13 changed files with 338 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pub_sub/csharp/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The terminal console output should look similar to this:
== APP - order-processor == Subscriber received : Order { OrderId = 10 }
```

3. Stop and clean up application processes
2. Stop and clean up application processes

```bash
dapr stop -f .
Expand Down
61 changes: 60 additions & 1 deletion pub_sub/go/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,65 @@ This quickstart includes one publisher: Go client message generator `checkout`.

And one subscriber: Go subscriber `order-processor`.

## Run all apps with multi-app run template file:

This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications.

1. Open a new terminal window and run the multi app run template:

<!-- STEP
name: Run multi app run template
expected_stdout_lines:
- 'Started Dapr with app id "order-processor-http"'
- 'Started Dapr with app id "checkout-http"'
- '== APP - checkout-http == Published data: {"orderId":1}'
- '== APP - order-processor-http == Subscriber received: map[orderId:1]'
expected_stderr_lines:
output_match_mode: substring
background: true
sleep: 15
-->

```bash
dapr run -f .
```

The terminal console output should look similar to this:

```text
== APP - checkout-http == Published data: {"orderId":1}
== APP - order-processor-http == Subscriber received: {"orderId":1}
== APP - checkout-http == Published data: {"orderId":2}
== APP - order-processor-http == Subscriber received: {"orderId":2}
== APP - checkout-http == Published data: {"orderId":3}
== APP - order-processor-http == Subscriber received: {"orderId":3}
== APP - checkout-http == Published data: {"orderId":4}
== APP - order-processor-http == Subscriber received: {"orderId":4}
== APP - checkout-http == Published data: {"orderId":5}
== APP - order-processor-http == Subscriber received: {"orderId":5}
== APP - checkout-http == Published data: {"orderId":6}
== APP - order-processor-http == Subscriber received: {"orderId":6}
== APP - order-processor-http == Subscriber received: {"orderId":7}
== APP - checkout-http == Published data: {"orderId":7}
== APP - checkout-http == Published data: {"orderId":8}
== APP - order-processor-http == Subscriber received: {"orderId":8}
== APP - checkout-http == Published data: {"orderId":9}
== APP - order-processor-http == Subscriber received: {"orderId":9}
== APP - checkout-http == Published data: {"orderId":10}
== APP - order-processor-http == Subscriber received: {"orderId":10}
```

2. Stop and clean up application processes

```bash
dapr stop -f .
```
<!-- END_STEP -->

## Run a single app at a time with Dapr (Optional)

An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- dotnet run` commands. This next section covers how to do this.

### Run Go message subscriber with Dapr

1. Run the Go subscriber app with Dapr in the `order-processor` folder:
Expand All @@ -27,7 +86,7 @@ sleep: 15

```bash
cd ./order-processor
dapr run --app-port 6002 --app-id order-processor --app-protocol http --dapr-http-port 3501 --resources-path ../../../components -- go run .
dapr run --app-port 6003 --app-id order-processor --app-protocol http --dapr-http-port 3501 --resources-path ../../../components -- go run .
```

<!-- END_STEP -->
Expand Down
6 changes: 3 additions & 3 deletions pub_sub/go/http/dapr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ version: 1
common:
resourcesPath: ../../components/
apps:
- appDirPath: ./order-processor/
appID: order-processor
appPort: 6002
- appID: order-processor-http
appDirPath: ./order-processor/
appPort: 6003
command: ["go", "run", "."]
- appID: checkout-http
appDirPath: ./checkout/
Expand Down
59 changes: 59 additions & 0 deletions pub_sub/go/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,65 @@ This quickstart includes one publisher: Go client message generator `checkout`

And one subscriber: Go subscriber `order-processor`

## Run all apps with multi-app run template file:

This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications.

1. Open a new terminal window and run the multi app run template:

<!-- STEP
name: Run multi app run template
expected_stdout_lines:
- 'Started Dapr with app id "order-processor"'
- 'Started Dapr with app id "checkout-sdk"'
- '== APP - checkout-sdk == Published data: {"orderId":1}'
- '== APP - order-processor == Subscriber received: map[orderId:1]'
expected_stderr_lines:
output_match_mode: substring
background: true
sleep: 15
-->

```bash
dapr run -f .
```

The terminal console output should look similar to this:

```text
== APP - checkout-sdk == Published data: {"orderId":1}
== APP - order-processor == Subscriber received: map[orderId:1]
== APP - checkout-sdk == Published data: {"orderId":2}
== APP - order-processor == Subscriber received: map[orderId:2]
== APP - checkout-sdk == Published data: {"orderId":3}
== APP - order-processor == Subscriber received: map[orderId:3]
== APP - order-processor == Subscriber received: map[orderId:4]
== APP - checkout-sdk == Published data: {"orderId":4}
== APP - checkout-sdk == Published data: {"orderId":5}
== APP - order-processor == Subscriber received: map[orderId:5]
== APP - checkout-sdk == Published data: {"orderId":6}
== APP - order-processor == Subscriber received: map[orderId:6]
== APP - order-processor == Subscriber received: map[orderId:7]
== APP - checkout-sdk == Published data: {"orderId":7}
== APP - checkout-sdk == Published data: {"orderId":8}
== APP - order-processor == Subscriber received: map[orderId:8]
== APP - checkout-sdk == Published data: {"orderId":9}
== APP - order-processor == Subscriber received: map[orderId:9]
== APP - checkout-sdk == Published data: {"orderId":10}
== APP - order-processor == Subscriber received: map[orderId:10]
```

2. Stop and clean up application processes

```bash
dapr stop -f .
```
<!-- END_STEP -->

## Run a single app at a time with Dapr (Optional)

An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- dotnet run` commands. This next section covers how to do this.

### Run Go message subscriber with Dapr

1. Run the Go subscriber app with Dapr in the `order-processor` folder:
Expand Down
11 changes: 11 additions & 0 deletions pub_sub/go/sdk/dapr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 1
common:
resourcesPath: ../../components/
apps:
- appID: order-processor
appDirPath: ./order-processor/
appPort: 6005
command: ["go", "run", "."]
- appID: checkout-sdk
appDirPath: ./checkout/
command: ["go", "run", "."]
74 changes: 74 additions & 0 deletions pub_sub/java/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,80 @@ And one subscriber:
* [OpenJDK 11](https://jdk.java.net/11/)
* [Apache Maven](https://maven.apache.org/install.html) version 3.x.

## Run all apps with multi-app run template file:

This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications.

1. Install dependencies:

<!-- STEP
name: Install Node dependencies
-->
```bash
cd ./order-processor
mvn clean install
cd ..
cd ./checkout
mvn clean install
cd ..
```
<!-- END_STEP -->

2. Open a new terminal window and run the multi app run template:

<!-- STEP
name: Run multi app run template
expected_stdout_lines:
- 'Started Dapr with app id "order-processor-http"'
- 'Started Dapr with app id "checkout-http"'
- '== APP - checkout-sdk == Published data: Order { OrderId = 10 }'
- '== APP - order-processor == Subscriber received : Order { OrderId = 10 }'
expected_stderr_lines:
output_match_mode: substring
background: true
sleep: 15
-->

```bash
dapr run -f .
```

The terminal console output should look similar to this:

```text
== APP - order-processor-http == 2023-09-04 14:25:37.624 INFO 88784 --- [nio-8080-exec-1] c.s.c.OrderProcessingServiceController : Subscriber received: 1
== APP - checkout-http == 1175 [main] INFO com.service.CheckoutServiceApplication - Published data: 2
== APP - order-processor-http == 2023-09-04 14:25:38.558 INFO 88784 --- [nio-8080-exec-2] c.s.c.OrderProcessingServiceController : Subscriber received: 2
== APP - checkout-http == 2184 [main] INFO com.service.CheckoutServiceApplication - Published data: 3
== APP - order-processor-http == 2023-09-04 14:25:39.567 INFO 88784 --- [nio-8080-exec-3] c.s.c.OrderProcessingServiceController : Subscriber received: 3
== APP - checkout-http == 3195 [main] INFO com.service.CheckoutServiceApplication - Published data: 4
== APP - order-processor-http == 2023-09-04 14:25:40.578 INFO 88784 --- [nio-8080-exec-4] c.s.c.OrderProcessingServiceController : Subscriber received: 4
== APP - checkout-http == 4203 [main] INFO com.service.CheckoutServiceApplication - Published data: 5
== APP - order-processor-http == 2023-09-04 14:25:41.586 INFO 88784 --- [nio-8080-exec-5] c.s.c.OrderProcessingServiceController : Subscriber received: 5
== APP - checkout-http == 5215 [main] INFO com.service.CheckoutServiceApplication - Published data: 6
== APP - order-processor-http == 2023-09-04 14:25:42.600 INFO 88784 --- [nio-8080-exec-6] c.s.c.OrderProcessingServiceController : Subscriber received: 6
== APP - checkout-http == 6219 [main] INFO com.service.CheckoutServiceApplication - Published data: 7
== APP - order-processor-http == 2023-09-04 14:25:43.601 INFO 88784 --- [nio-8080-exec-7] c.s.c.OrderProcessingServiceController : Subscriber received: 7
== APP - checkout-http == 7224 [main] INFO com.service.CheckoutServiceApplication - Published data: 8
== APP - order-processor-http == 2023-09-04 14:25:44.607 INFO 88784 --- [nio-8080-exec-8] c.s.c.OrderProcessingServiceController : Subscriber received: 8
== APP - checkout-http == 8229 [main] INFO com.service.CheckoutServiceApplication - Published data: 9
== APP - order-processor-http == 2023-09-04 14:25:45.612 INFO 88784 --- [nio-8080-exec-9] c.s.c.OrderProcessingServiceController : Subscriber received: 9
== APP - checkout-http == 9237 [main] INFO com.service.CheckoutServiceApplication - Published data: 10
== APP - order-processor-http == 2023-09-04 14:25:46.620 INFO 88784 --- [io-8080-exec-10] c.s.c.OrderProcessingServiceController : Subscriber received: 10
```

3. Stop and clean up application processes

```bash
dapr stop -f .
```
<!-- END_STEP -->

## Run a single app at a time with Dapr (Optional)

An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- dotnet run` commands. This next section covers how to do this.


### Run Java message subscriber app with Dapr

1. Navigate to directory and install dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CheckoutServiceApplication {

public static void main(String[] args) throws InterruptedException, IOException {
String uri = DAPR_HOST + ":" + DAPR_HTTP_PORT + "/v1.0/publish/" + PUBSUB_NAME + "/" + TOPIC;
for (int i = 0; i <= 10; i++) {
for (int i = 1; i <= 10; i++) {
int orderId = i;
JSONObject obj = new JSONObject();
obj.put("orderId", orderId);
Expand All @@ -40,7 +40,7 @@ public static void main(String[] args) throws InterruptedException, IOException

HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
logger.info("Published data: {}", orderId);
TimeUnit.MILLISECONDS.sleep(3000);
TimeUnit.MILLISECONDS.sleep(1000);
}
}
}
11 changes: 11 additions & 0 deletions pub_sub/java/http/dapr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 1
common:
resourcesPath: ../../components/
apps:
- appID: order-processor-http
appDirPath: ./order-processor/target/
appPort: 8081
command: ["java", "-jar", "OrderProcessingService-0.0.1-SNAPSHOT.jar"]
- appID: checkout-http
appDirPath: ./checkout/target/
command: ["java", "-jar", "CheckoutService-0.0.1-SNAPSHOT.jar"]
74 changes: 74 additions & 0 deletions pub_sub/java/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,80 @@ And one subscriber:
* [OpenJDK 11](https://jdk.java.net/11/)
* [Apache Maven](https://maven.apache.org/install.html) version 3.x.

## Run all apps with multi-app run template file:

This section shows how to run both applications at once using [multi-app run template files](https://docs.dapr.io/developing-applications/local-development/multi-app-dapr-run/multi-app-overview/) with `dapr run -f .`. This enables to you test the interactions between multiple applications.

1. Install dependencies:

<!-- STEP
name: Install Node dependencies
-->
```bash
cd ./order-processor
mvn clean install
cd ..
cd ./checkout
mvn clean install
cd ..
```
<!-- END_STEP -->

2. Open a new terminal window and run the multi app run template:

<!-- STEP
name: Run multi app run template
expected_stdout_lines:
- 'Started Dapr with app id "order-processor-sdk"'
- 'Started Dapr with app id "checkout-sdk"'
- '== APP - checkout-sdk == Published data: Order { OrderId = 10 }'
- '== APP - order-processor == Subscriber received : Order { OrderId = 10 }'
expected_stderr_lines:
output_match_mode: substring
background: true
sleep: 15
-->

```bash
dapr run -f .
```

The terminal console output should look similar to this:

```text
== APP - checkout-sdk == 563 [main] INFO com.service.CheckoutServiceApplication - Published data: 1
== APP - order-processor-sdk == 2023-09-04 13:57:18.434 INFO 82828 --- [nio-8080-exec-3] c.s.c.OrderProcessingServiceController : Subscriber received: 1
== APP - checkout-sdk == 1576 [main] INFO com.service.CheckoutServiceApplication - Published data: 2
== APP - order-processor-sdk == 2023-09-04 13:57:19.419 INFO 82828 --- [nio-8080-exec-4] c.s.c.OrderProcessingServiceController : Subscriber received: 2
== APP - checkout-sdk == 2587 [main] INFO com.service.CheckoutServiceApplication - Published data: 3
== APP - order-processor-sdk == 2023-09-04 13:57:20.431 INFO 82828 --- [nio-8080-exec-5] c.s.c.OrderProcessingServiceController : Subscriber received: 3
== APP - checkout-sdk == 3602 [main] INFO com.service.CheckoutServiceApplication - Published data: 4
== APP - order-processor-sdk == 2023-09-04 13:57:21.447 INFO 82828 --- [nio-8080-exec-6] c.s.c.OrderProcessingServiceController : Subscriber received: 4
== APP - checkout-sdk == 4612 [main] INFO com.service.CheckoutServiceApplication - Published data: 5
== APP - order-processor-sdk == 2023-09-04 13:57:22.455 INFO 82828 --- [nio-8080-exec-7] c.s.c.OrderProcessingServiceController : Subscriber received: 5
== APP - checkout-sdk == 5624 [main] INFO com.service.CheckoutServiceApplication - Published data: 6
== APP - order-processor-sdk == 2023-09-04 13:57:23.468 INFO 82828 --- [nio-8080-exec-8] c.s.c.OrderProcessingServiceController : Subscriber received: 6
== APP - checkout-sdk == 6631 [main] INFO com.service.CheckoutServiceApplication - Published data: 7
== APP - order-processor-sdk == 2023-09-04 13:57:24.474 INFO 82828 --- [nio-8080-exec-9] c.s.c.OrderProcessingServiceController : Subscriber received: 7
== APP - checkout-sdk == 7643 [main] INFO com.service.CheckoutServiceApplication - Published data: 8
== APP - order-processor-sdk == 2023-09-04 13:57:25.487 INFO 82828 --- [io-8080-exec-10] c.s.c.OrderProcessingServiceController : Subscriber received: 8
== APP - checkout-sdk == 8649 [main] INFO com.service.CheckoutServiceApplication - Published data: 9
== APP - order-processor-sdk == 2023-09-04 13:57:26.492 INFO 82828 --- [nio-8080-exec-2] c.s.c.OrderProcessingServiceController : Subscriber received: 9
== APP - checkout-sdk == 9662 [main] INFO com.service.CheckoutServiceApplication - Published data: 10
== APP - order-processor-sdk == 2023-09-04 13:57:27.504 INFO 82828 --- [nio-8080-exec-1] c.s.c.OrderProcessingServiceController : Subscriber received: 10
```

3. Stop and clean up application processes

```bash
dapr stop -f .
```
<!-- END_STEP -->

## Run a single app at a time with Dapr (Optional)

An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple `dapr run .. -- dotnet run` commands. This next section covers how to do this.

### Run Java message subscriber app with Dapr

1. Navigate to directory and install dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void main(String[] args) throws InterruptedException{
String PUBSUB_NAME = "orderpubsub";
DaprClient client = new DaprClientBuilder().build();

for (int i = 0; i <= 10; i++) {
for (int i = 1; i <= 10; i++) {
int orderId = i;
Order order = new Order(orderId);

Expand All @@ -26,7 +26,7 @@ public static void main(String[] args) throws InterruptedException{
TOPIC_NAME,
order).block();
logger.info("Published data: " + order.getOrderId());
TimeUnit.MILLISECONDS.sleep(5000);
TimeUnit.MILLISECONDS.sleep(1000);
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions pub_sub/java/sdk/dapr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 1
common:
resourcesPath: ../../components/
apps:
- appID: order-processor-sdk
appDirPath: ./order-processor/target/
appPort: 8080
command: ["java", "-jar", "OrderProcessingService-0.0.1-SNAPSHOT.jar"]
- appID: checkout-sdk
appDirPath: ./checkout/target/
command: ["java", "-jar", "CheckoutService-0.0.1-SNAPSHOT.jar"]
Loading

0 comments on commit 3dc9e44

Please sign in to comment.