Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
de4c37e
Upgrade the version to 1.0.0-SNAPSHOT (#413)
artursouza Dec 16, 2020
11d9e3b
Rename methods and parameters for consistency across SDKs (#410)
arghya88 Dec 16, 2020
b0f1a44
Split components dir for samples + other fixes. (#417)
artursouza Dec 16, 2020
7f1ce0b
Update zipkin detail page for tracing sample. (#423)
artursouza Dec 17, 2020
a35e414
set etag to be null if it's empty (#414)
arghya88 Dec 18, 2020
3b51b5b
Rename ActorProxy invoke to invokeMethod. (#420)
He-Pin Dec 18, 2020
08f133d
Throws IllegalArgumentException without wrapping as DaprException. (#…
artursouza Dec 22, 2020
b5dd421
add metadata in get bulk state request (#401)
skyao Dec 29, 2020
4c1773c
refactor to move duplicate code to method (#429)
arghya88 Dec 29, 2020
2714402
Fix input encoding and error parsing for HTTP calls. (#428)
artursouza Dec 30, 2020
1a6675a
Support TTL in PubSub. Fixes + refactor of CloudEvent. Fix handling c…
artursouza Dec 30, 2020
6a44d51
Adds method to wait for Dapr sidecar. (#433)
artursouza Dec 31, 2020
9e13586
Refactor tracing demo to show A->B->C call stack. (#436)
artursouza Jan 8, 2021
76d877c
Fix blocking calls for gRPC even though using Reactor (#435)
xiazuojie Jan 12, 2021
019dee9
Fix handling of metadata, headers. Removes etag from getState. (#440)
artursouza Jan 14, 2021
d43272f
Rename InvokeServiceRequest to InvokeMethodRequest. (#443)
artursouza Jan 15, 2021
446cd17
Support ActorMethod to change method's name. (#448)
artursouza Jan 20, 2021
81b47f8
Makes http call async and allows timeout in Mono. (#445)
artursouza Jan 21, 2021
38b899d
Add java.lang.reflect.Type to TypeRef per #331 (#449)
pkedy Jan 22, 2021
befed4a
Makes service method API invocations over HTTP by default. (#450)
artursouza Jan 23, 2021
57345eb
Use DaprChannel instead of closeable ActorProxyBuilder. (#451)
artursouza Jan 25, 2021
907748f
Adding GetBulkSecret API.
artursouza Jan 25, 2021
233c699
Merge pull request #452 from artursouza/get_bulk_secrets
wcs1only Jan 25, 2021
c35f0e1
Added unit tests for nullable etag #442
wcs1only Jan 25, 2021
faf3bec
Merge pull request #454 from wcs1only/nullable-etag
wcs1only Jan 25, 2021
c5b4cbd
Add version to Components. (#455)
artursouza Jan 26, 2021
efee056
Updating state management example to include etag mismatch exception …
kachawla Jan 27, 2021
6c26942
Adds autoconfiguration for springboot apps. (#459)
artursouza Jan 27, 2021
a42120f
Merge branch 'master' into release-1.0
artursouza Jan 27, 2021
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
10 changes: 4 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ jobs:
GOARCH: amd64
GOPROXY: https://proxy.golang.org
JDK_VER: 13.0.x
DAPR_CLI_VER: 1.0.0-rc.2
DAPR_RUNTIME_VER: 1.0.0-rc.1
DAPR_CLI_VER: 1.0.0-rc.3
DAPR_RUNTIME_VER: 1.0.0-rc.2
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/3dacfb672d55f1436c249057aaebbe597e1066f3/install/install.sh
DAPR_CLI_REF: 3dacfb672d55f1436c249057aaebbe597e1066f3
DAPR_REF: 3cca3cc1567f1cb955ae69b8fd784f075f62ad42
DAPR_CLI_REF:
DAPR_REF: 5a15b3e0f093d2d0938b12f144c7047474a290fe
OSSRH_USER_TOKEN: ${{ secrets.OSSRH_USER_TOKEN }}
OSSRH_PWD_TOKEN: ${{ secrets.OSSRH_PWD_TOKEN }}
GPG_KEY: ${{ secrets.GPG_KEY }}
Expand Down Expand Up @@ -91,8 +91,6 @@ jobs:
run: |
docker-compose -f ./sdk-tests/deploy/local-test-vault.yml up -d
docker ps
- name: Setup Vault's test token
run: echo myroot > /tmp/.hashicorp_vault_token
- name: Clean up files
run: mvn clean
- name: Build sdk
Expand Down
1 change: 1 addition & 0 deletions examples/components/actors/redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: statestore
spec:
type: state.redis
version: 1
metadata:
- name: redisHost
value: localhost:6379
Expand Down
1 change: 1 addition & 0 deletions examples/components/bindings/kafka_bindings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: sample123
spec:
type: bindings.kafka
version: 1
metadata:
# Kafka broker connection setting
- name: brokers
Expand Down
1 change: 1 addition & 0 deletions examples/components/pubsub/redis_messagebus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: messagebus
spec:
type: pubsub.redis
version: 1
metadata:
- name: redisHost
value: localhost:6379
Expand Down
1 change: 1 addition & 0 deletions examples/components/secrets/hashicorp_vault.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: vault
spec:
type: secretstores.hashicorp.vault
version: 1
metadata:
- name: vaultAddr
value: "http://127.0.0.1:8200"
Expand Down
1 change: 1 addition & 0 deletions examples/components/state/redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: statestore
spec:
type: state.redis
version: 1
metadata:
- name: redisHost
value: localhost:6379
Expand Down
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>io.dapr.springboot.DaprMainApplication</mainClass>
<mainClass>io.dapr.examples.DaprMainApplication</mainClass>
<classifier>exec</classifier>
<finalName>dapr-java-sdk-examples</finalName>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
* Licensed under the MIT License.
*/

package io.dapr.springboot;
package io.dapr.examples;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* Dapr's HTTP callback implementation via SpringBoot.
* Scanning package io.dapr.springboot is required.
*/
@SpringBootApplication(scanBasePackages = {"io.dapr.springboot", "io.dapr.examples"})
@SpringBootApplication
public class DaprApplication {

/**
Expand Down
22 changes: 22 additions & 0 deletions examples/src/main/java/io/dapr/examples/DaprConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*/

package io.dapr.examples;

import io.dapr.client.DaprClient;
import io.dapr.client.DaprClientBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DaprConfig {

private static final DaprClientBuilder BUILDER = new DaprClientBuilder();

@Bean
public DaprClient buildDaprClient() {
return BUILDER.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

package io.dapr.springboot;
package io.dapr.examples;

import java.lang.reflect.Method;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
* Licensed under the MIT License.
*/

package io.dapr.springboot;
package io.dapr.examples;

import io.dapr.examples.invoke.http.InvokeClient;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.trace.propagation.HttpTraceContext;
import io.opentelemetry.context.propagation.DefaultContextPropagators;
import io.opentelemetry.exporter.logging.LoggingSpanExporter;
import io.opentelemetry.exporter.zipkin.ZipkinSpanExporter;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
Expand Down Expand Up @@ -64,10 +63,6 @@ public static Tracer createTracer(String instrumentationName) {
System.out.println("WARNING: Zipkin is not available.");
}

final LoggingSpanExporter loggingExporter = new LoggingSpanExporter();
OpenTelemetrySdk.getGlobalTracerManagement()
.addSpanProcessor(SimpleSpanProcessor.builder(loggingExporter).build());

return tracer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
* Licensed under the MIT License.
*/

package io.dapr.springboot;
package io.dapr.examples;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.propagation.TextMapPropagator;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
Expand All @@ -36,8 +33,6 @@ public String get(@Nullable HttpServletRequest carrier, String key) {
return carrier.getHeader(key);
}
};
@Autowired
Tracer tracer;

@Override
public boolean preHandle(
Expand All @@ -49,43 +44,15 @@ public boolean preHandle(
return true;
}

Span span;
try {
Context context = textFormat.extract(Context.current(), request, HTTP_SERVLET_REQUEST_GETTER);
request.setAttribute("opentelemetry-context", context);
span = tracer.spanBuilder(request.getRequestURI()).setParent(context).startSpan();
span.setAttribute("handler", "pre");
} catch (Exception e) {
span = tracer.spanBuilder(request.getRequestURI()).startSpan();
span.setAttribute("handler", "pre");

span.addEvent(e.toString());
span.setAttribute("error", true);
}
request.setAttribute("opentelemetry-span", span);
Context context = textFormat.extract(Context.current(), request, HTTP_SERVLET_REQUEST_GETTER);
request.setAttribute("opentelemetry-context", context);
return true;
}

@Override
public void postHandle(
HttpServletRequest request, HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
}

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response,
Object handler, Exception exception) {
Object contextObject = request.getAttribute("opentelemetry-context");
Object spanObject = request.getAttribute("opentelemetry-span");
if ((contextObject == null) || (spanObject == null)) {
return;
}
Context context = (Context) contextObject;
Span span = (Span) spanObject;
span.setAttribute("handler", "afterCompletion");
final TextMapPropagator textFormat = OpenTelemetry.getGlobalPropagators().getTextMapPropagator();
textFormat.inject(context, response, HttpServletResponse::addHeader);
span.end();
ModelAndView modelAndView) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

package io.dapr.springboot;
package io.dapr.examples;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public interface DemoActor {

void registerReminder();

@ActorMethod(name = "echo_message")
String say(String something);

void clock(String message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package io.dapr.examples.actors;

import io.dapr.actors.ActorId;
import io.dapr.actors.client.ActorClient;
import io.dapr.actors.client.ActorProxyBuilder;

import java.util.ArrayList;
Expand All @@ -30,7 +31,8 @@ public class DemoActorClient {
* @throws InterruptedException If program has been interrupted.
*/
public static void main(String[] args) throws InterruptedException {
try (ActorProxyBuilder<DemoActor> builder = new ActorProxyBuilder(DemoActor.class)) {
try (ActorClient client = new ActorClient()) {
ActorProxyBuilder<DemoActor> builder = new ActorProxyBuilder(DemoActor.class, client);
List<Thread> threads = new ArrayList<>(NUM_ACTORS);

// Creates multiple actors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package io.dapr.examples.actors;

import io.dapr.actors.runtime.ActorRuntime;
import io.dapr.springboot.DaprApplication;
import io.dapr.examples.DaprApplication;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
Expand Down
13 changes: 10 additions & 3 deletions examples/src/main/java/io/dapr/examples/actors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public class DemoActorImpl extends AbstractActor implements DemoActor, Remindabl
An actor inherits from `AbstractActor` and implements the constructor to pass through `ActorRuntimeContext` and `ActorId`. By default, the actor's name will be the same as the class' name. Optionally, it can be annotated with `ActorType` and override the actor's name. The actor's methods can be synchronously or use [Project Reactor's Mono](https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Mono.html) return type. Finally, state management is done via methods in `super.getActorStateManager()`. The `DemoActor` interface is used by the Actor runtime and also client. See how `DemoActor` interface can be annotated as Dapr Actor.

```java
import io.dapr.actors.ActorMethod;

/**
* Example of implementation of an Actor.
*/
Expand All @@ -113,6 +115,7 @@ public interface DemoActor {

void registerReminder();

@ActorMethod(name = "echo_message")
String say(String something);

void clock(String message);
Expand All @@ -123,7 +126,10 @@ public interface DemoActor {

```

The `@ActorType` annotation indicates the Dapr Java SDK that this interface is an Actor Type, allowing a name for the type to be defined. Some methods can return a `Mono` object. In these cases, the `@ActorMethod` annotation is used to hint the Dapr Java SDK of the type encapsulated in the `Mono` object. You can read more about Java generic type erasure [here](https://docs.oracle.com/javase/tutorial/java/generics/erasure.html).
The `@ActorType` annotation indicates the Dapr Java SDK that this interface is an Actor Type, allowing a name for the type to be defined.

The `@ActorMethod` annotation can be applied to an interface method to specify configuration for that method. In this example, the `say` method, is renamed to `echo_message` - this can be used when invoking an actor method implemented in a different programming language (like C# or Python) and the method name does not match Java's naming conventions.
Some methods can return a `Mono` object. In these cases, the `@ActorMethod` annotation is used to hint the Dapr Java SDK of the type encapsulated in the `Mono` object. You can read more about Java generic type erasure [here](https://docs.oracle.com/javase/tutorial/java/generics/erasure.html).


Now, execute the following script in order to run DemoActorService:
Expand All @@ -143,7 +149,8 @@ public class DemoActorClient {
private static final int NUM_ACTORS = 3;

public static void main(String[] args) throws InterruptedException {
try (ActorProxyBuilder<DemoActor> builder = new ActorProxyBuilder(DemoActor.class)) {
try (ActorClient client = new ActorClient()) {
ActorProxyBuilder<DemoActor> builder = new ActorProxyBuilder(DemoActor.class, client);
///...
for (int i = 0; i < NUM_ACTORS; i++) {
DemoActor actor = builder.build(ActorId.createRandom());
Expand Down Expand Up @@ -183,7 +190,7 @@ public class DemoActorClient {
}
```

First, the client defines how many actors it is going to create. The main method declares a `ActorProxyBuilder` to create instances of the `DemoActor` interface, which are implemented automatically by the SDK and make remote calls to the equivalent methods in Actor runtime. `ActorProxyBuilder` implements `Closeable`, which means it holds resources that need to be closed. In this example, we use the "try-resource" feature in Java.
First, the client defines how many actors it is going to create. The main method declares a `ActorClient` and `ActorProxyBuilder` to create instances of the `DemoActor` interface, which are implemented automatically by the SDK and make remote calls to the equivalent methods in Actor runtime. `ActorClient` is reusable for different actor types and should be instantiated only once in your code. `ActorClient` also implements `AutoCloseable`, which means it holds resources that need to be closed. In this example, we use the "try-resource" feature in Java.

Then, the code executes the `callActorForever` private method once per actor. Initially, it will invoke `registerReminder()`, which sets the due time and period for the reminder. Then, `incrementAndGet()` increments a counter, persists it and sends it back as response. Finally `say` method which will print a message containing the received string along with the formatted server time.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package io.dapr.examples.bindings.http;

import io.dapr.springboot.DaprApplication;
import io.dapr.examples.DaprApplication;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,4 @@ For bringing down the kafka cluster that was started in the beginning, run
docker-compose -f ./src/main/java/io/dapr/examples/bindings/http/docker-compose-single-kafka.yml down
```

For more details on Dapr Spring Boot integration, please refer to [Dapr Spring Boot](../../../springboot/DaprApplication.java) Application implementation.
For more details on Dapr Spring Boot integration, please refer to [Dapr Spring Boot](../../DaprApplication.java) Application implementation.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class Client {

}
```
The code uses the `DaprClient` created by the `DaprClientBuilder`. It tries to get a state from state store but provides an unknown state store. It causes Dapr sidecar to return error, which is converted to a `DaprException` to the application. To be compatible with Project Reactor, `DaprException` extends from `RuntimeException` - making it an unchecked exception.
The code uses the `DaprClient` created by the `DaprClientBuilder`. It tries to get a state from state store but provides an unknown state store. It causes Dapr sidecar to return error, which is converted to a `DaprException` to the application. To be compatible with Project Reactor, `DaprException` extends from `RuntimeException` - making it an unchecked exception. Applications might also get `IllegalArgumentException` when invoking methods with invalid input parameters that are validated at the client side.

The Dapr client is also within a try-with-resource block to properly close the client at the end.

Expand Down
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 @@ -8,7 +8,6 @@
import com.google.protobuf.Any;
import io.dapr.v1.AppCallbackGrpc;
import io.dapr.v1.CommonProtos;
import io.dapr.v1.DaprAppCallbackProtos;
import io.grpc.Server;
import io.grpc.ServerBuilder;
import io.grpc.stub.StreamObserver;
Expand Down
4 changes: 2 additions & 2 deletions examples/src/main/java/io/dapr/examples/invoke/grpc/README.md
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 @@ -5,7 +5,7 @@

package io.dapr.examples.invoke.http;

import io.dapr.springboot.DaprApplication;
import io.dapr.examples.DaprApplication;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
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
Loading