Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS Spring cloud map support (with AWS SDK v2) #506

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

<modules>
<module>spring-cloud-aws-core</module>
<module>spring-cloud-aws-cloudmap</module>
<module>spring-cloud-aws-autoconfigure</module>
<module>spring-cloud-aws-dependencies</module>
<module>spring-cloud-aws-parameter-store</module>
Expand Down
6 changes: 6 additions & 0 deletions spring-cloud-aws-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
<version>3.0.0-SNAPSHOT</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-cloudmap</artifactId>
<version>3.0.0-SNAPSHOT</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.awspring.cloud</groupId>
<artifactId>spring-cloud-aws-dynamodb</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2013-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.awspring.cloud.autoconfigure.cloudmap;

import io.awspring.cloud.autoconfigure.cloudmap.discovery.CloudMapDiscoveryClient;
import io.awspring.cloud.autoconfigure.cloudmap.properties.CloudMapProperties;
import io.awspring.cloud.autoconfigure.cloudmap.properties.registration.ServiceRegistration;
import io.awspring.cloud.autoconfigure.cloudmap.registration.CloudMapAutoRegistration;
import io.awspring.cloud.autoconfigure.core.AwsClientBuilderConfigurer;
import io.awspring.cloud.autoconfigure.core.AwsClientCustomizer;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryClient;
import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryClientBuilder;

/**
* Cloudmap BootstrapConfiguration configuration class to create the required beans.
*
* @author Hari Ohm Prasath
* @since 3.0
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(CloudMapProperties.class)
@ConditionalOnClass({ ServiceDiscoveryClient.class, ServiceRegistration.class, CloudMapAutoRegistration.class })
hariohmprasath marked this conversation as resolved.
Show resolved Hide resolved
@ConditionalOnProperty(prefix = CloudMapProperties.CONFIG_PREFIX, name = "enabled", matchIfMissing = true)
public class CloudMapBootstrapConfiguration {
hariohmprasath marked this conversation as resolved.
Show resolved Hide resolved

private final ApplicationContext context;
private final CloudMapProperties properties;

public CloudMapBootstrapConfiguration(CloudMapProperties properties, ApplicationContext context) {
this.properties = properties;
this.context = context;
}

@ConditionalOnMissingBean
@Bean
public ServiceDiscoveryClient discoveryClient(AwsClientBuilderConfigurer awsClientBuilderConfigurer,
ObjectProvider<AwsClientCustomizer<ServiceDiscoveryClientBuilder>> configurer) {
return awsClientBuilderConfigurer
.configure(ServiceDiscoveryClient.builder(), this.properties, configurer.getIfAvailable()).build();
}

@Bean
@ConditionalOnMissingBean
CloudMapAutoRegistration createAutoRegistration(ServiceDiscoveryClient serviceDiscovery) {
return new CloudMapAutoRegistration(context, serviceDiscovery, properties.getRegistry());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of ApplicationContext, CloudMapRegistration should use ApplicationEventPublisher for publishing events.

Since it's the only bean that uses is, ApplicationEventPublisher should be provided as a bean factory method parameter instead of a field in the class.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might need some help on this, do you have a sample for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a fix.

}

@Bean
@ConditionalOnMissingBean
CloudMapDiscoveryClient createDiscoveryClient(ServiceDiscoveryClient serviceDiscovery) {
return new CloudMapDiscoveryClient(serviceDiscovery, properties);
}

@Bean
@ConditionalOnMissingBean
ServiceRegistration serviceRegistration() {
return new ServiceRegistration(properties.getRegistry());
}

}
Loading