Skip to content

Commit af4bcff

Browse files
authored
Merge branch 'master' into master
2 parents 22a7d78 + beafb5a commit af4bcff

File tree

84 files changed

+3576
-591
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+3576
-591
lines changed

.github/workflows/build.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
DAPR_RUNTIME_VER: 1.9.3
3030
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v1.9.1/install/install.sh
3131
DAPR_CLI_REF:
32-
DAPR_REF:
32+
DAPR_REF: a8c698ad897e42d6624f5fc6ccfd0630e2a8fd00
3333
steps:
3434
- uses: actions/checkout@v3
3535
- name: Set up OpenJDK ${{ env.JDK_VER }}
@@ -100,9 +100,10 @@ jobs:
100100
- name: Codecov
101101
uses: codecov/[email protected]
102102
- name: Install jars
103-
run: mvn install -q
103+
run: mvn install -q
104104
- name: Integration tests
105-
run: mvn -f sdk-tests/pom.xml verify -q
105+
id: integration_tests
106+
run: mvn -f sdk-tests/pom.xml verify
106107
- name: Upload test report for sdk
107108
uses: actions/upload-artifact@master
108109
with:
@@ -113,6 +114,19 @@ jobs:
113114
with:
114115
name: report-dapr-java-sdk-actors
115116
path: sdk-actors/target/jacoco-report/
117+
- name: Upload failsafe test report for sdk-tests on failure
118+
if: ${{ failure() && steps.integration_tests.conclusion == 'failure' }}
119+
uses: actions/upload-artifact@master
120+
with:
121+
name: failsafe-report-sdk-tests
122+
path: sdk-tests/target/failsafe-reports
123+
- name: Upload surefire test report for sdk-tests on failure
124+
if: ${{ failure() && steps.integration_tests.conclusion == 'failure' }}
125+
uses: actions/upload-artifact@master
126+
with:
127+
name: surefire-report-sdk-tests
128+
path: sdk-tests/target/surefire-reports
129+
116130
publish:
117131
runs-on: ubuntu-latest
118132
needs: build

.github/workflows/validate.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
validate:
2929
runs-on: ubuntu-latest
3030
strategy:
31+
fail-fast: false # Keep running if one leg fails.
3132
matrix:
3233
java: [ 11, 13, 15, 16 ]
3334
env:
@@ -40,7 +41,7 @@ jobs:
4041
DAPR_RUNTIME_VER: 1.9.3
4142
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/v1.9.1/install/install.sh
4243
DAPR_CLI_REF:
43-
DAPR_REF:
44+
DAPR_REF: a8c698ad897e42d6624f5fc6ccfd0630e2a8fd00
4445
steps:
4546
- uses: actions/checkout@v3
4647
- name: Set up OpenJDK ${{ env.JDK_VER }}
@@ -129,10 +130,10 @@ jobs:
129130
working-directory: ./examples
130131
run: |
131132
mm.py ./src/main/java/io/dapr/examples/state/README.md
132-
- name: Validate pubsub HTTP example
133+
- name: Validate pubsub example
133134
working-directory: ./examples
134135
run: |
135-
mm.py ./src/main/java/io/dapr/examples/pubsub/http/README.md
136+
mm.py ./src/main/java/io/dapr/examples/pubsub/README.md
136137
- name: Validate bindings HTTP example
137138
working-directory: ./examples
138139
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# IDE generated files and directories
22
*.iml
33
.idea/
4+
.run/
45
.vs/
56
.vscode/
67

