Skip to content

Commit

Permalink
Disable validate() method in @PostContruct method (Azure#17066)
Browse files Browse the repository at this point in the history
* disable @PostContruct validate() method, in case no such properties are configured
  • Loading branch information
saragluna authored Nov 4, 2020
1 parent d8a30cf commit 560a085
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ spring.cloud.stream.bindings.input1.binder=eventhub2
spring.cloud.stream.bindings.output1.destination=[eventhub-2-name]
spring.cloud.stream.bindings.output1.binder=eventhub2

spring.cloud.stream.eventhub2.bindings.input1.consumer.checkpoint-mode=MANUAL
spring.cloud.stream.eventhub.bindings.input1.consumer.checkpoint-mode=MANUAL
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ public EventHubConnectionStringProvider eventHubConnectionStringProvider(
} else {
String connectionString = eventHubProperties.getConnectionString();

if (!StringUtils.hasText(connectionString)) {
throw new IllegalArgumentException("Event hubs connection string cannot be empty");
if (StringUtils.hasText(connectionString)) {
TelemetryCollector.getInstance()
.addProperty(EVENT_HUB, NAMESPACE, EventHubUtils.getNamespace(connectionString));
}

TelemetryCollector.getInstance()
.addProperty(EVENT_HUB, NAMESPACE, EventHubUtils.getNamespace(connectionString));
return new EventHubConnectionStringProvider(connectionString);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
package com.azure.spring.cloud.autoconfigure.eventhub;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;

import javax.annotation.PostConstruct;
import javax.validation.constraints.Pattern;

/**
Expand Down Expand Up @@ -69,16 +67,4 @@ public void setCheckpointContainer(String checkpointContainer) {
this.checkpointContainer = checkpointContainer;
}

/**
* Validate Event Hubs properties.
*
* @throws IllegalArgumentException If namespace or connectionString is empty.
*/
@PostConstruct
public void validate() {
if (!StringUtils.hasText(namespace) && !StringUtils.hasText(connectionString)) {
throw new IllegalArgumentException("Either 'spring.cloud.azure.eventhub.namespace' or "
+ "'spring.cloud.azure.eventhub.connection-string' should be provided");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@
package com.azure.spring.cloud.autoconfigure.servicebus;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;

import javax.annotation.PostConstruct;

/**
* @author Warren Zhu
*/
@Validated
@ConfigurationProperties("spring.cloud.azure.servicebus")
public class AzureServiceBusProperties {

Expand All @@ -36,16 +31,4 @@ public void setConnectionString(String connectionString) {
this.connectionString = connectionString;
}

/**
* Validate properties.
*
* @throws IllegalArgumentException If namespace or connectionString is empty.
*/
@PostConstruct
public void validate() {
if (!StringUtils.hasText(namespace) && !StringUtils.hasText(connectionString)) {
throw new IllegalArgumentException("Either 'spring.cloud.azure.servicebus.namespace' or "
+ "'spring.cloud.azure.servicebus.connection-string' should be provided");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public ServiceBusQueueClientFactory queueClientFactory(AzureServiceBusProperties
if (resourceManagerProvider != null) {
clientFactory.setResourceManagerProvider(resourceManagerProvider);
clientFactory.setNamespace(serviceBusProperties.getNamespace());
} else {
} else if (connectionString != null) {
TelemetryCollector.getInstance().addProperty(SERVICE_BUS_QUEUE, NAMESPACE,
ServiceBusUtils.getNamespace(connectionString));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public ServiceBusTopicClientFactory topicClientFactory(AzureServiceBusProperties
if (resourceManagerProvider != null) {
clientFactory.setNamespace(serviceBusProperties.getNamespace());
clientFactory.setResourceManagerProvider(resourceManagerProvider);
} else {
} else if (connectionString != null) {
TelemetryCollector.getInstance().addProperty(SERVICE_BUS_TOPIC, NAMESPACE,
ServiceBusUtils.getNamespace(connectionString));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Azure azure(AzureTokenCredentials credentials, AzureProperties azurePrope
.withInterceptor(new ResourceManagerThrottlingInterceptor()).withUserAgent(SPRING_CLOUD_USER_AGENT)
.build();

String subscriptionId = Optional.of(azureProperties.getSubscriptionId())
String subscriptionId = Optional.ofNullable(azureProperties.getSubscriptionId())
.orElseGet(credentials::defaultSubscriptionId);
return Azure.authenticate(restClient, credentials.domain())
.withSubscription(subscriptionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@

package com.azure.spring.eventhub.stream.binder.config;

import com.azure.spring.eventhub.stream.binder.properties.EventHubExtendedBindingProperties;
import com.azure.spring.eventhub.stream.binder.EventHubMessageChannelBinder;
import com.azure.spring.eventhub.stream.binder.provisioning.EventHubChannelProvisioner;
import com.azure.spring.eventhub.stream.binder.provisioning.EventHubChannelResourceManagerProvisioner;
import com.azure.spring.cloud.autoconfigure.context.AzureContextAutoConfiguration;
import com.azure.spring.cloud.autoconfigure.context.AzureEnvironmentAutoConfiguration;
import com.azure.spring.cloud.autoconfigure.eventhub.AzureEventHubAutoConfiguration;
import com.azure.spring.cloud.autoconfigure.eventhub.AzureEventHubProperties;
import com.azure.spring.cloud.autoconfigure.eventhub.EventHubUtils;
import com.azure.spring.cloud.context.core.api.ResourceManagerProvider;
import com.azure.spring.cloud.telemetry.TelemetryCollector;
import com.azure.spring.eventhub.stream.binder.EventHubMessageChannelBinder;
import com.azure.spring.eventhub.stream.binder.properties.EventHubExtendedBindingProperties;
import com.azure.spring.eventhub.stream.binder.provisioning.EventHubChannelProvisioner;
import com.azure.spring.eventhub.stream.binder.provisioning.EventHubChannelResourceManagerProvisioner;
import com.azure.spring.integration.eventhub.api.EventHubOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
Expand All @@ -21,6 +22,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.util.StringUtils;

import javax.annotation.PostConstruct;

Expand All @@ -29,8 +31,9 @@
*/
@Configuration
@ConditionalOnMissingBean(Binder.class)
@Import({AzureEventHubAutoConfiguration.class, AzureEnvironmentAutoConfiguration.class})
@EnableConfigurationProperties({AzureEventHubProperties.class, EventHubExtendedBindingProperties.class})
@Import({ AzureEventHubAutoConfiguration.class, AzureEnvironmentAutoConfiguration.class,
AzureContextAutoConfiguration.class })
@EnableConfigurationProperties({ AzureEventHubProperties.class, EventHubExtendedBindingProperties.class })
public class EventHubBinderConfiguration {

private static final String EVENT_HUB_BINDER = "EventHubBinder";
Expand All @@ -47,12 +50,14 @@ public void collectTelemetry() {
@Bean
@ConditionalOnMissingBean
public EventHubChannelProvisioner eventHubChannelProvisioner(AzureEventHubProperties eventHubProperties) {
final String connectionString = eventHubProperties.getConnectionString();

if (resourceManagerProvider != null) {
return new EventHubChannelResourceManagerProvisioner(resourceManagerProvider,
eventHubProperties.getNamespace());
} else {
eventHubProperties.getNamespace());
} else if (StringUtils.hasText(connectionString)) {
TelemetryCollector.getInstance().addProperty(EVENT_HUB_BINDER, NAMESPACE,
EventHubUtils.getNamespace(eventHubProperties.getConnectionString()));
EventHubUtils.getNamespace(connectionString));
}

return new EventHubChannelProvisioner();
Expand All @@ -61,9 +66,10 @@ public EventHubChannelProvisioner eventHubChannelProvisioner(AzureEventHubProper
@Bean
@ConditionalOnMissingBean
public EventHubMessageChannelBinder eventHubBinder(EventHubChannelProvisioner eventHubChannelProvisioner,
EventHubOperation eventHubOperation, EventHubExtendedBindingProperties bindingProperties) {
EventHubOperation eventHubOperation,
EventHubExtendedBindingProperties bindingProperties) {
EventHubMessageChannelBinder binder =
new EventHubMessageChannelBinder(null, eventHubChannelProvisioner, eventHubOperation);
new EventHubMessageChannelBinder(null, eventHubChannelProvisioner, eventHubOperation);
binder.setBindingProperties(bindingProperties);
return binder;
}
Expand Down

0 comments on commit 560a085

Please sign in to comment.