diff --git a/examples/.vscode/launch.json b/examples/.vscode/launch.json new file mode 100644 index 000000000..a782a8810 --- /dev/null +++ b/examples/.vscode/launch.json @@ -0,0 +1,96 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "java", + "name": "Debug (Launch) - Current File", + "request": "launch", + "mainClass": "${file}" + }, + { + "type": "java", + "name": "Debug (Launch)-DemoActorClient", + "request": "launch", + "mainClass": "io.dapr.examples.actors.http.DemoActorClient", + "projectName": "dapr-sdk-examples" + }, + { + "type": "java", + "name": "Debug (Launch)-DemoActorService", + "request": "launch", + "mainClass": "io.dapr.examples.actors.http.DemoActorService", + "projectName": "dapr-sdk-examples", + "args": "-port=3000" + }, + { + "type": "java", + "name": "Debug (Launch)-InputBindingExample", + "request": "launch", + "mainClass": "io.dapr.examples.bindings.http.InputBindingExample", + "projectName": "dapr-sdk-examples", + "args": "-port=3000" + }, + { + "type": "java", + "name": "Debug (Launch)-OutputBindingExample", + "request": "launch", + "mainClass": "io.dapr.examples.bindings.http.OutputBindingExample", + "projectName": "dapr-sdk-examples" + }, + { + "type": "java", + "name": "Debug (Launch)-HelloWorldClient", + "request": "launch", + "mainClass": "io.dapr.examples.invoke.grpc.HelloWorldClient", + "projectName": "dapr-sdk-examples" + }, + { + "type": "java", + "name": "Debug (Launch)-HelloWorldService", + "request": "launch", + "mainClass": "io.dapr.examples.invoke.grpc.HelloWorldService", + "projectName": "dapr-sdk-examples", + "args": "-port=5000" + }, + { + "type": "java", + "name": "Debug (Launch)-DemoService", + "request": "launch", + "mainClass": "io.dapr.examples.invoke.http.DemoService", + "projectName": "dapr-sdk-examples", + "args": "-port=3000" + }, + { + "type": "java", + "name": "Debug (Launch)-InvokeClient", + "request": "launch", + "mainClass": "io.dapr.examples.invoke.http.InvokeClient", + "projectName": "dapr-sdk-examples" + }, + { + "type": "java", + "name": "Debug (Launch)-Publisher", + "request": "launch", + "mainClass": "io.dapr.examples.pubsub.http.Publisher", + "projectName": "dapr-sdk-examples" + }, + { + "type": "java", + "name": "Debug (Launch)-Subscriber", + "request": "launch", + "mainClass": "io.dapr.examples.pubsub.http.Subscriber", + "projectName": "dapr-sdk-examples", + "args": "-port=3000" + }, + { + "type": "java", + "name": "Debug (Launch)-StateClient", + "request": "launch", + "mainClass": "io.dapr.examples.state.StateClient", + "projectName": "dapr-sdk-examples" + } + ] +} \ No newline at end of file diff --git a/examples/src/main/java/io/dapr/examples/actors/http/README.md b/examples/src/main/java/io/dapr/examples/actors/http/README.md index a9b0897a1..43d8ec5cd 100644 --- a/examples/src/main/java/io/dapr/examples/actors/http/README.md +++ b/examples/src/main/java/io/dapr/examples/actors/http/README.md @@ -55,7 +55,7 @@ public class DemoActorService { This application uses `ActorRuntime.getInstance().registerActor()` in order to register `DemoActorImpl` as an actor in the Dapr Actor runtime. Internally, it is using `DefaultObjectSerializer` for two properties: `objectSerializer` is for Dapr's sent and received objects, and `stateSerializer` is for objects to be persisted. -`DaprApplication.start()` method will run the Spring Boot [DaprApplication](../../../springboot/DaprApplication.java), which registers the Dapr Spring Boot controller [DaprController](../../springboot/DaprController.java). This controller contains all Actor methods implemented as endpoints. The Dapr's sidecar will call into the controller. +`DaprApplication.start()` method will run the Spring Boot [DaprApplication](../../../springboot/DaprApplication.java), which registers the Dapr Spring Boot controller [DaprController](../../../springboot/DaprController.java). This controller contains all Actor methods implemented as endpoints. The Dapr's sidecar will call into the controller. See [DemoActorImpl](DemoActorImpl.java) for details on the implementation of an actor: ```java @@ -105,7 +105,37 @@ An actor inherits from `AbstractActor` and implements the constructor to pass th Now, execute the following script in order to run DemoActorService: ```sh cd to [repo-root] -dapr run --app-id demoactorservice --app-port 3000 --port 3005 -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.actors.http.DemoActorService -D exec.args="-p 3000" +dapr run --app-id demoactorservice --app-port 3000 --port 3005 -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.actors.http.DemoActorService -Dexec.args="-p 3000" +``` + +### Debugging the Demo actor service + +If you want to debug the actor service, you have to make sure to provide the port as an argument. + +For VSCode you can find a sample launch.json which includes: +```json +... +{ + "type": "java", + "name": "Debug (Launch)-DemoActorService", + "request": "launch", + "mainClass": "io.dapr.examples.actors.http.DemoActorService", + "projectName": "dapr-sdk-examples", + "args": "-port=3000" +}, +... +``` + +Use the following commands to run the Dapr sidecar. + +For Linux and MacOS: +```sh +dapr run --app-id demoactorservice --app-port 3000 --port 3005 --grpc-port 5001 -- cat +``` + +For Windows: +```sh +dapr run --app-id demoactorservice --app-port 3000 --port 3005 --grpc-port 5001 -- waitfor FOREVER ``` ### Running the Actor client @@ -164,7 +194,7 @@ Use the follow command to execute the DemoActorClient: ```sh cd to [repo-root] -dapr run --app-id demoactorclient --port 3006 -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.actors.http.DemoActorClient +dapr run --app-id demoactorclient --port 3006 -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.actors.http.DemoActorClient ``` Once running, the `DemoActorClient` logs will start displaying the different steps: diff --git a/examples/src/main/java/io/dapr/examples/bindings/http/InputBindingExample.java b/examples/src/main/java/io/dapr/examples/bindings/http/InputBindingExample.java index 181bd2177..ed73e2ea6 100644 --- a/examples/src/main/java/io/dapr/examples/bindings/http/InputBindingExample.java +++ b/examples/src/main/java/io/dapr/examples/bindings/http/InputBindingExample.java @@ -18,7 +18,7 @@ import org.apache.commons.cli.Options; * 2. cd to [repo-root]/examples * 3. Run : * dapr run --app-id inputbinding --app-port 3000 --port 3005 \ - * -- mvn exec:java -D exec.mainClass=io.dapr.examples.bindings.http.InputBindingExample -D exec.args="-p 3000" + * -- mvn exec:java -Dexec.mainClass=io.dapr.examples.bindings.http.InputBindingExample -Dexec.args="-p 3000" */ public class InputBindingExample { diff --git a/examples/src/main/java/io/dapr/examples/bindings/http/OutputBindingExample.java b/examples/src/main/java/io/dapr/examples/bindings/http/OutputBindingExample.java index 37fd4b49a..5816e43da 100644 --- a/examples/src/main/java/io/dapr/examples/bindings/http/OutputBindingExample.java +++ b/examples/src/main/java/io/dapr/examples/bindings/http/OutputBindingExample.java @@ -15,7 +15,7 @@ import io.dapr.client.DaprClientBuilder; * 2. cd to [repo-root]/examples * 3. Run the program: * dapr run --app-id outputbinding --port 3006 \ - * -- mvn exec:java -D exec.mainClass=io.dapr.examples.bindings.http.OutputBindingExample + * -- mvn exec:java -Dexec.mainClass=io.dapr.examples.bindings.http.OutputBindingExample */ public class OutputBindingExample { diff --git a/examples/src/main/java/io/dapr/examples/bindings/http/README.md b/examples/src/main/java/io/dapr/examples/bindings/http/README.md index 9b96bf830..8db200b18 100644 --- a/examples/src/main/java/io/dapr/examples/bindings/http/README.md +++ b/examples/src/main/java/io/dapr/examples/bindings/http/README.md @@ -89,7 +89,37 @@ public class InputBindingController { Execute the follow script in order to run the Input Binding example: ```sh cd to [repo-root]/examples -dapr run --app-id inputbinding --app-port 3000 --port 3005 -- mvn exec:java -D exec.mainClass=io.dapr.examples.bindings.http.InputBindingExample -D exec.args="-p 3000" +dapr run --app-id inputbinding --app-port 3000 --port 3005 -- mvn exec:java -Dexec.mainClass=io.dapr.examples.bindings.http.InputBindingExample -Dexec.args="-p 3000" +``` + +### Debugging the Input binding sample + +If you want to debug the `InputBindingExample`, you have to make sure to provide the port as an argument. + +For VSCode you can find a sample launch.json which includes: +```json +... +{ + "type": "java", + "name": "Debug (Launch)-InputBindingExample", + "request": "launch", + "mainClass": "io.dapr.examples.bindings.http.InputBindingExample", + "projectName": "dapr-sdk-examples", + "args": "-port=3000" +}, +... +``` + +Use the following commands to run the Dapr sidecar. + +For Linux and MacOS: +```sh +dapr run --app-id inputbinding --app-port 3000 --port 3005 --grpc-port 5001 -- cat +``` + +For Windows: +```sh +dapr run --app-id inputbinding --app-port 3000 --port 3005 --grpc-port 5001 -- waitfor FOREVER ``` ### Running the Output binding sample @@ -123,7 +153,7 @@ Use the follow command to execute the Output Binding example: ```sh cd to [repo-root]/examples -dapr run --app-id outputbinding --port 3006 -- mvn exec:java -D exec.mainClass=io.dapr.examples.bindings.http.OutputBindingExample +dapr run --app-id outputbinding --port 3006 -- mvn exec:java -Dexec.mainClass=io.dapr.examples.bindings.http.OutputBindingExample ``` Once running, the OutputBindingExample should print the output as follows: diff --git a/examples/src/main/java/io/dapr/examples/invoke/grpc/HelloWorldClient.java b/examples/src/main/java/io/dapr/examples/invoke/grpc/HelloWorldClient.java index 728e91824..545e10faa 100644 --- a/examples/src/main/java/io/dapr/examples/invoke/grpc/HelloWorldClient.java +++ b/examples/src/main/java/io/dapr/examples/invoke/grpc/HelloWorldClient.java @@ -13,7 +13,7 @@ import io.dapr.client.domain.Verb; * 1. Build and install jars: * mvn clean install * 2. Send messages to the server: - * dapr run -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.invoke.grpc.HelloWorldClient + * dapr run -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.invoke.grpc.HelloWorldClient */ public class HelloWorldClient { diff --git a/examples/src/main/java/io/dapr/examples/invoke/grpc/HelloWorldService.java b/examples/src/main/java/io/dapr/examples/invoke/grpc/HelloWorldService.java index 6a0fd8419..bc54c2fba 100644 --- a/examples/src/main/java/io/dapr/examples/invoke/grpc/HelloWorldService.java +++ b/examples/src/main/java/io/dapr/examples/invoke/grpc/HelloWorldService.java @@ -30,8 +30,8 @@ import static io.dapr.examples.DaprExamplesProtos.SayResponse; * mvn clean install * 2. Run in server mode: * dapr run --app-id hellogrpc --app-port 5000 --protocol grpc \ - * -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.invoke.grpc.HelloWorldService \ - * -D exec.args="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5009" + * -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.invoke.grpc.HelloWorldService \ + * -Dexec.args="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5009" */ public class HelloWorldService { diff --git a/examples/src/main/java/io/dapr/examples/invoke/grpc/README.md b/examples/src/main/java/io/dapr/examples/invoke/grpc/README.md index a25426560..5496a181a 100644 --- a/examples/src/main/java/io/dapr/examples/invoke/grpc/README.md +++ b/examples/src/main/java/io/dapr/examples/invoke/grpc/README.md @@ -26,7 +26,7 @@ mvn install ### Running the example's service -The first component is the service. It has a simple API with the `Say` method. This method will print out each message received from the client. The proto file below contains the description of the HelloWorld service found in the `./proto/examples/helloworld.proto` file: +The first component is the service. It has a simple API with the `say` method. This method will print out each message received from the client. The proto file below contains the description of the HelloWorld service found in the `./examples/proto/helloworld.proto` file: ```text service HelloWorld { @@ -48,19 +48,16 @@ private static class GrpcHelloWorldDaprService extends DaprClientGrpc.DaprClient ///... @Override public void onInvoke(DaprClientProtos.InvokeEnvelope request, StreamObserver responseObserver) { - try { - if ("say".equals(request.getMethod())) { - // IMPORTANT: do not use Any.unpack(), use Type.ParseFrom() instead. - SayRequest sayRequest = SayRequest.parseFrom(request.getData().getValue()); - SayResponse sayResponse = this.say(sayRequest); - responseObserver.onNext(Any.pack(sayResponse)); - } - } catch (InvalidProtocolBufferException e) { - e.printStackTrace(); - responseObserver.onError(e); - } finally { - responseObserver.onCompleted(); + try { + if ("say".equals(request.getMethod())) { + SayRequest sayRequest = + SayRequest.newBuilder().setMessage(request.getData().getValue().toStringUtf8()).build(); + SayResponse sayResponse = this.say(sayRequest); + responseObserver.onNext(Any.pack(sayResponse)); } + } finally { + responseObserver.onCompleted(); + } } ///... } @@ -70,11 +67,41 @@ In the `GrpcHelloWorldDaprService` class, the `onInvoke` method is the most impo Now run the service code: ```sh -dapr run --app-id hellogrpc --app-port 5000 --protocol grpc -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.invoke.grpc.HelloWorldService -D exec.args="-p 5000" +dapr run --app-id hellogrpc --app-port 5000 --protocol grpc -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.invoke.grpc.HelloWorldService -Dexec.args="-p 5000" ``` The `app-id` argument is used to identify this service in Dapr's runtime. The `app-port` determines which port Dapr's runtime should call into this service. The `protocol` argument informs Dapr which protocol it should use to invoke the application: `grpc` or `http`(default). +### Debugging the example's service + +If you want to debug the `HelloWorldService`, you have to make sure to provide the port as an argument. + +For VSCode you can find a sample launch.json which includes: +```json +... +{ + "type": "java", + "name": "Debug (Launch)-HelloWorldService", + "request": "launch", + "mainClass": "io.dapr.examples.invoke.grpc.HelloWorldService", + "projectName": "dapr-sdk-examples", + "args": "-port=5000" +}, +... +``` + +Use the following commands to run the Dapr sidecar. + +For Linux and MacOS: +```sh +dapr run --app-id hellogrpc --app-port 5000 --protocol grpc --port 3005 --grpc-port 5001 -- cat +``` + +For Windows: +```sh +dapr run --app-id hellogrpc --app-port 5000 --protocol grpc --port 3005 --grpc-port 5001 -- waitfor FOREVER +``` + ### Running the example's client The other component is the client. It will send one message per second to the service via Dapr's invoke API using Dapr's SDK. Open the `HelloWorldClient.java` file, it uses the Dapr's Java SDK to invoke the `say` method on the service above: @@ -103,14 +130,14 @@ private static class HelloWorldClient { } ``` -First, it creates an instance of `DaprClient` via `DaprClientBuilder`. The protocol used by DaprClient is transparent to the application. The HTTP and GRPC ports used by Dapr's sidecar are automatically chosen and exported as environment variables: `DAPR_HTTP_PORT` and `DAPR_GRPC_PORT`. Dapr's Java SDK references these environment variables when communicating to Dapr's sidecar. +First, it creates an instance of `DaprClient` via `DaprClientBuilder`. The protocol used by DaprClient can be set with the JVM's system property `dapr.grpc.enabled` or environment variable `DAPR_GRPC_ENABLED`. If both are not set, the default is to use HTTP. The HTTP and GRPC ports used by Dapr's sidecar are automatically chosen and exported as environment variables to the app: `DAPR_HTTP_PORT` and `DAPR_GRPC_PORT`. Dapr's Java SDK references these environment variables when communicating to Dapr's sidecar. Finally, it will go through in an infinite loop and invoke the `say` method every second. Notice the use of `block()` on the return from `invokeService` - it is required to actually make the service invocation via a [Mono](https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Mono.html) object. Finally, open a new command line terminal and run the client code to send some messages. ```sh -dapr run -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.invoke.grpc.HelloWorldClient +dapr run -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.invoke.grpc.HelloWorldClient ``` Once the messages are sent, use `CTRL+C` to exit Dapr. diff --git a/examples/src/main/java/io/dapr/examples/invoke/http/DemoService.java b/examples/src/main/java/io/dapr/examples/invoke/http/DemoService.java index 2d505bff3..e1394dc6a 100644 --- a/examples/src/main/java/io/dapr/examples/invoke/http/DemoService.java +++ b/examples/src/main/java/io/dapr/examples/invoke/http/DemoService.java @@ -16,7 +16,7 @@ import org.apache.commons.cli.Options; * mvn clean install * 2. Run in server mode: * dapr run --app-id invokedemo --app-port 3000 --port 3005 \ - * -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.invoke.http.DemoService -D exec.args="-p 3000" + * -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.invoke.http.DemoService -Dexec.args="-p 3000" */ public class DemoService { diff --git a/examples/src/main/java/io/dapr/examples/invoke/http/README.md b/examples/src/main/java/io/dapr/examples/invoke/http/README.md index 6c4dfc6fb..3fa31d6ee 100644 --- a/examples/src/main/java/io/dapr/examples/invoke/http/README.md +++ b/examples/src/main/java/io/dapr/examples/invoke/http/README.md @@ -38,7 +38,7 @@ mvn install The Demo service application is meant to expose a method that can be remotely invoked. In this example, the service code has two parts: -In the `DemoService.java` file, you will find the `DemoService` class, containing the main method. The main method uses the Spring Boot´s DaprApplication class for initializing the `ExposerServiceController`. See the code snippet below: +In the `DemoService.java` file, you will find the `DemoService` class, containing the main method. The main method uses the Spring Boot´s DaprApplication class for initializing the `DemoServiceController`. See the code snippet below: ```java public class DemoService { @@ -89,11 +89,40 @@ public class DemoServiceController { Use the follow command to execute the demo service example: ```sh -dapr run --app-id invokedemo --app-port 3000 --port 3005 -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.invoke.http.DemoService -D exec.args="-p 3000" +dapr run --app-id invokedemo --app-port 3000 --port 3005 -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.invoke.http.DemoService -Dexec.args="-p 3000" ``` -Once running, the ExposerService is now ready to be invoked by Dapr. +Once running, the DemoService is now ready to be invoked by Dapr. +### Debugging the Demo service sample + +If you want to debug the `DemoService`, you have to make sure to provide the port as an argument. + +For VSCode you can find a sample launch.json which includes: +```json +... +{ + "type": "java", + "name": "Debug (Launch)-DemoService", + "request": "launch", + "mainClass": "io.dapr.examples.invoke.http.DemoService", + "projectName": "dapr-sdk-examples", + "args": "-port=3000" +}, +... +``` + +Use the following commands to run the Dapr sidecar. + +For Linux and MacOS: +```sh +dapr run --app-id invokedemo --app-port 3000 --port 3005 --grpc-port 5001 -- cat +``` + +For Windows: +```sh +dapr run --app-id invokedemo --app-port 3000 --port 3005 --grpc-port 5001 -- waitfor FOREVER +``` ### Running the InvokeClient sample @@ -118,7 +147,7 @@ The class knows the app id for the remote application. It uses the the static `D Execute the follow script in order to run the InvokeClient example, passing two messages for the remote method: ```sh -dapr run --port 3006 -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.invoke.http.InvokeClient -D exec.args="'message one' 'message two'" +dapr run --port 3006 -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.invoke.http.InvokeClient -Dexec.args="'message one' 'message two'" ``` Once running, the output should display the messages sent from invoker in the demo service output as follows: diff --git a/examples/src/main/java/io/dapr/examples/pubsub/http/Publisher.java b/examples/src/main/java/io/dapr/examples/pubsub/http/Publisher.java index 852f82ecf..85790a789 100644 --- a/examples/src/main/java/io/dapr/examples/pubsub/http/Publisher.java +++ b/examples/src/main/java/io/dapr/examples/pubsub/http/Publisher.java @@ -16,7 +16,7 @@ import java.util.Collections; * mvn clean install * 2. Run the program: * dapr run --app-id publisher --port 3006 -- \ - * mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.pubsub.http.Publisher + * mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.pubsub.http.Publisher */ public class Publisher { diff --git a/examples/src/main/java/io/dapr/examples/pubsub/http/README.md b/examples/src/main/java/io/dapr/examples/pubsub/http/README.md index d774ab108..d9673b28a 100644 --- a/examples/src/main/java/io/dapr/examples/pubsub/http/README.md +++ b/examples/src/main/java/io/dapr/examples/pubsub/http/README.md @@ -1,6 +1,6 @@ # Dapr Pub-Sub Sample -In this sample, we'll create a publisher and a subscriber java applications using Dapr, based on the publish-subcribe pattern. The publisher will generate messages of a specific topic, while subscriber will listen for messages of specific topic. See [Why Pub-Sub](#why-pub-sub) to understand when this pattern might be a good choice for your software architecture. +In this sample, we'll create a publisher and a subscriber java applications using Dapr, based on the publish-subcribe pattern. The publisher will generate messages of a specific topic, while subscriber will listen for messages of specific topic. See [Why Pub-Sub](https://github.com/dapr/samples/tree/master/4.pub-sub#why-pub-sub) to understand when this pattern might be a good choice for your software architecture. Visit [this](https://github.com/dapr/docs/tree/master/concepts/publish-subscribe-messaging) link for more information about Dapr and Pub-Sub. @@ -52,16 +52,16 @@ public class SubscriberController { ///... @GetMapping("/dapr/subscribe") public byte[] daprConfig() throws Exception { - return SERIALIZER.serialize(new String[] { "message" }); + return SERIALIZER.serialize(new String[] { "testingtopic" }); } - @PostMapping(path = "/message") + @PostMapping(path = "/testingtopic") public Mono handleMessage(@RequestBody(required = false) byte[] body, @RequestHeader Map headers) { return Mono.fromRunnable(() -> { try { // Dapr's event is compliant to CloudEvent. - CloudEventEnvelope envelope = SERIALIZER.deserialize(body, CloudEventEnvelope.class); + CloudEvent envelope = CloudEvent.deserialize(body); String message = envelope.getData() == null ? "" : new String(envelope.getData()); System.out.println("Subscriber got message: " + message); @@ -74,7 +74,37 @@ public class SubscriberController { ``` Execute the follow script in order to run the Subscriber example: ```sh -dapr run --app-id subscriber --app-port 3000 --port 3005 -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.pubsub.http.Subscriber -D exec.args="-p 3000" +dapr run --app-id subscriber --app-port 3000 --port 3005 -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.pubsub.http.Subscriber -Dexec.args="-p 3000" +``` + +### Debugging the subscriber + +If you want to debug the `Subscriber`, you have to make sure to provide the port as an argument. + +For VSCode you can find a sample launch.json which includes: +```json +... +{ + "type": "java", + "name": "Debug (Launch)-Subscriber", + "request": "launch", + "mainClass": "io.dapr.examples.pubsub.http.Subscriber", + "projectName": "dapr-sdk-examples", + "args": "-port=3000" +}, +... +``` + +Use the following commands to run the Dapr sidecar. + +For Linux and MacOS +```sh +dapr run --app-id subscriber --app-port 3000 --port 3005 --grpc-port 5001 -- cat +``` + +For Windows: +```sh +dapr run --app-id subscriber --app-port 3000 --port 3005 --grpc-port 5001 -- waitfor FOREVER ``` ### Running the publisher @@ -122,7 +152,7 @@ public class Publisher { Use the follow command to execute the Publisher example: ```sh -dapr run --app-id publisher --port 3006 -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.pubsub.http.Publisher +dapr run --app-id publisher --port 3006 -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.pubsub.http.Publisher ``` Once running, the Publisher should print the output as follows: @@ -137,4 +167,4 @@ Once running, the Subscriber should print the output as follows: Messages have been retrieved from the topic. -For more details on Dapr Spring Boot integration, please refer to [Dapr Spring Boot](../../../springboot/DaprApplication.java) Application implementation. \ No newline at end of file +For more details on Dapr Spring Boot integration, please refer to [Dapr Spring Boot](../../../springboot/DaprApplication.java) Application implementation. diff --git a/examples/src/main/java/io/dapr/examples/state/README.md b/examples/src/main/java/io/dapr/examples/state/README.md index 74abce6e6..2a8c63d2a 100644 --- a/examples/src/main/java/io/dapr/examples/state/README.md +++ b/examples/src/main/java/io/dapr/examples/state/README.md @@ -27,7 +27,7 @@ mvn install ### Running the StateClient This example uses the Java SDK Dapr client in order to save, retrieve and delete a state, in this case, an instance of a class. See the code snippet bellow: -``` +```java public class StateClient { ///... private static final String KEY_NAME = "mykey"; @@ -60,7 +60,7 @@ The code uses the `DaprClient` created by the `DaprClientBuilder`. Notice that t Run this example with the following command: ```sh -dapr run --port 3006 -- mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.state.StateClient -D exec.args="'my message'" +dapr run --port 3006 -- mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.state.StateClient -Dexec.args="'my message'" ``` Once running, the OutputBindingExample should print the output as follows: diff --git a/examples/src/main/java/io/dapr/examples/state/StateClient.java b/examples/src/main/java/io/dapr/examples/state/StateClient.java index f1604ef9f..8e5aad570 100644 --- a/examples/src/main/java/io/dapr/examples/state/StateClient.java +++ b/examples/src/main/java/io/dapr/examples/state/StateClient.java @@ -15,7 +15,7 @@ import reactor.core.publisher.Mono; * mvn clean install * 2. send a message to be saved as state: * dapr run --port 3006 -- \ - * mvn exec:java -pl=examples -D exec.mainClass=io.dapr.examples.state.StateClient -D exec.args="'my message'" + * mvn exec:java -pl=examples -Dexec.mainClass=io.dapr.examples.state.StateClient -Dexec.args="'my message'" */ public class StateClient { diff --git a/sdk-tests/src/test/java/io/dapr/it/DaprRun.java b/sdk-tests/src/test/java/io/dapr/it/DaprRun.java index 57f5884ec..83d6cffbd 100644 --- a/sdk-tests/src/test/java/io/dapr/it/DaprRun.java +++ b/sdk-tests/src/test/java/io/dapr/it/DaprRun.java @@ -18,7 +18,7 @@ public class DaprRun { // the arg in -Dexec.args is the app's port private static final String DAPR_COMMAND = - " -- mvn exec:java -D exec.mainClass=%s -D exec.classpathScope=test -D exec.args=\"%s\""; + " -- mvn exec:java -Dexec.mainClass=%s -Dexec.classpathScope=test -Dexec.args=\"%s\""; private final DaprPorts ports;