daprdocs/content/en/java-sdk-docs/_index.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,13 @@ try (DaprClient client = (new DaprClientBuilder()).build()) {
148148
```java
149149
import com.fasterxml.jackson.databind.ObjectMapper;
150150
import io.dapr.Topic;
151+
import io.dapr.client.domain.BulkSubscribeAppResponse;
152+
import io.dapr.client.domain.BulkSubscribeAppResponseEntry;
153+
import io.dapr.client.domain.BulkSubscribeAppResponseStatus;
154+
import io.dapr.client.domain.BulkSubscribeMessage;
155+
import io.dapr.client.domain.BulkSubscribeMessageEntry;
151156
import io.dapr.client.domain.CloudEvent;
157+
import io.dapr.springboot.annotations.BulkSubscribe;
152158
import org.springframework.web.bind.annotation.PostMapping;
153159
import org.springframework.web.bind.annotation.RequestBody;
154160
import org.springframework.web.bind.annotation.RestController;
@@ -186,6 +192,62 @@ public class SubscriberController {
186192
});
187193
}
188194

195+
@BulkSubscribe()
196+
@Topic(name = "testingtopicbulk", pubsubName = "${myAppProperty:messagebus}")
197+
@PostMapping(path = "/testingtopicbulk")
198+
public Mono<BulkSubscribeAppResponse> handleBulkMessage(
199+
@RequestBody(required = false) BulkSubscribeMessage<CloudEvent<String>> bulkMessage) {
200+
return Mono.fromCallable(() -> {
201+
if (bulkMessage.getEntries().size() == 0) {
202+
return new BulkSubscribeAppResponse(new ArrayList<BulkSubscribeAppResponseEntry>());
203+
}
204+
205+
System.out.println("Bulk Subscriber received " + bulkMessage.getEntries().size() + " messages.");
206+
207+
List<BulkSubscribeAppResponseEntry> entries = new ArrayList<BulkSubscribeAppResponseEntry>();
208+
for (BulkSubscribeMessageEntry<?> entry : bulkMessage.getEntries()) {
209+
try {
210+
System.out.printf("Bulk Subscriber message has entry ID: %s\n", entry.getEntryId());
211+
CloudEvent<?> cloudEvent = (CloudEvent<?>) entry.getEvent();
212+
System.out.printf("Bulk Subscriber got: %s\n", cloudEvent.getData());
213+
entries.add(new BulkSubscribeAppResponseEntry(entry.getEntryId(), BulkSubscribeAppResponseStatus.SUCCESS));
214+
} catch (Exception e) {
215+
e.printStackTrace();
216+
entries.add(new BulkSubscribeAppResponseEntry(entry.getEntryId(), BulkSubscribeAppResponseStatus.RETRY));
217+
}
218+
}
219+
return new BulkSubscribeAppResponse(entries);
220+
});
221+
}
222+
}
223+
```
224+
225+
##### Bulk Publish Messages
226+
> Note: API is in Alpha stage
227+
228+
229+
```java
230+
import io.dapr.client.DaprClientBuilder;
231+
import io.dapr.client.DaprPreviewClient;
232+
import io.dapr.client.domain.BulkPublishResponse;
233+
import io.dapr.client.domain.BulkPublishResponseFailedEntry;
234+
import java.util.ArrayList;
235+
import java.util.List;
236+
class Solution {
237+
public void publishMessages() {
238+
try (DaprPreviewClient client = (new DaprClientBuilder()).buildPreviewClient()) {
239+
// Create a list of messages to publish
240+
List<String> messages = new ArrayList<>();
241+
for (int i = 0; i < NUM_MESSAGES; i++) {
242+
String message = String.format("This is message #%d", i);
243+
messages.add(message);
244+
System.out.println("Going to publish message : " + message);
245+
}
246+
247+
// Publish list of messages using the bulk publish API
248+
BulkPublishResponse<String> res = client.publishEvents(PUBSUB_NAME, TOPIC_NAME, "text/plain", messages).block()
249+
}
250+
}
189251
}
190252
```
191253

examples/components/pubsub/redis_messagebus.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@ spec:
1010
value: localhost:6379
1111
- name: redisPassword
1212
value: ""
13+
scopes:
14+
- publisher
15+
- bulk-publisher
16+
- subscriber
17+
- publisher-tracing

examples/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@
123123
<artifactId>dapr-sdk</artifactId>
124124
<version>${project.version}</version>
125125
</dependency>
126+
<dependency>
127+
<groupId>com.evanlennick</groupId>
128+
<artifactId>retry4j</artifactId>
129+
<version>0.15.0</version>
130+
</dependency>
126131
</dependencies>
127132

128133
<build>

examples/src/main/java/io/dapr/examples/bindings/http/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ cd examples
5050

5151
Before getting into the application code, follow these steps in order to set up a local instance of Kafka. This is needed for the local instances. Steps are:
5252

53-
1. To run container locally run:
53+
1. To run container locally run:
5454

5555
<!-- STEP
5656
name: Setup kafka container

examples/src/main/java/io/dapr/examples/exception/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ sleep: 5
7474
-->
7575

7676
```bash
77-
dapr run --app-id exception_example -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.exception.Client
77+
dapr run --app-id exception-example -- java -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.exception.Client
7878
```
7979

8080
<!-- END_STEP -->
@@ -124,7 +124,7 @@ name: Cleanup
124124
-->
125125

126126
```bash
127-
dapr stop --app-id exception_example
127+
dapr stop --app-id exception-example
128128
```
129129

130130
<!-- END_STEP -->
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* Copyright 2023 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.examples.pubsub;
15+
16+
import io.dapr.client.DaprClient;
17+
import io.dapr.client.DaprClientBuilder;
18+
import io.dapr.client.DaprPreviewClient;
19+
import io.dapr.client.domain.BulkPublishResponse;
20+
import io.dapr.client.domain.BulkPublishResponseFailedEntry;
21+
import io.dapr.examples.OpenTelemetryConfig;
22+
import io.opentelemetry.api.OpenTelemetry;
23+
import io.opentelemetry.api.trace.Span;
24+
import io.opentelemetry.api.trace.Tracer;
25+
import io.opentelemetry.context.Scope;
26+
import io.opentelemetry.sdk.OpenTelemetrySdk;
27+
28+
import java.util.ArrayList;
29+
import java.util.List;
30+
31+
import static io.dapr.examples.OpenTelemetryConfig.getReactorContext;
32+
33+
/**
34+
* Message publisher.
35+
* 1. Build and install jars:
36+
* mvn clean install
37+
* 2. cd [repo root]/examples
38+
* 3. Run the program:
39+
* dapr run --components-path ./components/pubsub --app-id bulk-publisher -- \
40+
* java -Ddapr.grpc.port="50010" -jar target/dapr-java-sdk-examples-exec.jar io.dapr.examples.pubsub.BulkPublisher
41+
*/
42+
public class BulkPublisher {
43+
44+
private static final int NUM_MESSAGES = 10;
45+
46+
private static final String TOPIC_NAME = "bulkpublishtesting";
47+
48+
//The name of the pubsub
49+
private static final String PUBSUB_NAME = "messagebus";
50+
51+
/**
52+
* main method.
53+
*
54+
* @param args incoming args
55+
* @throws Exception any exception
56+
*/
57+
public static void main(String[] args) throws Exception {
58+
OpenTelemetry openTelemetry = OpenTelemetryConfig.createOpenTelemetry();
59+
Tracer tracer = openTelemetry.getTracer(BulkPublisher.class.getCanonicalName());
60+
Span span = tracer.spanBuilder("Bulk Publisher's Main").setSpanKind(Span.Kind.CLIENT).startSpan();
61+
try (DaprPreviewClient client = (new DaprClientBuilder()).buildPreviewClient()) {
62+
DaprClient c = (DaprClient) client;
63+
c.waitForSidecar(10000);
64+
try (Scope scope = span.makeCurrent()) {
65+
System.out.println("Using preview client...");
66+
List<String> messages = new ArrayList<>();
67+
System.out.println("Constructing the list of messages to publish");
68+
for (int i = 0; i < NUM_MESSAGES; i++) {
69+
String message = String.format("This is message #%d", i);
70+
messages.add(message);
71+
System.out.println("Going to publish message : " + message);
72+
}
73+
BulkPublishResponse<?> res = client.publishEvents(PUBSUB_NAME, TOPIC_NAME, "text/plain", messages)
74+
.subscriberContext(getReactorContext()).block();
75+
System.out.println("Published the set of messages in a single call to Dapr");
76+
if (res != null) {
77+
if (res.getFailedEntries().size() > 0) {
78+
// Ideally this condition will not happen in examples
79+
System.out.println("Some events failed to be published");
80+
for (BulkPublishResponseFailedEntry<?> entry : res.getFailedEntries()) {
81+
System.out.println("EntryId : " + entry.getEntry().getEntryId()
82+
+ " Error message : " + entry.getErrorMessage());
83+
}
84+
}
85+
} else {
86+
throw new Exception("null response from dapr");
87+
}
88+
}
89+
// Close the span.
90+
91+
span.end();
92+
// Allow plenty of time for Dapr to export all relevant spans to the tracing infra.
93+
Thread.sleep(10000);
94+
// Shutdown the OpenTelemetry tracer.
95+
OpenTelemetrySdk.getGlobalTracerManagement().shutdown();
96+
97+
System.out.println("Done");
98+
}
99+
}
100+
}
101+

0 commit comments

Comments
 (0)