Last active
December 17, 2021 15:01
-
-
Save saragluna/6c005fab01097f7495174e1c436d492d to your computer and use it in GitHub Desktop.
Spring Cloud Azure Service module is an extra abstraction layer for putting all Azure Service client builder factories. This is because we may want to use *ClientBuilderFactory in all Spring Cloud Azure modules, for example, spring-messaging-azure-servicebus and spring-cloud-azure-autoconfigure will both use the ServiceBusClientBuilderFactory.
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. | |
/** | |
* Spring Cloud Azure Service module is an extra abstraction layer for putting all Azure Service client builder | |
* factories. Since we want to use *ClientBuilderFactory in all Spring Cloud Azure modules, for example, | |
* spring-messaging-azure-servicebus and spring-cloud-azure-autoconfigure will both use the | |
* {@link ServiceBusClientBuilderFactory}, so we put all the factories for | |
* service client builder in this module. | |
*/ | |
public class SpringServiceUsages { | |
//================= | |
// Demo how to use EventProcessingListener.java | |
// The auto-configuration of `EventProcessorClientBuilder` requires users to provider a consumer for EventContext or EventBatchContext: | |
// 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/AzureEventHubsProcessorClientConfiguration.java#L32 | |
// 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/AzureEventHubsProcessorClientConfiguration.java#L51 | |
// So besides providing the connection info of the event hub, a bean of type `EventProcessingListener` should also be provided in user's application context. | |
@Bean | |
EventProcessingListener myEventHubEventProcessingListener() { | |
return (RecordEventProcessingListener) eventContext -> System.out.println(eventContext.getEventData()); | |
} | |
//================= | |
// Demo how to use MessageProcessingListener.java | |
// The auto-configuration of `ServiceBusProcessorClientBuilderFactory` requires users to provider a consumer for ServiceBusReceivedMessageContext: | |
// https://github.com/Azure/azure-sdk-for-java/blob/92af61521f76ea60e95cd5cec521ab1cf1c4d246/sdk/spring/spring-cloud-azure-autoconfigure/src/main/java/com/azure/spring/cloud/autoconfigure/servicebus/AzureServiceBusProcessorClientConfiguration.java#L30 | |
// 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/AzureEventHubsProcessorClientConfiguration.java#L51 | |
// So besides providing the connection info of the service bus queue/topic, a bean of type `MessageProcessingListener` should also be provided in user's application context. | |
@Bean | |
MessageProcessingListener myServiceBusMessageProcessingListener() { | |
return (RecordMessageProcessingListener) messageContext -> System.out.println(messageContext.getMessage()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm confused by this code sample - I can't understand what benefit it is demonstrating over directly using the Azure SDK for creating a new
ServiceBusReceiverAsyncClient
?