Skip to content

Commit 4b83da6

Browse files
Adding @Serviceconnection spring boot support with Testcontainers (dapr#1118)
* adding service connection plumbing Signed-off-by: salaboy <[email protected]> * fixing style Signed-off-by: salaboy <[email protected]> * updating sdk-tests Signed-off-by: salaboy <[email protected]> * Update dapr-spring/dapr-spring-boot-autoconfigure/src/main/java/io/dapr/spring/boot/autoconfigure/client/DaprClientAutoConfiguration.java Co-authored-by: Eddú Meléndez Gonzales <[email protected]> Signed-off-by: salaboy <[email protected]> * Update dapr-spring/dapr-spring-boot-autoconfigure/src/main/java/io/dapr/spring/boot/autoconfigure/client/PropertiesDaprConnectionDetails.java Co-authored-by: Eddú Meléndez Gonzales <[email protected]> Signed-off-by: salaboy <[email protected]> * fixing details Signed-off-by: salaboy <[email protected]> * adding @Serviceconnection to Dapr Signed-off-by: salaboy <[email protected]> * fixing tests and style Signed-off-by: salaboy <[email protected]> * removing test that is not needed anymore Signed-off-by: salaboy <[email protected]> * updating starter dependencies Signed-off-by: salaboy <[email protected]> * adding juniper testcontainers support Signed-off-by: salaboy <[email protected]> * adding new testing module Signed-off-by: salaboy <[email protected]> * cleaning sdk-tests deps Signed-off-by: salaboy <[email protected]> * removing dead code Signed-off-by: salaboy <[email protected]> * removing core that is not needed Signed-off-by: salaboy <[email protected]> * adding setters Signed-off-by: salaboy <[email protected]> * default constructor Signed-off-by: salaboy <[email protected]> --------- Signed-off-by: salaboy <[email protected]> Co-authored-by: Eddú Meléndez Gonzales <[email protected]>
1 parent 9b927c8 commit 4b83da6

File tree

24 files changed

+312
-294
lines changed

24 files changed

+312
-294
lines changed

dapr-spring/dapr-spring-boot-autoconfigure/pom.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
<packaging>jar</packaging>
1616

1717
<dependencies>
18-
<dependency>
19-
<groupId>io.dapr.spring</groupId>
20-
<artifactId>dapr-spring-core</artifactId>
21-
<version>${project.parent.version}</version>
22-
<optional>true</optional>
23-
</dependency>
2418
<dependency>
2519
<groupId>io.dapr.spring</groupId>
2620
<artifactId>dapr-spring-data</artifactId>

dapr-spring/dapr-spring-boot-autoconfigure/src/main/java/io/dapr/spring/boot/autoconfigure/client/DaprClientAutoConfiguration.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,33 @@
1515

1616
import io.dapr.client.DaprClient;
1717
import io.dapr.client.DaprClientBuilder;
18-
import io.dapr.spring.core.client.DaprClientCustomizer;
19-
import org.springframework.beans.factory.ObjectProvider;
18+
import io.dapr.config.Properties;
2019
import org.springframework.boot.autoconfigure.AutoConfiguration;
2120
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
2221
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
22+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2323
import org.springframework.context.annotation.Bean;
2424

25-
import java.util.stream.Collectors;
26-
2725
@AutoConfiguration
2826
@ConditionalOnClass(DaprClient.class)
27+
@EnableConfigurationProperties(DaprClientProperties.class)
2928
public class DaprClientAutoConfiguration {
3029

3130
@Bean
32-
@ConditionalOnMissingBean
33-
DaprClientBuilderConfigurer daprClientBuilderConfigurer(ObjectProvider<DaprClientCustomizer> customizerProvider) {
34-
DaprClientBuilderConfigurer configurer = new DaprClientBuilderConfigurer();
35-
configurer.setDaprClientCustomizer(customizerProvider.orderedStream().collect(Collectors.toList()));
36-
37-
return configurer;
31+
@ConditionalOnMissingBean(DaprConnectionDetails.class)
32+
DaprConnectionDetails daprConnectionDetails(DaprClientProperties properties) {
33+
return new PropertiesDaprConnectionDetails(properties);
3834
}
3935

4036
@Bean
4137
@ConditionalOnMissingBean
42-
DaprClientBuilder daprClientBuilder(DaprClientBuilderConfigurer daprClientBuilderConfigurer) {
38+
DaprClientBuilder daprClientBuilder(DaprConnectionDetails daprConnectionDetails) {
4339
DaprClientBuilder builder = new DaprClientBuilder();
44-
45-
return daprClientBuilderConfigurer.configure(builder);
40+
builder.withPropertyOverride(Properties.HTTP_ENDPOINT, daprConnectionDetails.httpEndpoint());
41+
builder.withPropertyOverride(Properties.GRPC_ENDPOINT, daprConnectionDetails.grpcEndpoint());
42+
builder.withPropertyOverride(Properties.HTTP_PORT, String.valueOf(daprConnectionDetails.httpPort()));
43+
builder.withPropertyOverride(Properties.GRPC_PORT, String.valueOf(daprConnectionDetails.grpcPort()));
44+
return builder;
4645
}
4746

4847
@Bean

dapr-spring/dapr-spring-boot-autoconfigure/src/main/java/io/dapr/spring/boot/autoconfigure/client/DaprClientBuilderConfigurer.java

Lines changed: 0 additions & 52 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2024 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.spring.boot.autoconfigure.client;
15+
16+
import io.dapr.spring.data.DaprKeyValueAdapterResolver;
17+
import org.springframework.boot.context.properties.ConfigurationProperties;
18+
19+
@ConfigurationProperties(prefix = "dapr.client")
20+
public class DaprClientProperties {
21+
private String httpEndpoint;
22+
private String grpcEndpoint;
23+
private Integer httpPort;
24+
private Integer grpcPort;
25+
26+
27+
/**
28+
* Constructs a {@link DaprClientProperties}.
29+
*/
30+
public DaprClientProperties() {
31+
}
32+
33+
/**
34+
* Constructs a {@link DaprClientProperties}.
35+
* @param httpEndpoint http endpoint to interact with the Dapr Sidecar
36+
* @param grpcEndpoint grpc endpoint to interact with the Dapr Sidecar
37+
* @param httpPort http port to interact with the Dapr Sidecar
38+
* @param grpcPort grpc port to interact with the Dapr Sidecar
39+
*/
40+
public DaprClientProperties(String httpEndpoint, String grpcEndpoint, Integer httpPort, Integer grpcPort) {
41+
this.httpEndpoint = httpEndpoint;
42+
this.grpcEndpoint = grpcEndpoint;
43+
this.httpPort = httpPort;
44+
this.grpcPort = grpcPort;
45+
}
46+
47+
public String getHttpEndpoint() {
48+
return httpEndpoint;
49+
}
50+
51+
public String getGrpcEndpoint() {
52+
return grpcEndpoint;
53+
}
54+
55+
public Integer getHttpPort() {
56+
return httpPort;
57+
}
58+
59+
public Integer getGrpcPort() {
60+
return grpcPort;
61+
}
62+
63+
public void setHttpEndpoint(String httpEndpoint) {
64+
this.httpEndpoint = httpEndpoint;
65+
}
66+
67+
public void setGrpcEndpoint(String grpcEndpoint) {
68+
this.grpcEndpoint = grpcEndpoint;
69+
}
70+
71+
public void setHttpPort(Integer httpPort) {
72+
this.httpPort = httpPort;
73+
}
74+
75+
public void setGrpcPort(Integer grpcPort) {
76+
this.grpcPort = grpcPort;
77+
}
78+
}

dapr-spring/dapr-spring-core/src/main/java/io/dapr/spring/core/client/DaprClientCustomizer.java renamed to dapr-spring/dapr-spring-boot-autoconfigure/src/main/java/io/dapr/spring/boot/autoconfigure/client/DaprConnectionDetails.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,16 @@
1111
limitations under the License.
1212
*/
1313

14-
package io.dapr.spring.core.client;
14+
package io.dapr.spring.boot.autoconfigure.client;
1515

16-
import io.dapr.client.DaprClientBuilder;
16+
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;
1717

18-
/**
19-
* Callback interface that can be used to customize a {@link DaprClientBuilder}.
20-
*/
21-
@FunctionalInterface
22-
public interface DaprClientCustomizer {
18+
public interface DaprConnectionDetails extends ConnectionDetails {
19+
String httpEndpoint();
2320

24-
/**
25-
* Callback to customize a {@link DaprClientBuilder} instance.
26-
*
27-
* @param daprClientBuilder the client builder to customize
28-
*/
29-
void customize(DaprClientBuilder daprClientBuilder);
21+
String grpcEndpoint();
3022

23+
Integer httpPort();
24+
25+
Integer grpcPort();
3126
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2024 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.spring.boot.autoconfigure.client;
15+
16+
class PropertiesDaprConnectionDetails implements DaprConnectionDetails {
17+
18+
private final DaprClientProperties daprClientProperties;
19+
20+
public PropertiesDaprConnectionDetails(DaprClientProperties daprClientProperties) {
21+
this.daprClientProperties = daprClientProperties;
22+
}
23+
24+
@Override
25+
public String httpEndpoint() {
26+
return this.daprClientProperties.getHttpEndpoint();
27+
}
28+
29+
@Override
30+
public String grpcEndpoint() {
31+
return this.daprClientProperties.getGrpcEndpoint();
32+
}
33+
34+
@Override
35+
public Integer httpPort() {
36+
return this.daprClientProperties.getHttpPort();
37+
}
38+
39+
@Override
40+
public Integer grpcPort() {
41+
return this.daprClientProperties.getGrpcPort();
42+
}
43+
}

dapr-spring/dapr-spring-boot-autoconfigure/src/test/java/io/dapr/spring/boot/autoconfigure/client/DaprClientAutoConfigurationTests.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ class DaprClientAutoConfigurationTests {
2929
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
3030
.withConfiguration(AutoConfigurations.of(DaprClientAutoConfiguration.class));
3131

32-
@Test
33-
void daprClientBuilderConfigurer() {
34-
contextRunner.run(context -> assertThat(context).hasSingleBean(DaprClientBuilderConfigurer.class));
35-
}
36-
3732
@Test
3833
void daprClientBuilder() {
3934
contextRunner.run(context -> assertThat(context).hasSingleBean(DaprClientBuilder.class));
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>io.dapr.spring</groupId>
8+
<artifactId>dapr-spring-parent</artifactId>
9+
<version>0.13.0-SNAPSHOT</version>
10+
<relativePath>../../pom.xml</relativePath>
11+
</parent>
12+
13+
<artifactId>dapr-spring-boot-starter-test</artifactId>
14+
<name>dapr-spring-boot-starter-test</name>
15+
<description>Dapr Spring Boot Starter Tests (with Testcontainers Support)</description>
16+
<packaging>jar</packaging>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.springframework.boot</groupId>
21+
<artifactId>spring-boot-starter-test</artifactId>
22+
</dependency>
23+
<dependency>
24+
<groupId>io.dapr.spring</groupId>
25+
<artifactId>dapr-spring-boot-tests</artifactId>
26+
<version>${project.parent.version}</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>io.dapr</groupId>
30+
<artifactId>testcontainers-dapr</artifactId>
31+
<version>${project.parent.version}</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-testcontainers</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.testcontainers</groupId>
39+
<artifactId>junit-jupiter</artifactId>
40+
<optional>true</optional>
41+
</dependency>
42+
</dependencies>
43+
44+
</project>

dapr-spring/dapr-spring-boot-starters/dapr-spring-boot-starter/pom.xml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,32 @@
1212

1313
<artifactId>dapr-spring-boot-starter</artifactId>
1414
<name>dapr-spring-boot-starter</name>
15-
<description>Dapr Client Spring Boot Starter</description>
15+
<description>Dapr Spring Boot Starter</description>
1616
<packaging>jar</packaging>
1717

1818
<dependencies>
1919
<dependency>
2020
<groupId>org.springframework.boot</groupId>
2121
<artifactId>spring-boot-starter</artifactId>
2222
</dependency>
23+
<dependency>
24+
<groupId>io.dapr</groupId>
25+
<artifactId>dapr-sdk-springboot</artifactId>
26+
<version>${dapr.sdk.version}</version>
27+
</dependency>
2328
<dependency>
2429
<groupId>io.dapr.spring</groupId>
25-
<artifactId>dapr-spring-core</artifactId>
30+
<artifactId>dapr-spring-boot-autoconfigure</artifactId>
2631
<version>${project.parent.version}</version>
2732
</dependency>
2833
<dependency>
2934
<groupId>io.dapr.spring</groupId>
30-
<artifactId>dapr-spring-boot-autoconfigure</artifactId>
35+
<artifactId>dapr-spring-data</artifactId>
36+
<version>${project.parent.version}</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>io.dapr.spring</groupId>
40+
<artifactId>dapr-spring-messaging</artifactId>
3141
<version>${project.parent.version}</version>
3242
</dependency>
3343
</dependencies>

0 commit comments

Comments
 (0)