Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
This commit is contained in:
Haishi2016 2020-01-30 17:44:43 -08:00 committed by GitHub
parent 145326a70d
commit d10cd91169
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 8 deletions

View File

@ -1,6 +1,6 @@
# Method invocation Sample
In this sample, we'll create a two java applications: An exposer service application which exposes a method and a client application which will invoke the method from demo service using Dapr.
In this sample, we'll create a two java applications: An demo service application which exposes a method and a client application which will invoke the method from demo service using Dapr.
This sample includes:
* DemoService (Exposes the method to be remotely accessed)
@ -10,12 +10,11 @@ Visit [this](https://github.com/dapr/docs/blob/master/concepts/service-invocatio
## Remote invocation using the Java-SDK
This sample uses the Client provided in Dapr Java SDK invoking a remote method. Exposing the method
This sample uses the Client provided in Dapr Java SDK invoking a remote method.
## Pre-requisites
* [Dapr and Dapr Cli](https://github.com/dapr/docs/blob/master/getting-started/environment-setup.md#environment-setup).
* [Dapr and Dapr CLI](https://github.com/dapr/docs/blob/master/getting-started/environment-setup.md#environment-setup).
* Java JDK 11 (or greater): [Oracle JDK](https://www.oracle.com/technetwork/java/javase/downloads/index.html#JDK11) or [OpenJDK](https://jdk.java.net/13/).
* [Apache Maven](https://maven.apache.org/install.html) version 3.x.
@ -37,7 +36,7 @@ mvn install
### Running the Demo service sample
The Demo service application is meant to expose a method that can be remotely invoked. In this example, the exposer feature has two parts:
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:
@ -54,7 +53,7 @@ public class DemoService {
}
```
`DaprApplication.start()` Method will run an Spring Boot application that registers the `DemoServiceController`, which exposes the invoking action as a POST request. The Dapr's sidecar is the one that performs the actual call to the controller, based on the binding features and the remote invocation action.
`DaprApplication.start()` Method will run an Spring Boot application that registers the `DemoServiceController`, which exposes the invoking action as a POST request. The Dapr's sidecar is the one that performs the actual call to the controller, triggered by client invocations or [bindings](https://github.com/dapr/docs/blob/master/concepts/bindings/README.md).
This Spring Controller exposes the `say` method. The method retrieves metadata from the headers and prints them along with the current date in console. The actual response from method is the formatted current date. See the code snippet below:
@ -87,7 +86,7 @@ public class DemoServiceController {
}
```
Use the follow command to execute the exposer example:
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"
@ -121,7 +120,7 @@ The class knows the app id for the remote application. It uses the the static `D
```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'"
```
Once running, the output should display the messages sent from invoker in the exposer service output as follows:
Once running, the output should display the messages sent from invoker in the demo service output as follows:
![exposeroutput](../../../../../../resources/img/exposer-service.png)