Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static void main(String[] args) throws Exception {
while (true) {
String message = "Message #" + (count++);
System.out.println("Sending message: " + message);
client.invokeService(serviceAppId, method, message, HttpExtension.NONE).block();
client.invokeMethod(serviceAppId, method, message, HttpExtension.NONE).block();
System.out.println("Message sent: " + message);

Thread.sleep(1000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static class HelloWorldClient {
while (true) {
String message = "Message #" + (count++);
System.out.println("Sending message: " + message);
client.invokeService(serviceAppId, method, message, HttpExtension.NONE).block();
client.invokeMethod(serviceAppId, method, message, HttpExtension.NONE).block();
System.out.println("Message sent: " + message);

Thread.sleep(1000);
Expand All @@ -113,7 +113,7 @@ 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. The Dapr client is also within a try-with-resource block to properly close the client at the end.

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, it will go through in an infinite loop and invoke the `say` method every second. Notice the use of `block()` on the return from `invokeMethod` - 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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class InvokeClient {
public static void main(String[] args) throws Exception {
try (DaprClient client = (new DaprClientBuilder()).build()) {
for (String message : args) {
byte[] response = client.invokeService(SERVICE_APP_ID, "say", message, HttpExtension.POST, null,
byte[] response = client.invokeMethod(SERVICE_APP_ID, "say", message, HttpExtension.POST, null,
byte[].class).block();
System.out.println(new String(response));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private static final String SERVICE_APP_ID = "invokedemo";
public static void main(String[] args) throws Exception {
try (DaprClient client = (new DaprClientBuilder()).build()) {
for (String message : args) {
byte[] response = client.invokeService(SERVICE_APP_ID, "say", message, HttpExtension.POST, null,
byte[] response = client.invokeMethod(SERVICE_APP_ID, "say", message, HttpExtension.POST, null,
byte[].class).block();
System.out.println(new String(response));
}
Expand All @@ -127,7 +127,7 @@ public static void main(String[] args) throws Exception {
}
```

The class knows the app id for the remote application. It uses the the static `Dapr.getInstance().invokeService` method to invoke the remote method defining the parameters: The verb, application id, method name, and proper data and metadata, as well as the type of the expected return type. The returned payload for this method invocation is plain text and not a [JSON String](https://www.w3schools.com/js/js_json_datatypes.asp), so we expect `byte[]` to get the raw response and not try to deserialize it.
The class knows the app id for the remote application. It uses the the static `Dapr.getInstance().invokeMethod` method to invoke the remote method defining the parameters: The verb, application id, method name, and proper data and metadata, as well as the type of the expected return type. The returned payload for this method invocation is plain text and not a [JSON String](https://www.w3schools.com/js/js_json_datatypes.asp), so we expect `byte[]` to get the raw response and not try to deserialize it.

Execute the follow script in order to run the InvokeClient example, passing two messages for the remote method:
```sh
Expand Down
10 changes: 5 additions & 5 deletions examples/src/main/java/io/dapr/examples/state/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class StateClient {
operationList.add(new TransactionalStateOperation<>(TransactionalStateOperation.OperationType.UPSERT,
new State<>(secondState, SECOND_KEY_NAME, "")));

client.executeTransaction(STATE_STORE_NAME, operationList).block();
client.executeStateTransaction(STATE_STORE_NAME, operationList).block();

// get multiple states
Mono<List<State<MyClass>>> retrievedMessagesMono = client.getStates(STATE_STORE_NAME,
Expand All @@ -85,7 +85,7 @@ public class StateClient {
operationList.clear();
operationList.add(new TransactionalStateOperation<>(TransactionalStateOperation.OperationType.DELETE,
new State<>(SECOND_KEY_NAME)));
mono = client.executeTransaction(STATE_STORE_NAME, operationList);
mono = client.executeStateTransaction(STATE_STORE_NAME, operationList);
mono.block();

Mono<List<State<MyClass>>> retrievedDeletedMessageMono = client.getStates(STATE_STORE_NAME,
Expand All @@ -105,10 +105,10 @@ The code uses the `DaprClient` created by the `DaprClientBuilder`. Notice that t
This example performs multiple operations:
* `client.saveState(...)` for persisting an instance of `MyClass`.
* `client.getState(...)` operation in order to retrieve back the persisted state using the same key.
* `client.executeTransaction(...)` operation in order to update existing state and add new state.
* `client.getStates(...)` operation in order to retrieve back the persisted states using the same keys.
* `client.executeStateTransaction(...)` operation in order to update existing state and add new state.
* `client.getBulkState(...)` operation in order to retrieve back the persisted states using the same keys.
* `client.deleteState(...)` operation to remove one of the persisted states.
* `client.executeTransaction(...)` operation in order to remove the other persisted state.
* `client.executeStateTransaction(...)` operation in order to remove the other persisted state.

Finally, the code tries to retrieve the deleted states, which should not be found.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ public static void main(String[] args) throws Exception {
operationList.add(new TransactionalStateOperation<>(TransactionalStateOperation.OperationType.UPSERT,
new State<>(secondState, SECOND_KEY_NAME, "")));

client.executeTransaction(STATE_STORE_NAME, operationList).block();
client.executeStateTransaction(STATE_STORE_NAME, operationList).block();
Comment thread
arghya88 marked this conversation as resolved.

// get multiple states
Mono<List<State<MyClass>>> retrievedMessagesMono = client.getStates(STATE_STORE_NAME,
Mono<List<State<MyClass>>> retrievedMessagesMono = client.getBulkState(STATE_STORE_NAME,
Arrays.asList(FIRST_KEY_NAME, SECOND_KEY_NAME), MyClass.class);
System.out.println("Retrieved messages using bulk get:");
retrievedMessagesMono.block().forEach(System.out::println);
Expand All @@ -88,10 +88,10 @@ public static void main(String[] args) throws Exception {
operationList.clear();
operationList.add(new TransactionalStateOperation<>(TransactionalStateOperation.OperationType.DELETE,
new State<>(SECOND_KEY_NAME)));
mono = client.executeTransaction(STATE_STORE_NAME, operationList);
mono = client.executeStateTransaction(STATE_STORE_NAME, operationList);
mono.block();

Mono<List<State<MyClass>>> retrievedDeletedMessageMono = client.getStates(STATE_STORE_NAME,
Mono<List<State<MyClass>>> retrievedDeletedMessageMono = client.getBulkState(STATE_STORE_NAME,
Arrays.asList(FIRST_KEY_NAME, SECOND_KEY_NAME), MyClass.class);
System.out.println("Trying to retrieve deleted states: ");
retrievedDeletedMessageMono.block().forEach(System.out::println);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void main(String[] args) throws Exception {
InvokeServiceRequestBuilder builder = new InvokeServiceRequestBuilder(SERVICE_APP_ID, "echo");
InvokeServiceRequest request
= builder.withBody(message).withHttpExtension(HttpExtension.POST).withContext(Context.current()).build();
client.invokeService(request, TypeRef.get(byte[].class))
client.invokeMethod(request, TypeRef.get(byte[].class))
.map(r -> {
System.out.println(new String(r.getObject()));
return r;
Expand All @@ -57,7 +57,7 @@ public static void main(String[] args) throws Exception {
InvokeServiceRequest sleepRequest = new InvokeServiceRequestBuilder(SERVICE_APP_ID, "sleep")
.withHttpExtension(HttpExtension.POST)
.withContext(r.getContext()).build();
return client.invokeService(sleepRequest, TypeRef.get(Void.class));
return client.invokeMethod(sleepRequest, TypeRef.get(Void.class));
}).block();
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/src/main/java/io/dapr/examples/tracing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private static final String SERVICE_APP_ID = "invokedemo";
InvokeServiceRequest sleepRequest = new InvokeServiceRequestBuilder(SERVICE_APP_ID, "sleep")
.withHttpExtension(HttpExtension.POST)
.withContext(r.getContext()).build();
return client.invokeService(sleepRequest, TypeRef.get(Void.class));
return client.invokeMethod(sleepRequest, TypeRef.get(Void.class));
}).block();
}
}
Expand All @@ -175,7 +175,7 @@ private static final String SERVICE_APP_ID = "invokedemo";
}
```

The class knows the app id for the remote application. It uses `invokeService` method to invoke API calls on the service endpoint. The request object includes an instance of `io.opentelemetry.context.Context` for the proper tracing headers to be propagated.
The class knows the app id for the remote application. It uses `invokeMethod` method to invoke API calls on the service endpoint. The request object includes an instance of `io.opentelemetry.context.Context` for the proper tracing headers to be propagated.

Execute the follow script in order to run the InvokeClient example, passing two messages for the remote method:
```sh
Expand Down
12 changes: 6 additions & 6 deletions sdk-actors/src/main/java/io/dapr/actors/client/ActorProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface ActorProxy {
* @param <T> The type to be returned.
* @return Asynchronous result with the Actor's response.
*/
<T> Mono<T> invokeActorMethod(String methodName, TypeRef<T> type);
<T> Mono<T> invoke(String methodName, TypeRef<T> type);

/**
* Invokes an Actor method on Dapr.
Expand All @@ -46,7 +46,7 @@ public interface ActorProxy {
* @param <T> The type to be returned.
* @return Asynchronous result with the Actor's response.
*/
<T> Mono<T> invokeActorMethod(String methodName, Class<T> clazz);
<T> Mono<T> invoke(String methodName, Class<T> clazz);

/**
* Invokes an Actor method on Dapr.
Expand All @@ -57,7 +57,7 @@ public interface ActorProxy {
* @param <T> The type to be returned.
* @return Asynchronous result with the Actor's response.
*/
<T> Mono<T> invokeActorMethod(String methodName, Object data, TypeRef<T> type);
<T> Mono<T> invoke(String methodName, Object data, TypeRef<T> type);

/**
* Invokes an Actor method on Dapr.
Expand All @@ -68,15 +68,15 @@ public interface ActorProxy {
* @param <T> The type to be returned.
* @return Asynchronous result with the Actor's response.
*/
<T> Mono<T> invokeActorMethod(String methodName, Object data, Class<T> clazz);
<T> Mono<T> invoke(String methodName, Object data, Class<T> clazz);

/**
* Invokes an Actor method on Dapr.
*
* @param methodName Method name to invoke.
* @return Asynchronous result with the Actor's response.
*/
Mono<Void> invokeActorMethod(String methodName);
Mono<Void> invoke(String methodName);

/**
* Invokes an Actor method on Dapr.
Expand All @@ -85,6 +85,6 @@ public interface ActorProxy {
* @param data Object with the data.
* @return Asynchronous result with the Actor's response.
*/
Mono<Void> invokeActorMethod(String methodName, Object data);
Mono<Void> invoke(String methodName, Object data);

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public String getActorType() {
* {@inheritDoc}
*/
@Override
public <T> Mono<T> invokeActorMethod(String methodName, Object data, TypeRef<T> type) {
return this.daprClient.invokeActorMethod(actorType, actorId.toString(), methodName, this.serialize(data))
public <T> Mono<T> invoke(String methodName, Object data, TypeRef<T> type) {
return this.daprClient.invoke(actorType, actorId.toString(), methodName, this.serialize(data))
.filter(s -> s.length > 0)
.map(s -> deserialize(s, type));
}
Expand All @@ -84,16 +84,16 @@ public <T> Mono<T> invokeActorMethod(String methodName, Object data, TypeRef<T>
* {@inheritDoc}
*/
@Override
public <T> Mono<T> invokeActorMethod(String methodName, Object data, Class<T> clazz) {
return this.invokeActorMethod(methodName, data, TypeRef.get(clazz));
public <T> Mono<T> invoke(String methodName, Object data, Class<T> clazz) {
return this.invoke(methodName, data, TypeRef.get(clazz));
}

/**
* {@inheritDoc}
*/
@Override
public <T> Mono<T> invokeActorMethod(String methodName, TypeRef<T> type) {
return this.daprClient.invokeActorMethod(actorType, actorId.toString(), methodName, null)
public <T> Mono<T> invoke(String methodName, TypeRef<T> type) {
return this.daprClient.invoke(actorType, actorId.toString(), methodName, null)
.filter(s -> s.length > 0)
.map(s -> deserialize(s, type));
}
Expand All @@ -102,24 +102,24 @@ public <T> Mono<T> invokeActorMethod(String methodName, TypeRef<T> type) {
* {@inheritDoc}
*/
@Override
public <T> Mono<T> invokeActorMethod(String methodName, Class<T> clazz) {
return this.invokeActorMethod(methodName, TypeRef.get(clazz));
public <T> Mono<T> invoke(String methodName, Class<T> clazz) {
return this.invoke(methodName, TypeRef.get(clazz));
}

/**
* {@inheritDoc}
*/
@Override
public Mono<Void> invokeActorMethod(String methodName) {
return this.daprClient.invokeActorMethod(actorType, actorId.toString(), methodName, null).then();
public Mono<Void> invoke(String methodName) {
return this.daprClient.invoke(actorType, actorId.toString(), methodName, null).then();
}

/**
* {@inheritDoc}
*/
@Override
public Mono<Void> invokeActorMethod(String methodName, Object data) {
return this.daprClient.invokeActorMethod(actorType, actorId.toString(), methodName, this.serialize(data)).then();
public Mono<Void> invoke(String methodName, Object data) {
return this.daprClient.invoke(actorType, actorId.toString(), methodName, this.serialize(data)).then();
}

/**
Expand All @@ -140,25 +140,25 @@ public Object invoke(Object proxy, Method method, Object[] args) {
if (method.getReturnType().equals(Mono.class)) {
ActorMethod actorMethodAnnotation = method.getDeclaredAnnotation(ActorMethod.class);
if (actorMethodAnnotation == null) {
return invokeActorMethod(method.getName());
return invoke(method.getName());
}

return invokeActorMethod(method.getName(), actorMethodAnnotation.returns());
return invoke(method.getName(), actorMethodAnnotation.returns());
}

return invokeActorMethod(method.getName(), method.getReturnType()).block();
return invoke(method.getName(), method.getReturnType()).block();
}

if (method.getReturnType().equals(Mono.class)) {
ActorMethod actorMethodAnnotation = method.getDeclaredAnnotation(ActorMethod.class);
if (actorMethodAnnotation == null) {
return invokeActorMethod(method.getName(), args[0]);
return invoke(method.getName(), args[0]);
}

return invokeActorMethod(method.getName(), args[0], actorMethodAnnotation.returns());
return invoke(method.getName(), args[0], actorMethodAnnotation.returns());
}

return invokeActorMethod(method.getName(), args[0], method.getReturnType()).block();
return invoke(method.getName(), args[0], method.getReturnType()).block();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ interface DaprClient {
* @param jsonPayload Serialized body.
* @return Asynchronous result with the Actor's response.
*/
Mono<byte[]> invokeActorMethod(String actorType, String actorId, String methodName, byte[] jsonPayload);
Mono<byte[]> invoke(String actorType, String actorId, String methodName, byte[] jsonPayload);

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DaprGrpcClient implements DaprClient {
* {@inheritDoc}
*/
@Override
public Mono<byte[]> invokeActorMethod(String actorType, String actorId, String methodName, byte[] jsonPayload) {
public Mono<byte[]> invoke(String actorType, String actorId, String methodName, byte[] jsonPayload) {
return Mono.fromCallable(DaprException.wrap(() -> {
DaprProtos.InvokeActorRequest req =
DaprProtos.InvokeActorRequest.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DaprHttpClient implements DaprClient {
* {@inheritDoc}
*/
@Override
public Mono<byte[]> invokeActorMethod(String actorType, String actorId, String methodName, byte[] jsonPayload) {
public Mono<byte[]> invoke(String actorType, String actorId, String methodName, byte[] jsonPayload) {
String url = String.format(ACTOR_METHOD_RELATIVE_URL_FORMAT, actorType, actorId, methodName);
Mono<DaprHttp.Response> responseMono =
this.client.invokeApi(DaprHttp.HttpMethods.POST.name(), url, null, jsonPayload, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ protected <T> Mono<Void> registerReminder(
try {
byte[] data = this.actorRuntimeContext.getObjectSerializer().serialize(state);
ActorReminderParams params = new ActorReminderParams(data, dueTime, period);
return this.actorRuntimeContext.getDaprClient().registerActorReminder(
return this.actorRuntimeContext.getDaprClient().registerReminder(
this.actorRuntimeContext.getActorTypeInformation().getName(),
this.id.toString(),
reminderName,
Expand Down Expand Up @@ -157,7 +157,7 @@ protected <T> Mono<String> registerActorTimer(
byte[] data = this.actorRuntimeContext.getObjectSerializer().serialize(state);
ActorTimerParams actorTimer = new ActorTimerParams(callback, data, dueTime, period);

return this.actorRuntimeContext.getDaprClient().registerActorTimer(
return this.actorRuntimeContext.getDaprClient().registerTimer(
this.actorRuntimeContext.getActorTypeInformation().getName(),
this.id.toString(),
name,
Expand All @@ -174,7 +174,7 @@ protected <T> Mono<String> registerActorTimer(
* @return Asynchronous void response.
*/
protected Mono<Void> unregisterTimer(String timerName) {
return this.actorRuntimeContext.getDaprClient().unregisterActorTimer(
return this.actorRuntimeContext.getDaprClient().unregisterTimer(
this.actorRuntimeContext.getActorTypeInformation().getName(),
this.id.toString(),
timerName);
Expand All @@ -187,7 +187,7 @@ protected Mono<Void> unregisterTimer(String timerName) {
* @return Asynchronous void response.
*/
protected Mono<Void> unregisterReminder(String reminderName) {
return this.actorRuntimeContext.getDaprClient().unregisterActorReminder(
return this.actorRuntimeContext.getDaprClient().unregisterReminder(
this.actorRuntimeContext.getActorTypeInformation().getName(),
this.id.toString(),
reminderName);
Expand Down
Loading