mirror of https://github.com/dapr/java-sdk.git
Fix directory for examples. (#306)
This commit is contained in:
parent
25e6e158dc
commit
7963560066
|
|
@ -33,6 +33,11 @@ Then build the Maven project:
|
|||
mvn install
|
||||
```
|
||||
|
||||
Get into the examples directory.
|
||||
```sh
|
||||
cd examples
|
||||
```
|
||||
|
||||
### Running the Demo actor service
|
||||
|
||||
The first Java class is `DemoActorService`. Its job is to register an implementation of `DemoActor` in the Dapr's Actor runtime. In `DemoActorService.java` file, you will find the `DemoActorService` class and the `main` method. See the code snippet below:
|
||||
|
|
@ -123,8 +128,7 @@ The `@ActorType` annotation indicates the Dapr Java SDK that this interface is a
|
|||
|
||||
Now, execute the following script in order to run DemoActorService:
|
||||
```sh
|
||||
cd to [repo-root]
|
||||
dapr run --components-path ./components --app-id demoactorservice --app-port 3000 --port 3005 -- java -jar examples/target/dapr-java-sdk-examples-exec.jar io.dapr.examples.actors.http.DemoActorService -p 3000
|
||||
dapr run --components-path ./components --app-id demoactorservice --app-port 3000 --port 3005 -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.actors.http.DemoActorService -p 3000
|
||||
```
|
||||
|
||||
### Running the Actor client
|
||||
|
|
@ -183,8 +187,7 @@ First, the client defines how many actors it is going to create. Then the main m
|
|||
Use the follow command to execute the DemoActorClient:
|
||||
|
||||
```sh
|
||||
cd to [repo-root]
|
||||
dapr run --components-path ./components --app-id demoactorclient --port 3006 -- java -jar examples/target/dapr-java-sdk-examples-exec.jar io.dapr.examples.actors.http.DemoActorClient
|
||||
dapr run --components-path ./components --app-id demoactorclient --port 3006 -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.actors.http.DemoActorClient
|
||||
```
|
||||
|
||||
Once running, the `DemoActorClient` logs will start displaying the different steps:
|
||||
|
|
|
|||
|
|
@ -36,13 +36,19 @@ Then build the Maven project:
|
|||
# make sure you are in the `java-sdk` directory.
|
||||
mvn install
|
||||
```
|
||||
|
||||
Then, go into the examples directory:
|
||||
|
||||
```sh
|
||||
cd examples
|
||||
```
|
||||
|
||||
### Setting Kafka locally
|
||||
|
||||
Before getting into the application code, follow these steps in order to setup a local instance of Kafka. This is needed for the local instances. Steps are:
|
||||
|
||||
1. Navigate to the root directory for the git repository.
|
||||
2. Run `docker-compose -f ./examples/src/main/java/io/dapr/examples/bindings/http/docker-compose-single-kafka.yml up -d` to run the container locally
|
||||
3. Run `docker ps` to see the container running locally:
|
||||
1. Run `docker-compose -f ./src/main/java/io/dapr/examples/bindings/http/docker-compose-single-kafka.yml up -d` to run the container locally
|
||||
2. Run `docker ps` to see the container running locally:
|
||||
|
||||
```bash
|
||||
342d3522ca14 kafka-docker_kafka "start-kafka.sh" 14 hours ago Up About
|
||||
|
|
@ -88,7 +94,6 @@ public class InputBindingController {
|
|||
|
||||
Execute the follow script in order to run the Input Binding example:
|
||||
```sh
|
||||
cd to [repo-root]/examples
|
||||
dapr run --components-path ./components --app-id inputbinding --app-port 3000 --port 3005 -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.bindings.http.InputBindingExample -p 3000
|
||||
```
|
||||
|
||||
|
|
@ -125,7 +130,6 @@ This example binds two events: A user-defined data object (using the `myClass` o
|
|||
Use the follow command to execute the Output Binding example:
|
||||
|
||||
```sh
|
||||
cd to [repo-root]/examples
|
||||
dapr run --components-path ./components --app-id outputbinding --port 3006 -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.bindings.http.OutputBindingExample
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -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 --components-path ./components -- java -jar examples/target/dapr-java-sdk-examples-exec.jar \
|
||||
* dapr run --components-path ./examples/components -- java -jar examples/target/dapr-java-sdk-examples-exec.jar \
|
||||
* io.dapr.examples.invoke.grpc.HelloWorldClient
|
||||
*/
|
||||
public class HelloWorldClient {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,11 @@ Then build the Maven project:
|
|||
mvn install
|
||||
```
|
||||
|
||||
Get into the examples' directory:
|
||||
```sh
|
||||
cd examples
|
||||
```
|
||||
|
||||
### 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:
|
||||
|
|
@ -69,7 +74,7 @@ In the `GrpcHelloWorldDaprService` class, the `onInvoke` method is the most impo
|
|||
Now run the service code:
|
||||
|
||||
```sh
|
||||
dapr run --components-path ./components --app-id hellogrpc --app-port 5000 --protocol grpc -- java -jar examples/target/dapr-java-sdk-examples-exec.jar io.dapr.examples.invoke.grpc.HelloWorldService -p 5000
|
||||
dapr run --components-path ./components --app-id hellogrpc --app-port 5000 --protocol grpc -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.invoke.grpc.HelloWorldService -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).
|
||||
|
|
@ -108,7 +113,7 @@ Finally, it will go through in an infinite loop and invoke the `say` method ever
|
|||
Finally, open a new command line terminal and run the client code to send some messages.
|
||||
|
||||
```sh
|
||||
dapr run --components-path ./components -- java -jar examples/target/dapr-java-sdk-examples-exec.jar io.dapr.examples.invoke.grpc.HelloWorldClient
|
||||
dapr run --components-path ./components -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.invoke.grpc.HelloWorldClient
|
||||
```
|
||||
|
||||
Once the messages are sent, use `CTRL+C` to exit Dapr.
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ import io.dapr.client.domain.Verb;
|
|||
* 1. Build and install jars:
|
||||
* mvn clean install
|
||||
* 2. Send messages to the server:
|
||||
* dapr run --components-path ./components --port 3006 -- java -jar examples/target/dapr-java-sdk-examples-exec.jar \
|
||||
* dapr run --components-path ./examples/components \
|
||||
* --port 3006 -- java -jar examples/target/dapr-java-sdk-examples-exec.jar \
|
||||
* io.dapr.examples.invoke.http.InvokeClient 'message one' 'message two'
|
||||
*/
|
||||
public class InvokeClient {
|
||||
|
|
|
|||
|
|
@ -34,6 +34,12 @@ Then build the Maven project:
|
|||
mvn install
|
||||
```
|
||||
|
||||
Then get into the examples directory:
|
||||
|
||||
```sh
|
||||
cd examples
|
||||
```
|
||||
|
||||
### Running the Demo service sample
|
||||
|
||||
The Demo service application is meant to expose a method that can be remotely invoked. In this example, the service code has two parts:
|
||||
|
|
@ -89,7 +95,7 @@ public class DemoServiceController {
|
|||
Use the follow command to execute the demo service example:
|
||||
|
||||
```sh
|
||||
dapr run --components-path ./components --app-id invokedemo --app-port 3000 --port 3005 -- java -jar examples/target/dapr-java-sdk-examples-exec.jar io.dapr.examples.invoke.http.DemoService -p 3000
|
||||
dapr run --components-path ./components --app-id invokedemo --app-port 3000 --port 3005 -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.invoke.http.DemoService -p 3000
|
||||
```
|
||||
|
||||
Once running, the ExposerService is now ready to be invoked by Dapr.
|
||||
|
|
@ -120,7 +126,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 --components-path ./components --port 3006 -- java -jar examples/target/dapr-java-sdk-examples-exec.jar io.dapr.examples.invoke.http.InvokeClient 'message one' 'message two'
|
||||
dapr run --components-path ./components --port 3006 -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.invoke.http.InvokeClient 'message one' 'message two'
|
||||
```
|
||||
Once running, the output should display the messages sent from invoker in the demo service output as follows:
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,13 @@ Then build the Maven project:
|
|||
# make sure you are in the `java-sdk` directory.
|
||||
mvn install
|
||||
```
|
||||
|
||||
Then get into the examples directory:
|
||||
|
||||
```sh
|
||||
cd examples
|
||||
```
|
||||
|
||||
### Running the subscriber
|
||||
|
||||
The first is the subscriber. It will subscribe to the topic to be used by the publisher and read the messages published. The Subscriber uses the Spring Boot´s DaprApplication class for initializing the `SubscriberController`. In `Subscriber.java` file, you will find the `Subscriber` class and the `main` method. See the code snippet below:
|
||||
|
|
@ -70,7 +77,7 @@ public class SubscriberController {
|
|||
```
|
||||
Execute the follow script in order to run the Subscriber example:
|
||||
```sh
|
||||
dapr run --components-path ./components --app-id subscriber --app-port 3000 --port 3005 -- java -jar examples/target/dapr-java-sdk-examples-exec.jar io.dapr.examples.pubsub.http.Subscriber -p 3000
|
||||
dapr run --components-path ./components --app-id subscriber --app-port 3000 --port 3005 -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.pubsub.http.Subscriber -p 3000
|
||||
```
|
||||
|
||||
### Running the publisher
|
||||
|
|
@ -118,7 +125,7 @@ public class Publisher {
|
|||
Use the follow command to execute the Publisher example:
|
||||
|
||||
```sh
|
||||
dapr run --components-path ./components --app-id publisher --port 3006 -- java -jar examples/target/dapr-java-sdk-examples-exec.jar io.dapr.examples.pubsub.http.Publisher
|
||||
dapr run --components-path ./components --app-id publisher --port 3006 -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.pubsub.http.Publisher
|
||||
```
|
||||
|
||||
Once running, the Publisher should print the output as follows:
|
||||
|
|
|
|||
|
|
@ -24,6 +24,11 @@ Then build the Maven project:
|
|||
mvn install
|
||||
```
|
||||
|
||||
Then get into the examples directory:
|
||||
```sh
|
||||
cd examples
|
||||
```
|
||||
|
||||
### 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. Multiple state stores are supported since Dapr 0.4. See the code snippet bellow:
|
||||
|
||||
|
|
@ -62,7 +67,7 @@ The code uses the `DaprClient` created by the `DaprClientBuilder`. Notice that t
|
|||
|
||||
Run this example with the following command:
|
||||
```sh
|
||||
dapr run --components-path ./components --port 3006 -- java -jar examples/target/dapr-java-sdk-examples-exec.jar io.dapr.examples.state.StateClient 'my message'
|
||||
dapr run --components-path ./components --port 3006 -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.state.StateClient 'my message'
|
||||
```
|
||||
Once running, the OutputBindingExample should print the output as follows:
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 296 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 211 KiB |
Loading…
Reference in New Issue