diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-eventhubs/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-eventhubs/README.md index 6b21d01cd935..530f96bc61c1 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-eventhubs/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-eventhubs/README.md @@ -24,9 +24,17 @@ completed before the run. 1. Create [Azure Storage][create-azure-storage] for checkpoint use. +1. **[Optional]** if you want to use service principal, please follow + [create service principal from Azure CLI][create-sp-using-azure-cli] to create one. + +1. **[Optional]** if you want to use managed identity, please follow + [create managed identity][create-managed-identity] to set up managed identity. + ## Examples -1. Update [application.yaml](src/main/resources/application.yaml). +1. Update [application.yaml](src/main/resources/application.yaml). If you choose to use + service principal or managed identity, update the `application-sp.yaml` or + `application-mi.yaml` respectively. ```yaml spring: cloud: @@ -65,6 +73,8 @@ completed before the run. [azure-portal]: http://ms.portal.azure.com/ [create-event-hubs]: https://docs.microsoft.com/azure/event-hubs/ [create-azure-storage]: https://docs.microsoft.com/azure/storage/ +[create-managed-identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-managed-identity.md +[create-sp-using-azure-cli]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-sp-using-azure-cli.md [eventhub-operation]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-integration-eventhubs/src/main/java/com/azure/spring/integration/eventhub/api/EventHubOperation.java [ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist [receive-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-eventhubs/src/main/java/com/azure/spring/sample/eventhubs/ReceiveController.java diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/README.md b/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/README.md index 0aac97a13a12..221aaeff613b 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/README.md +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/README.md @@ -20,10 +20,18 @@ completed before the run. 1. Create Azure Service Bus namespace, queue and topic. Please see [how to create][create-service-bus]. +1. **[Optional]** if you want to use service principal, please follow + [create service principal from Azure CLI][create-sp-using-azure-cli] to create one. + +1. **[Optional]** if you want to use managed identity, please follow + [create managed identity][create-managed-identity] to set up managed identity. + ## Examples -1. Update [application.yaml](src/main/resources/application.yaml). +1. Update [application.yaml](src/main/resources/application.yaml). If you choose to use + service principal or managed identity, update the `application-sp.yaml` or + `application-mi.yaml` respectively. ```yaml spring: cloud: @@ -44,7 +52,7 @@ completed before the run. 1. Send a POST request to service bus queue - $ curl -X POST http://localhost:8080/messages?message=hello + $ curl -X POST http://localhost:8080/queues?message=hello 1. Verify in your app’s logs that a similar message was posted: @@ -72,6 +80,8 @@ completed before the run. [azure-account]: https://azure.microsoft.com/account/ [azure-portal]: http://ms.portal.azure.com/ [create-service-bus]: https://docs.microsoft.com/azure/service-bus-messaging/service-bus-create-namespace-portal +[create-managed-identity]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-managed-identity.md +[create-sp-using-azure-cli]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/create-sp-using-azure-cli.md [ready-to-run-checklist]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/README.md#ready-to-run-checklist [queue-receive-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/java/com/azure/spring/sample/servicebus/QueueReceiveController.java [queue-send-controller]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/java/com/azure/spring/sample/servicebus/QueueSendController.java diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/java/com/azure/spring/sample/servicebus/QueueReceiveController.java b/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/java/com/azure/spring/sample/servicebus/QueueReceiveController.java index 9dd3f90f5812..17c615dd28e6 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/java/com/azure/spring/sample/servicebus/QueueReceiveController.java +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/java/com/azure/spring/sample/servicebus/QueueReceiveController.java @@ -33,10 +33,10 @@ public class QueueReceiveController { @ServiceActivator(inputChannel = INPUT_CHANNEL) public void messageReceiver(byte[] payload, @Header(AzureHeaders.CHECKPOINTER) Checkpointer checkpointer) { String message = new String(payload); - System.out.println(String.format("New message received: '%s'", message)); + System.out.printf("New message received: '%s'%n", message); checkpointer.success().handle((r, ex) -> { if (ex == null) { - System.out.println(String.format("Message '%s' successfully checkpointed", message)); + System.out.printf("Message '%s' successfully checkpointed.%n", message); } return null; }); diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/resources/application-mi.yaml b/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/resources/application-mi.yaml new file mode 100644 index 000000000000..bf6d55a60124 --- /dev/null +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/resources/application-mi.yaml @@ -0,0 +1,18 @@ +spring: + cloud: + azure: + msi-enabled: true + managed-identity: + client-id: [the-id-of-managed-identity] + resource-group: [resource-group] + subscription-id: [subscription-id] + +# Uncomment below configurations if you want to enable auto creating resources. +# +# subscription-id: [subscription-id] +# auto-create-resources: true +# environment: Azure +# region: [region] + + servicebus: + namespace: [servicebus-namespace] diff --git a/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/resources/application-sp.yaml b/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/resources/application-sp.yaml index b504f20fdb83..4efbfbe7617a 100644 --- a/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/resources/application-sp.yaml +++ b/sdk/spring/azure-spring-boot-samples/azure-spring-integration-sample-servicebus/src/main/resources/application-sp.yaml @@ -5,5 +5,13 @@ spring: client-secret: [service-principal-secret] tenant-id: [tenant-id] resource-group: [resource-group] + +# Uncomment below configurations if you want to enable auto creating resources. +# +# subscription-id: [subscription-id] +# auto-create-resources: true +# environment: Azure +# region: [region] + servicebus: namespace: [servicebus-namespace]