Last active
December 17, 2021 15:32
-
-
Save saragluna/dec50631b1ffd0125a477b6565b205f3 to your computer and use it in GitHub Desktop.
The Spring Cloud Azure Resource Manager is an abstract layer for azure-resource-manager. It can read metadata from ARM as well as create resources.
This file contains hidden or 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
// Copyright (c) Microsoft Corporation. All rights reserved. | |
// Licensed under the MIT License. | |
/** | |
* The Spring Cloud Azure Resource Manager is an abstract layer for azure-resource-manager. It can read metadata from ARM | |
* as well as create resources. | |
*/ | |
public class SpringResourceManagerUsages { | |
//=================== | |
// Demos how *ArmConnectionStringProvider will be used in a Spring Boot application. These beans are created by our autoconfiguration module. | |
// Support Azure Event Hubs for Apache Kafka in the auto-configuration, which requires us to auto-configure a | |
// KafkaProperties bean. But we will only configure such bean if we detect that a connection string for Event Hubs | |
// is provided in current application context. This connection string can be retrieved via ARM. | |
// An EventHubsArmConnectionStringProvider will be created if azure-resourcemanager is on the classpath | |
// https://github.com/Azure/azure-sdk-for-java/blob/9121aa08d9ae802b16618ed576203dff331e1696/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/resourcemanager/AzureEventHubsResourceManagerAutoConfiguration.java#L42-L51 | |
// And then the KafkaProperties bean configuration will pick up this connection string provider: https://github.com/Azure/azure-sdk-for-java/blob/92af61521f76ea60e95cd5cec521ab1cf1c4d246/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/eventhubs/AzureEventHubsClientBuilderConfiguration.java#L43 | |
@Bean | |
@ConditionalOnMissingBean | |
@ConditionalOnProperty(prefix = AzureEventHubsProperties.PREFIX, value = "namespace") | |
@ConditionalOnMissingProperty(prefix = AzureEventHubsProperties.PREFIX, value = "connection-string") | |
@Order | |
public EventHubsArmConnectionStringProvider eventHubsArmConnectionStringProvider() { | |
return new EventHubsArmConnectionStringProvider(this.azureResourceManager, resourceMetadata, | |
resourceMetadata.getName()); | |
} | |
//=================== | |
// Demos how *EventHubsProvisioner will be used in a Spring Cloud Stream application. | |
// This bean will be pick up by the configuration of a EventHubsChannelProvisioner: | |
// https://github.com/Azure/azure-sdk-for-java/blob/9121aa08d9ae802b16618ed576203dff331e1696/sdk/spring/spring-cloud-azure-stream-binder-eventhubs/src/main/java/com/azure/spring/cloud/stream/binder/eventhubs/config/EventHubsBinderConfiguration.java#L55-L58 | |
@Bean | |
public EventHubsProvisioner myEventHubsProvisioner() { | |
return new EventHubsProvisioner() { | |
@Override | |
public void provisionNamespace(String namespace) { | |
// provision the namespace | |
} | |
@Override | |
public void provisionEventHub(String namespace, String eventHub) { | |
// provision the event hub | |
} | |
@Override | |
public void provisionConsumerGroup(String namespace, String eventHub, String consumerGroup) { | |
// provision the consumer group; | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where is
azureResourceManager
set? Is it injected by Spring, are there any annotations missing, etc?