-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factory for Service Discovery Client and Builder (#1086)
Co-authored-by: Denis Stepanov <[email protected]>
- Loading branch information
Showing
6 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
.../io/micronaut/aws/sdk/v2/service/servicediscovery/ServiceDiscoveryAsyncClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2017-2020 original 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.micronaut.aws.sdk.v2.service.servicediscovery; | ||
|
||
import io.micronaut.aws.sdk.v2.service.AwsClientFactory; | ||
import io.micronaut.context.annotation.Bean; | ||
import io.micronaut.context.annotation.Factory; | ||
import io.micronaut.context.annotation.Requires; | ||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain; | ||
import software.amazon.awssdk.http.SdkHttpClient; | ||
import software.amazon.awssdk.http.async.SdkAsyncHttpClient; | ||
import software.amazon.awssdk.regions.providers.AwsRegionProviderChain; | ||
import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryAsyncClient; | ||
import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryAsyncClientBuilder; | ||
import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryClient; | ||
import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryClientBuilder; | ||
|
||
import javax.inject.Singleton; | ||
|
||
/** | ||
* Factory that creates service discovery clients. | ||
* | ||
* @author Denis Stepanov | ||
*/ | ||
@Factory | ||
public class ServiceDiscoveryAsyncClientFactory extends AwsClientFactory<ServiceDiscoveryClientBuilder, | ||
ServiceDiscoveryAsyncClientBuilder, ServiceDiscoveryClient, ServiceDiscoveryAsyncClient> { | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param credentialsProvider The credentials provider | ||
* @param regionProvider The region provider | ||
*/ | ||
public ServiceDiscoveryAsyncClientFactory(AwsCredentialsProviderChain credentialsProvider, AwsRegionProviderChain regionProvider) { | ||
super(credentialsProvider, regionProvider); | ||
} | ||
|
||
@Override | ||
protected ServiceDiscoveryClientBuilder createSyncBuilder() { | ||
return ServiceDiscoveryClient.builder(); | ||
} | ||
|
||
@Override | ||
protected ServiceDiscoveryAsyncClientBuilder createAsyncBuilder() { | ||
return ServiceDiscoveryAsyncClient.builder(); | ||
} | ||
|
||
@Requires(missingBeans = ServiceDiscoveryClientBuilder.class) | ||
@Override | ||
@Singleton | ||
public ServiceDiscoveryClientBuilder syncBuilder(SdkHttpClient httpClient) { | ||
return super.syncBuilder(httpClient); | ||
} | ||
|
||
@Requires(missingBeans = ServiceDiscoveryClient.class) | ||
@Override | ||
@Bean(preDestroy = "close") | ||
@Singleton | ||
public ServiceDiscoveryClient syncClient(ServiceDiscoveryClientBuilder builder) { | ||
return super.syncClient(builder); | ||
} | ||
|
||
@Requires(missingBeans = ServiceDiscoveryAsyncClientBuilder.class) | ||
@Override | ||
@Singleton | ||
@Requires(beans = SdkAsyncHttpClient.class) | ||
public ServiceDiscoveryAsyncClientBuilder asyncBuilder(SdkAsyncHttpClient httpClient) { | ||
return super.asyncBuilder(httpClient); | ||
} | ||
|
||
@Requires(missingBeans = ServiceDiscoveryAsyncClient.class) | ||
@Override | ||
@Bean(preDestroy = "close") | ||
@Singleton | ||
@Requires(beans = SdkAsyncHttpClient.class) | ||
public ServiceDiscoveryAsyncClient asyncClient(ServiceDiscoveryAsyncClientBuilder builder) { | ||
return super.asyncClient(builder); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
aws-sdk-v2/src/main/java/io/micronaut/aws/sdk/v2/service/servicediscovery/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2017-2020 original 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. | ||
*/ | ||
/** | ||
* Service discovery client configuration and factory. | ||
* | ||
* @author Denis Stepanov | ||
*/ | ||
@Requires(classes = {ServiceDiscoveryClient.class, ServiceDiscoveryAsyncClient.class}) | ||
@Configuration | ||
package io.micronaut.aws.sdk.v2.service.servicediscovery; | ||
|
||
import io.micronaut.context.annotation.Configuration; | ||
import io.micronaut.context.annotation.Requires; | ||
import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryAsyncClient; | ||
import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryClient; |
36 changes: 36 additions & 0 deletions
36
aws-sdk-v2/src/test/groovy/io/micronaut/aws/sdk/v2/service/ServiceDiscoveryClientSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.micronaut.aws.sdk.v2.service; | ||
|
||
import io.micronaut.aws.sdk.v2.ApplicationContextSpecification; | ||
import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryAsyncClient | ||
import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryAsyncClientBuilder; | ||
import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryClient | ||
import software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryClientBuilder; | ||
|
||
class ServiceDiscoveryClientSpec extends ApplicationContextSpecification { | ||
|
||
void "it can configure a service discovery client"() { | ||
when: | ||
ServiceDiscoveryClient client = applicationContext.getBean(ServiceDiscoveryClient) | ||
|
||
then: | ||
client.serviceName() == ServiceDiscoveryClient.SERVICE_NAME | ||
} | ||
|
||
void "it can configure an async service discovery client"() { | ||
when: | ||
ServiceDiscoveryAsyncClient client = applicationContext.getBean(ServiceDiscoveryAsyncClient) | ||
|
||
then: | ||
client.serviceName() == ServiceDiscoveryClient.SERVICE_NAME | ||
} | ||
|
||
void "it can configure an async service discovery client Builder"() { | ||
expect: | ||
applicationContext.getBean(ServiceDiscoveryAsyncClientBuilder) | ||
} | ||
|
||
void "it can configure a service discovery client Builder"() { | ||
expect: | ||
applicationContext.getBean(ServiceDiscoveryClientBuilder) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
To use Service discovery, the AWS Java SDK for Amazon Route 53 Auto Naming module, add the following dependency: | ||
|
||
dependency:servicediscovery[groupId="software.amazon.awssdk"] | ||
|
||
Then, the following beans will be created: | ||
|
||
* `software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryClientBuilder` | ||
* `software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryClient` | ||
And: | ||
|
||
* `software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryAsyncClient` | ||
* `software.amazon.awssdk.services.servicediscovery.ServiceDiscoveryAsyncClientBuilder`. | ||
The HTTP client, credentials and region will be configured as per described in the <<sdkv2, SDK v2 documentation>>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters