Skip to content

Commit

Permalink
AWS Spring cloud map support
Browse files Browse the repository at this point in the history
Support for integrating with AWS Cloudmap
  • Loading branch information
hariohmprasath committed Sep 4, 2022
1 parent 8db741e commit 690b3be
Show file tree
Hide file tree
Showing 27 changed files with 1,844 additions and 1 deletion.
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,85 @@
/*
* 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.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 })
@ConditionalOnProperty(prefix = CloudMapProperties.CONFIG_PREFIX, name = "enabled", matchIfMissing = true)
public class CloudMapBootstrapConfiguration {

private final ApplicationContext context;
private ServiceDiscoveryClient serviceDiscovery;
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) {
this.serviceDiscovery = awsClientBuilderConfigurer
.configure(ServiceDiscoveryClient.builder(), this.properties, configurer.getIfAvailable()).build();
return this.serviceDiscovery;
}

@Bean
@ConditionalOnMissingBean
CloudMapAutoRegistration createAutoRegistration() {
return new CloudMapAutoRegistration(context, serviceDiscovery, properties.getRegistry());
}

@Bean
@ConditionalOnMissingBean
public CloudMapDiscoveryClient discoveryClient() {
return new CloudMapDiscoveryClient(serviceDiscovery, properties);
}

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

}
Loading

0 comments on commit 690b3be

Please sign in to comment.