From 7cf08213e45e450d24222931a5d34f8247e988f5 Mon Sep 17 00:00:00 2001 From: Min Zhu Date: Thu, 1 Dec 2022 21:49:45 +0000 Subject: [PATCH] poc: add service settings as bean to have more granularity. --- .../com/sample/autoconfig/LanguageAutoConfig.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cloud-language-starter/src/main/java/com/sample/autoconfig/LanguageAutoConfig.java b/cloud-language-starter/src/main/java/com/sample/autoconfig/LanguageAutoConfig.java index 474cc9f..02167f5 100644 --- a/cloud-language-starter/src/main/java/com/sample/autoconfig/LanguageAutoConfig.java +++ b/cloud-language-starter/src/main/java/com/sample/autoconfig/LanguageAutoConfig.java @@ -95,8 +95,8 @@ public TransportChannelProvider defaultLanguageTransportChannelProvider() { } @Bean - @ConditionalOnMissingBean - public LanguageServiceClient languageServiceClient(@Qualifier("languageServiceCredentials") CredentialsProvider credentialsProvider, + @ConditionalOnMissingBean(name = "languageServiceSettings") + public LanguageServiceSettings languageServiceClient(@Qualifier("languageServiceCredentials") CredentialsProvider credentialsProvider, @Qualifier("defaultLanguageTransportChannelProvider") TransportChannelProvider defaultTransportChannelProvider) throws IOException { @@ -179,9 +179,16 @@ public LanguageServiceClient languageServiceClient(@Qualifier("languageServiceCr // ... clientSettingsBuilder.annotateTextSettings() .setRetrySettings(annotateTextRetrySettingsBuilder.build()); + return clientSettingsBuilder.build(); + } - return LanguageServiceClient.create(clientSettingsBuilder.build()); + @Bean + @ConditionalOnMissingBean + public LanguageServiceClient languageServiceClient(@Qualifier("languageServiceSettings") LanguageServiceSettings languageServiceSettings) + throws IOException { + return LanguageServiceClient.create(languageServiceSettings); } + /** * Returns the "user-agent" header value which should be added to the google-cloud-java REST API * calls. e.g., {@code Spring-autoconfig/1.0.0.RELEASE spring-autogen-language/1.0.0.RELEASE}.