-
Autoconfigure an Event Hubs processor with another checkpoint store implementation
-
Autoconfigure producer and consumer of different Event Hubs namespaces
-
Autoconfigure producer and consumer of different Service Bus namespaces
a. Configure options in application.yaml
spring.cloud.azure:
keyvault:
secret:
endpoint: ${AZURE_KEYVAULT_ENDPOINT}
b. Autowire SecretClient
in Spring Boot application:
@Service
public class KeyVaultService {
@Autowired
private SecretClient secretClient; // SecretAsyncClient is also available for autowire
}
a. Configure options in application.yaml
spring.cloud.azure:
keyvault:
certificate:
endpoint: ${AZURE_KEYVAULT_ENDPOINT}
b. Autowire CertificateClient
in Spring Boot application:
@Service
public class KeyVaultService {
@Autowired
private CertificateClient secretClient; // CertificateAsyncClient is also available for autowire
}
a. Configure options in application.yaml
spring.cloud.azure:
cosmos:
endpoint: ${AZURE_COSMOS_ENDPOINT}
b. Autowire CosmosClient
in Spring Boot application:
@Service
public class CosmosService {
@Autowired
private CosmosClient client; // CosmosAsyncClient is also available for autowire
}
a. Configure options in application.yaml
spring.cloud.azure:
appconfiguration:
endpoint: ${AZURE_APPCONFIGURATION_ENDPOINT}
b. Autowire ConfigurationClient
in Spring Boot application:
@Service
public class AppConfigurationService {
@Autowired
private ConfigurationClient client; // ConfigurationAsyncClient is also available for autowire
}
a. Configure options in application.yaml
spring.cloud.azure:
storage:
blob:
endpoint: ${AZURE_STORAGE_ENDPOINT}
b. Autowire BlobServiceClient
in Spring Boot application:
@Service
public class StorageBlobService {
@Autowired
private BlobServiceClient client; // BlobServiceAsyncClient is also available for autowire
}
a. Configure options in application.yaml
spring.cloud.azure:
storage:
blob:
endpoint: ${AZURE_STORAGE_ENDPOINT}
container-name: ${AZURE_STORAGE_CONTAINER_NAME}
b. Autowire BlobContainerClient
in Spring Boot application:
@Service
public class StorageBlobService {
@Autowired
private BlobContainerClient client; // BlobContainerAsyncClient is also available for autowire
}
a. Configure options in application.yaml
spring.cloud.azure:
storage:
blob:
endpoint: ${AZURE_STORAGE_ENDPOINT}
container-name: ${AZURE_STORAGE_CONTAINER_NAME}
blob-name: ${AZURE_STORAGE_BLOB_NAME}
b. Autowire BlobClient
in Spring Boot application:
@Service
public class StorageBlobService {
@Autowired
private BlobClient client; // BlobAsyncClient is also available for autowire
}
a. Configure options in application.yaml
spring.cloud.azure:
storage:
fileshare:
endpoint: ${AZURE_STORAGE_ENDPOINT}
b. Autowire ShareServiceClient
in Spring Boot application:
@Service
public class StorageShareService {
@Autowired
private ShareServiceClient client; // ShareServiceAsyncClient is also available for autowire
}
a. Configure options in application.yaml
spring.cloud.azure:
storage:
fileshare:
endpoint: ${AZURE_STORAGE_ENDPOINT}
share-name: ${AZURE_STORAGE_SHARE_NAME}
b. Autowire ShareClient
in Spring Boot application:
@Service
public class StorageShareService {
@Autowired
private ShareClient client; // ShareAsyncClient is also available for autowire
}
a. Configure options in application.yaml
spring.cloud.azure:
storage:
blob:
endpoint: ${AZURE_STORAGE_ENDPOINT}
share-name: ${AZURE_STORAGE_SHARE_NAME}
file-name: ${AZURE_STORAGE_FILE_NAME}
b. Autowire ShareFileClient
in Spring Boot application:
@Service
public class StorageShareService {
@Autowired
private ShareFileClient client; // ShareFileAsyncClient is also available for autowire
}
a. Configure options in application.yaml
spring.cloud.azure:
storage:
queue:
endpoint: ${AZURE_STORAGE_ENDPOINT}
b. Autowire QueueServiceClient
in Spring Boot application:
@Service
public class StorageQueueService {
@Autowired
private QueueServiceClient client; // QueueServiceAsyncClient is also available for autowire
}
a. Configure options in application.yaml
spring.cloud.azure:
eventhubs:
namespace: ${AZURE_EVENTHUBS_NAMESPACE}
producer:
event-hub-name: ${AZURE_EVENTHUBS_PRODUCER}
b. Autowire EventHubProducerClient
in Spring Boot application:
@Service
public class EventHubsProducerService {
@Autowired
private EventHubProducerClient client; // EventHubProducerAsyncClient is also available for autowire
}
a. Configure options in application.yaml
spring.cloud.azure:
eventhubs:
namespace: ${AZURE_EVENTHUBS_NAMESPACE}
consumer:
event-hub-name: ${AZURE_EVENTHUBS_CONSUMER}
consumer-group: ${AZURE_EVENTHUBS_CONSUMER_GROUP}
b. Autowire EventHubConsumerClient
in Spring Boot application:
@Service
public class EventHubsConsumerService {
@Autowired
private EventHubConsumerClient client; // EventHubConsumerAsyncClient is also available for autowire
}
a. Configure options in application.yaml
spring.cloud.azure:
eventhubs:
namespace: ${AZURE_EVENTHUBS_NAMESPACE}
processor:
event-hub-name: ${AZURE_EVENTHUBS_PROCESSOR}
consumer-group: ${AZURE_EVENTHUBS_CONSUMER_GROUP}
checkpoint-store:
account-name: ${AZURE_STORAGE_ACCOUNT_NAME}
container-name: ${AZURE_STORAGE_CONTAINER_NAME}
b. Provide a EventProcessingListener
in Spring Boot application:
@Configuration
public class UserConfiguration {
@Bean
EventProcessingListener myEventHubEventListener() {
return (RecordEventProcessingListener) eventContext -> {
// on event
};
}
}
c. Autowire EventProcessorClient
in Spring Boot application:
@Service
public class EventHubsProcessorService {
@Autowired
private EventProcessorClient client;
}
a. Configure options in application.yaml
spring.cloud.azure:
eventhubs:
namespace: ${AZURE_EVENTHUBS_NAMESPACE}
processor:
event-hub-name: ${AZURE_EVENTHUBS_PROCESSOR}
consumer-group: ${AZURE_EVENTHUBS_CONSUMER_GROUP}
b. Provide a CheckpointStore
in Spring Boot application:
@Configuration
public class UserConfiguration {
@Bean
CheckpointStore myCheckpointStore() {
// MyCheckpointStore is another implementation of CheckpointStore
return new MyCheckpointStore();
}
}
c. Autowire EventProcessorClient
in Spring Boot application:
@Service
public class EventHubsProcessorService {
@Autowired
private EventProcessorClient client;
}
a. Configure options in application.yaml
spring.cloud.azure:
eventhubs:
producer:
namespace: ${AZURE_EVENTHUBS_NAMESPACE_1}
event-hub-name: ${AZURE_EVENTHUBS_PRODUCER}
consumer:
namespace: ${AZURE_EVENTHUBS_NAMESPACE_2}
event-hub-name: ${AZURE_EVENTHUBS_CONSUMER}
b. Autowire EventHubProducerClient
and EventHubConsumerClient
in Spring Boot application:
@Service
public class EventHubsService {
@Autowired
private EventHubProducerClient producerClient;
@Autowired
private EventHubConsumerClient consumerClient;
void receiveAndSend() {
// Consume events from the first event hub.
consumerClient.receiveFromPartition(partitionId, 15, EventPosition.earliest(), Duration.ofSeconds(40));
// processing the events
...
//and then send to another event hub
producerClient.send(...);
}
}
a. Configure options in application.yaml
spring.cloud.azure:
servicebus:
namespace: ${AZURE_SERVICEBUS_NAMESPACE}
producer:
entity-type: QUEUE
entity-name: ${AZURE_SERVICEBUS_QUEUE_NAME}
b. Autowire ServiceBusSenderClient
in Spring Boot application:
@Service
public class ServiceBusProducerService {
@Autowired
private ServiceBusSenderClient client; // ServiceBusSenderAsyncClient is also available for autowire
}
a. Configure options in application.yaml
spring.cloud.azure:
servicebus:
namespace: ${AZURE_SERVICEBUS_NAMESPACE}
consumer:
entity-type: QUEUE
entity-name: ${AZURE_SERVICEBUS_QUEUE_NAME}
b. Autowire ServiceBusReceiverClient
in Spring Boot application:
@Service
public class ServiceBusConsumerService {
@Autowired
private ServiceBusReceiverClient client; // ServiceBusReceiverAsyncClient is also available for autowire
}
a. Configure options in application.yaml
spring.cloud.azure:
servicebus:
namespace: ${AZURE_SERVICEBUS_NAMESPACE}
consumer:
entity-type: QUEUE
entity-name: ${AZURE_SERVICEBUS_QUEUE_NAME}
session-enabled: true
b. Autowire ServiceBusSessionReceiverClient
in Spring Boot application:
@Service
public class ServiceBusConsumerService {
@Autowired
private ServiceBusSessionReceiverClient client; // ServiceBusSessionReceiverAsyncClient is also available for autowire
}
a. Configure options in application.yaml
spring.cloud.azure:
servicebus:
namespace: ${AZURE_SERVICEBUS_NAMESPACE}
processor:
entity-type: TOPIC
entity-name: ${AZURE_SERVICEBUS_TOPIC_NAME}
subscription-name: ${AZURE_SERVICEBUS_SUBSCRIPTION_NAME}
b. Provide a MessageProcessingListener
in Spring Boot application:
@Configuration
public class UserConfiguration {
@Bean
MessageProcessingListener myServiceBusMessageListener() {
return (RecordMessageProcessingListener) messageContext -> {
// on message
};
}
}
c. Autowire ServiceBusProcessorClient
in Spring Boot application:
@Service
public class ServiceBusProcessorService {
@Autowired
private ServiceBusProcessorClient client;
}
a. Configure options in application.yaml
spring.cloud.azure:
servicebus:
producer:
namespace: ${AZURE_SERVICEBUS_NAMESPACE_1}
entity-type: TOPIC
entity-name: ${AZURE_SERVICEBUS_TOPIC_NAME}
processor:
namespace: ${AZURE_SERVICEBUS_NAMESPACE_2}
entity-type: QUEUE
entity-name: ${AZURE_SERVICEBUS_QUEUE_NAME}
b. Provide a MessageProcessingListener
in Spring Boot application and use the ServiceBusSenderClient
:
@Configuration
public class UserConfiguration {
@Bean
MessageProcessingListener myServiceBusMessageListener(ServiceBusSenderClient senderClient) {
return (RecordMessageProcessingListener) messageContext -> {
// on message
// process message and then send to another entity
senderClient.sendMessage(...);
};
}
}
DefaultAzureCredential
is applied to all SDK clients if no extra authenticating options are provided.
spring.cloud.azure:
eventhubs:
namespace: ${AZURE_EVENTHUBS_NAMESPACE}
credential:
managed-identity-client-id: ${USER_ASSIGNED_MANAGED_IDENTITY_CLIENT_ID}
spring.cloud.azure:
eventhubs:
namespace: ${AZURE_EVENTHUBS_NAMESPACE}
credential:
client-id: ${AZURE_CLIENT_ID}
client-serect: ${AZURE_CLIENT_SECRET}
spring.cloud.azure:
appconfiguration:
endpoint: ${AZURE_APPCONFIGURATION_ENDPOINT}
credential:
client-id: ${AZURE_CLIENT_ID}
client-secret: ${AZURE_CLIENT_SECRET}
eventhubs:
namespace: ${AZURE_EVENTHUBS_NAMESPACE}
credential:
managed-identity-client-id: ${USER_ASSIGNED_MANAGED_IDENTITY_CLIENT_ID}
spring.cloud.azure:
proxy:
hostname: ${AZURE_PROXY_HOSTNAME}
port: ${AZURE_PROXY_PORT}
spring.cloud.azure:
keyvault:
secret:
endpoint: ${AZURE_KEYVAULT_ENDPOINT}
proxy:
hostname: ${AZURE_KEYVAULT_PROXY_HOSTNAME}
port: ${AZURE_KEYVAULT_PROXY_PORT}
a. Define a BeanPostProcessor in Spring Boot application
static class AzureServiceClientBuilderFactoryPostProcessor implements BeanPostProcessor, BeanFactoryAware {
private BeanFactory beanFactory;
@SuppressWarnings("rawtypes")
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof AbstractAzureCredentialBuilderFactory) {
return bean;
}
if (bean instanceof AbstractAzureServiceClientBuilderFactory
&& beanFactory.containsBean(DEFAULT_TOKEN_CREDENTIAL_BEAN_NAME)) {
((AbstractAzureServiceClientBuilderFactory) bean).setDefaultTokenCredential(
(TokenCredential) beanFactory.getBean(DEFAULT_TOKEN_CREDENTIAL_BEAN_NAME));
}
return bean;
}
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
}
b. Now this BeanPostProcessor can set the credential for all *ClientBuilderFactorys.
a. Configure options in application.yaml
spring.cloud.azure:
eventhubs:
namespace: ${AZURE_EVENTHUBS_NAMESPACE}
b. Autowire EventHubClientBuilderFactory
in Spring Boot application:
@Service
public class EventHubsService {
@Autowired
private EventHubClientBuilderFactory factory;
void createBuilder() {
// builder1 and builder2 share the same configurations set up in the `application.yaml`
EventHubClientBuilder builder1 = factory.build();
EventHubClientBuilder builder2 = factory.build();
}
}
@srnagar here's the updated configuration proeprties link https://microsoft.github.io/spring-cloud-azure/4.0.0-beta.3/4.0.0-beta.3/reference/html/appendix.html.