From 9f8a49322fd9bec6bf9a845eda998973c7ab00bd Mon Sep 17 00:00:00 2001 From: zhihaoguo Date: Tue, 4 Jan 2022 13:44:59 +0800 Subject: [PATCH 01/12] refactor servicebus samples with terraform and defaultcredential --- .../multiple-namespaces/README.md | 2 +- .../multiple-namespaces/terraform/main.tf | 8 +- .../multiple-namespaces/terraform/outputs.tf | 4 +- .../terraform/variables.tf | 8 +- .../single-namespace/README.md | 4 +- .../single-namespace/terraform/main.tf | 8 +- .../single-namespace/terraform/outputs.tf | 3 +- .../single-namespace/terraform/variables.tf | 8 +- .../servicebus-jms-queue/README.md | 174 ++++++--- .../src/main/resources/application.properties | 5 - .../src/main/resources/application.yaml | 6 + .../servicebus-jms-queue/terraform/main.tf | 82 ++++ .../servicebus-jms-queue/terraform/outputs.tf | 10 + .../terraform/setup_env.sh | 2 + .../terraform/variables.tf | 23 ++ .../servicebus-jms-topic/README.md | 172 ++++++--- .../src/main/resources/application.properties | 7 - .../src/main/resources/application.yaml | 11 + .../servicebus-jms-topic/terraform/main.tf | 83 ++++ .../servicebus-jms-topic/terraform/outputs.tf | 15 + .../terraform/setup_env.sh | 3 + .../terraform/variables.tf | 31 ++ .../servicebus-multibinders/README.md | 300 ++++++++------- .../src/main/resources/application-mi.yaml | 58 --- .../src/main/resources/application-sp.yaml | 59 --- .../src/main/resources/application.yaml | 4 +- .../servicebus-multibinders/terraform/main.tf | 150 ++++++++ .../terraform/outputs.tf | 28 ++ .../terraform/setup_env.sh | 6 + .../terraform/variables.tf | 17 + .../servicebus-queue-binder/README.md | 358 ++++++++--------- .../src/main/resources/application-mi.yaml | 30 -- .../src/main/resources/application-sp.yaml | 29 -- .../src/main/resources/application.yaml | 2 +- .../servicebus-queue-binder/terraform/main.tf | 92 +++++ .../terraform/outputs.tf | 9 + .../terraform/setup_env.sh | 5 + .../terraform/variables.tf | 17 + .../servicebus-topic-binder/README.md | 361 ++++++++---------- .../src/main/resources/application-mi.yaml | 29 -- .../src/main/resources/application-sp.yaml | 30 -- .../src/main/resources/application.yaml | 4 +- .../servicebus-topic-binder/terraform/main.tf | 92 +++++ .../terraform/outputs.tf | 16 + .../terraform/setup_env.sh | 5 + .../terraform/variables.tf | 17 + 46 files changed, 1476 insertions(+), 911 deletions(-) delete mode 100644 servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/src/main/resources/application.properties create mode 100644 servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/src/main/resources/application.yaml create mode 100644 servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/main.tf create mode 100644 servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/outputs.tf create mode 100644 servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/setup_env.sh create mode 100644 servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/variables.tf delete mode 100644 servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.properties create mode 100644 servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.yaml create mode 100644 servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/main.tf create mode 100644 servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/outputs.tf create mode 100644 servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/setup_env.sh create mode 100644 servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/variables.tf delete mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/src/main/resources/application-mi.yaml delete mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/src/main/resources/application-sp.yaml create mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/main.tf create mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/outputs.tf create mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/setup_env.sh create mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/variables.tf delete mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/src/main/resources/application-mi.yaml delete mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/src/main/resources/application-sp.yaml create mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/main.tf create mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/outputs.tf create mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/setup_env.sh create mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/variables.tf delete mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/src/main/resources/application-mi.yaml delete mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/src/main/resources/application-sp.yaml create mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/main.tf create mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/outputs.tf create mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/setup_env.sh create mode 100644 servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/variables.tf diff --git a/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/README.md b/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/README.md index 5624496a1..06bbe006e 100644 --- a/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/README.md +++ b/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/README.md @@ -123,7 +123,7 @@ Send a POST request to service bus queue $ curl -X POST http://localhost:8080/queues?message=hello ``` -Verify in your app’s logs that a similar message was posted: +Verify in your app’s logs that similar messages were posted: ```shell Message was sent successfully for queue1. ... diff --git a/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/main.tf b/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/main.tf index 78a58f7e5..c95b54550 100644 --- a/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/main.tf +++ b/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/main.tf @@ -27,8 +27,8 @@ resource "azurerm_resource_group" "main" { location = var.location tags = { - "terraform" = "true" - "application-name" = var.application_name + "terraform" = "true" + "application-name" = var.application_name "spring-cloud-azure-sample" = var.sample_tag_value } } @@ -104,13 +104,13 @@ resource "azurerm_servicebus_queue" "application_queue_02" { data "azurerm_client_config" "client_config" { } -resource "azurerm_role_assignment" "servicebus_01_data_owner" { +resource "azurerm_role_assignment" "role_servicebus_data_owner_01" { scope = azurerm_servicebus_namespace.servicebus_namespace_01.id role_definition_name = "Azure Service Bus Data Owner" principal_id = data.azurerm_client_config.client_config.object_id } -resource "azurerm_role_assignment" "servicebus_02_data_owner" { +resource "azurerm_role_assignment" "role_servicebus_data_owner_02" { scope = azurerm_servicebus_namespace.servicebus_namespace_02.id role_definition_name = "Azure Service Bus Data Owner" principal_id = data.azurerm_client_config.client_config.object_id diff --git a/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/outputs.tf b/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/outputs.tf index 199ce6820..b2ae36231 100644 --- a/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/outputs.tf +++ b/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/outputs.tf @@ -1,11 +1,11 @@ output "AZURE_SERVICEBUS_NAMESPACE_01" { value = azurerm_servicebus_namespace.servicebus_namespace_01.name - description = "The servicebus_01 namespace." + description = "The name of servicebus_01 namespace." } output "AZURE_SERVICEBUS_NAMESPACE_02" { value = azurerm_servicebus_namespace.servicebus_namespace_02.name - description = "The servicebus_02 namespace." + description = "The name of servicebus_02 namespace." } diff --git a/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/variables.tf b/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/variables.tf index b7bccba09..99326c152 100644 --- a/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/variables.tf +++ b/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/variables.tf @@ -1,17 +1,17 @@ variable "application_name" { type = string - description = "The name of your application" - default = "servicebusapp" + description = "The name of your application." + default = "multiple-namespaces-servicebus" } variable "location" { type = string - description = "The Azure region where all resources in this example should be created" + description = "The Azure region where all resources in this example should be created." default = "eastus" } variable "sample_tag_value" { type = string - description = "The value of spring-cloud-azure-sample tag" + description = "The value of spring-cloud-azure-sample tag." default = "true" } \ No newline at end of file diff --git a/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/README.md b/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/README.md index fbf0928d2..2bdc64703 100644 --- a/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/README.md +++ b/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/README.md @@ -118,7 +118,7 @@ mvn clean spring-boot:run $ curl -X POST http://localhost:8080/queues?message=hello -2. Verify in your app’s logs that a similar message was posted: +2. Verify in your app’s logs that similar messages were posted: New message received: 'hello' Message 'hello' successfully checkpointed @@ -126,7 +126,7 @@ mvn clean spring-boot:run $ curl -X POST http://localhost:8080/topics?message=hello -4. Verify in your app’s logs that a similar message was posted: +4. Verify in your app’s logs that similar messages were posted: New message received: 'hello' Message 'hello' successfully checkpointed diff --git a/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/main.tf b/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/main.tf index 7edc3e8a3..49bc6a6b5 100644 --- a/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/main.tf +++ b/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/main.tf @@ -27,8 +27,8 @@ resource "azurerm_resource_group" "main" { location = var.location tags = { - "terraform" = "true" - "application-name" = var.application_name + "terraform" = "true" + "application-name" = var.application_name "spring-cloud-azure-sample" = var.sample_tag_value } } @@ -58,7 +58,7 @@ resource "azurecaf_name" "servicebus_namespace_authorization_rule" { resource_type = "azurerm_servicebus_namespace_authorization_rule" } -resource "azurerm_servicebus_namespace_authorization_rule" "application" { +resource "azurerm_servicebus_namespace_authorization_rule" "authorization_rule" { name = azurecaf_name.servicebus_namespace_authorization_rule.result namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name resource_group_name = azurerm_resource_group.main.name @@ -103,7 +103,7 @@ resource "azurerm_servicebus_subscription" "application" { data "azurerm_client_config" "client_config" { } -resource "azurerm_role_assignment" "servicebus_data_owner" { +resource "azurerm_role_assignment" "role_servicebus_data_owner" { scope = azurerm_servicebus_namespace.servicebus_namespace.id role_definition_name = "Azure Service Bus Data Owner" principal_id = data.azurerm_client_config.client_config.object_id diff --git a/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/outputs.tf b/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/outputs.tf index 155b11f6f..4aa5129c6 100644 --- a/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/outputs.tf +++ b/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/outputs.tf @@ -1,5 +1,4 @@ output "SERVICEBUS_NAMESPACE" { value = azurerm_servicebus_namespace.servicebus_namespace.name - description = "The servicebus namespace." + description = "The name of servicebus namespace." } - diff --git a/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/variables.tf b/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/variables.tf index 8f1b98e64..9e513c3e8 100644 --- a/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/variables.tf +++ b/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/variables.tf @@ -1,17 +1,17 @@ variable "application_name" { type = string - description = "The name of your application" - default = "servicebusapp" + description = "The name of your application." + default = "single-namespaces-servicebus" } variable "location" { type = string - description = "The Azure region where all resources in this example should be created" + description = "The Azure region where all resources in this example should be created." default = "eastus" } variable "sample_tag_value" { type = string - description = "The value of spring-cloud-azure-sample tag" + description = "The value of spring-cloud-azure-sample tag." default = "true" } diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/README.md b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/README.md index bbfc7ea0e..5f88e135b 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/README.md +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/README.md @@ -1,68 +1,154 @@ -# Sample for Spring JMS with Azure Service Bus Queue Spring Cloud client library for Java +# Sample for Spring JMS with Azure Service Bus Queue Spring Cloud client library for Java -## Key concepts +This sample project demonstrates how to use Spring JMS for Azure Service Bus Queue via Spring Boot Starter `spring-cloud-azure-starter-servicebus-jms`. -This sample project demonstrates how to use Spring JMS for Azure Service Bus Queue via Spring Boot Starter `spring-cloud-azure-starter-servicebus-jms`. -Running this sample will be charged by Azure. You can check the usage and bill at this [link](https://azure.microsoft.com/account/). +## What You Will Build +You will build an application using Spring JMS to send and receive messages for Azure Service Bus Queue. -## Getting started +## What You Need +- [An Azure subscription](https://azure.microsoft.com/free/) +- [Terraform](https://www.terraform.io/) +- [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli) +- [JDK8](https://www.oracle.com/java/technologies/downloads/) or later +- Maven +- You can also import the code straight into your IDE: + - [IntelliJ IDEA](https://www.jetbrains.com/idea/download) +## Provision Azure Resources Required to Run This Sample +This sample will create Azure resources using Terraform. If you choose to run it without using Terraform to provision resources, please pay attention to: +> [!IMPORTANT] +> If you choose to use a security principal to authenticate and authorize with Azure Active Directory for accessing an Azure resource +> please refer to [Authorize access with Azure AD](https://microsoft.github.io/spring-cloud-azure/docs/current/reference/html/index.html#authorize-access-with-azure-active-directory) to make sure the security principal has been granted the sufficient permission to access the Azure resource. -### Create Service Bus on Azure +### Authenticate Using the Azure CLI +Terraform must authenticate to Azure to create infrastructure. -1. Go to [Azure portal](https://portal.azure.com/) and create the service by following this [link](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-create-namespace-portal). +In your terminal, use the Azure CLI tool to setup your account permissions locally. -## Examples -### Config the sample +```shell +az login +``` -1. Update [application.properties](https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/src/main/resources/application.properties) - ```properties - # Fill service bus namespace connection string copied from portal - spring.jms.servicebus.connection-string=[servicebus-namespace-connection-string] +Your browser window will open and you will be prompted to enter your Azure login credentials. After successful authentication, your terminal will display your subscription information. You do not need to save this output as it is saved in your system for Terraform to use. - # The idle timeout in milliseconds after which the connection will be failed if the peer sends no AMQP frames - # Default is 1800000 - spring.jms.servicebus.idle-timeout=[idle-timeout] - - #Fill service bus pricing tier according to the one you created. Supported values are premium, standard and basic. - spring.jms.servicebus.pricing-tier=[pricing-tier] - ``` +```shell +You have logged in. Now let us find all the subscriptions to which you have access... -2. Specify your queue name. Update `QUEUE_NAME` in [QueueSendController] and [QueueReceiveController] . - -### How to run -1. Run with Maven - ``` - cd azure-spring-boot-samples/servicebus/spring-cloud-azure-starter-servicebus-jms - mvn spring-boot:run - ``` +[ + { + "cloudName": "AzureCloud", + "homeTenantId": "home-Tenant-Id", + "id": "subscription-id", + "isDefault": true, + "managedByTenants": [], + "name": "Subscription-Name", + "state": "Enabled", + "tenantId": "0envbwi39-TenantId", + "user": { + "name": "your-username@domain.com", + "type": "user" + } + } +] +``` + +If you have more than one subscription, specify the subscription-id you want to use with command below: +```shell +az account set --subscription +``` + +### Provision the Resources + +After login Azure CLI with your account, now you can use the terraform script to create Azure Resources. + +```shell +# In the root directory of the sample +# Initialize your Terraform configuration +terraform -chdir=./terraform init + +# Apply your Terraform Configuration +# Type `yes` at the confirmation prompt to proceed. +terraform -chdir=./terraform apply + +``` + + + + +It may take a few minutes to run the script. After successful running, you will see prompt information like below: + +```shell + +azurecaf_name.resource_group: Creating... +azurecaf_name.azurecaf_name_servicebus: Creating... +azurecaf_name.servicebus_namespace_authorization_rule: Creating... +azurecaf_name.servicebus_namespace_authorization_rule: Creation complete after ... +azurecaf_name.azurecaf_name_servicebus: Creation complete after 0s ... +azurecaf_name.resource_group: Creation complete after ... +azurerm_resource_group.main: Creating... +azurerm_resource_group.main: Creation complete after ... +... +azurerm_servicebus_namespace.servicebus_namespace: Creation complete after ... +azurerm_servicebus_queue.queue: Creating... +azurerm_servicebus_namespace_authorization_rule.authorization_rule: Creating... +azurerm_servicebus_queue.queue: Creation complete after 6s ... +azurerm_servicebus_namespace_authorization_rule.authorization_rule: Still creating... [10s elapsed] +azurerm_servicebus_namespace_authorization_rule.authorization_rule: Creation complete ... + +Apply complete! Resources: 7 added, 0 changed, 0 destroyed. -2. Send a POST request to service bus queue. +Outputs: + +... + +``` + +You can go to [Azure portal](https://ms.portal.azure.com/) in your web browser to check the resources you created. + +### Export Output to Your Local Environment +Running the command below to export environment values: + +```shell + source ./terraform/setup_env.sh +``` + +## Run Locally + +In your terminal, run `mvn clean spring-boot:run`. + + +```shell +mvn clean spring-boot:run +``` + +## Verify This Sample + + +1. Send a POST request to service bus queue. ``` - $ curl -X POST localhost:8080/queue?message=hello + $ curl -d "" http://localhost:8080/queue?message=hello ``` - -3. Verify in your app's logs that a similar message was posted: + +2. Verify in your app's logs that a similar message was posted: ``` Sending message + ... Received message from queue: hello ``` - -4. Delete the resources on [Azure Portal](https://ms.portal.azure.com/) to avoid extra charges. -## Troubleshooting -## Next steps -Please check the following table for reference links of detailed Service Bus usage. -Type | Reference Link ---- | --- -`Queues` | [https://docs.microsoft.com/azure/service-bus-messaging/service-bus-java-how-to-use-queues](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-java-how-to-use-queues) +## Clean Up Resources +After running the sample, if you don't want to run the sample, remember to destroy the Azure resources you created to avoid unnecessary billing. + +The terraform destroy command terminates resources managed by your Terraform project. +To destroy the resources you created. + +```shell +terraform -chdir=./terraform destroy +``` + -## Contributing - -[QueueSendController]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/src/main/java/com/azure/spring/sample/jms/queue/QueueSendController.java -[QueueReceiveController]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/src/main/java/com/azure/spring/sample/jms/queue/QueueReceiveController.java diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/src/main/resources/application.properties b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/src/main/resources/application.properties deleted file mode 100644 index d9ee4a90f..000000000 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/src/main/resources/application.properties +++ /dev/null @@ -1,5 +0,0 @@ -spring.jms.servicebus.connection-string=[servicebus-namespace-connection-string] - -spring.jms.servicebus.idle-timeout=[idle-timeout] - -spring.jms.servicebus.pricing-tier=[pricing-tier] diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/src/main/resources/application.yaml b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/src/main/resources/application.yaml new file mode 100644 index 000000000..4e5a8064f --- /dev/null +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/src/main/resources/application.yaml @@ -0,0 +1,6 @@ +spring: + jms: + servicebus: + connection-string: ${SERVICEBUS_NAMESPACE_CONNECTION_STRING} + idle-timeout: 1800000 + pricing-tier: ${PRICING_TIER} diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/main.tf b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/main.tf new file mode 100644 index 000000000..c63f12694 --- /dev/null +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/main.tf @@ -0,0 +1,82 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 2.75" + } + azurecaf = { + source = "aztfmod/azurecaf" + version = "1.2.10" + } + } +} + +provider "azurerm" { + features {} +} + +resource "azurecaf_name" "resource_group" { + name = var.application_name + resource_type = "azurerm_resource_group" + random_length = 5 + clean_input = true +} + +resource "azurerm_resource_group" "main" { + name = azurecaf_name.resource_group.result + location = var.location + + tags = { + "terraform" = "true" + "application-name" = var.application_name + "spring-cloud-azure-sample" = var.sample_tag_value + } +} + +resource "azurecaf_name" "azurecaf_name_servicebus" { + name = var.application_name + resource_type = "azurerm_servicebus_namespace" + random_length = 5 + clean_input = true +} + +resource "azurerm_servicebus_namespace" "servicebus_namespace" { + name = azurecaf_name.azurecaf_name_servicebus.result + location = var.location + resource_group_name = azurerm_resource_group.main.name + + sku = var.pricing_tier + zone_redundant = false + + tags = { + "spring-cloud-azure-sample" = var.sample_tag_value + } +} + +resource "azurecaf_name" "servicebus_namespace_authorization_rule" { + name = var.application_name + resource_type = "azurerm_servicebus_namespace_authorization_rule" +} + +resource "azurerm_servicebus_namespace_authorization_rule" "authorization_rule" { + name = azurecaf_name.servicebus_namespace_authorization_rule.result + namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name + resource_group_name = azurerm_resource_group.main.name + + listen = true + send = true + manage = true +} + +resource "azurerm_servicebus_queue" "queue" { + name = "que001" + namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name + resource_group_name = azurerm_resource_group.main.name + + enable_partitioning = false + max_delivery_count = 10 + lock_duration = "PT30S" + max_size_in_megabytes = 1024 + requires_session = false + default_message_ttl = "P14D" +} diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/outputs.tf b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/outputs.tf new file mode 100644 index 000000000..27d2bb201 --- /dev/null +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/outputs.tf @@ -0,0 +1,10 @@ +output "SERVICEBUS_NAMESPACE_CONNECTION_STRING" { + value = azurerm_servicebus_namespace.servicebus_namespace.default_primary_connection_string + description = "The connection_string of servicebus namespace." + sensitive = true +} + +output "PRICING_TIER" { + value = var.pricing_tier + description = "The pricing tier of Service Bus." +} \ No newline at end of file diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/setup_env.sh b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/setup_env.sh new file mode 100644 index 000000000..fe2880e0b --- /dev/null +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/setup_env.sh @@ -0,0 +1,2 @@ +export SERVICEBUS_NAMESPACE_CONNECTION_STRING=$(terraform -chdir=./terraform output -raw SERVICEBUS_NAMESPACE_CONNECTION_STRING) +export PRICING_TIER=$(terraform -chdir=./terraform output -raw PRICING_TIER) \ No newline at end of file diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/variables.tf b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/variables.tf new file mode 100644 index 000000000..631172409 --- /dev/null +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/variables.tf @@ -0,0 +1,23 @@ +variable "application_name" { + type = string + description = "The name of your application." + default = "servicebus-jms-queue" +} + +variable "location" { + type = string + description = "The Azure region where all resources in this example should be created." + default = "eastus" +} + +variable "sample_tag_value" { + type = string + description = "The value of spring-cloud-azure-sample tag." + default = "true" +} + +variable "pricing_tier" { + type = string + description = "The pricing tier of Service Bus." + default = "Standard" +} \ No newline at end of file diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/README.md b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/README.md index 4a7db667a..584bd2c26 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/README.md +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/README.md @@ -1,73 +1,151 @@ -# Sample for Spring JMS with Azure Service Bus Topic Spring Cloud client library for Java -## Key concepts +# Sample for Spring JMS with Azure Service Bus Topic Spring Cloud client library for Java This sample project demonstrates how to use Spring JMS Topic for Azure Service Bus via Spring Boot Starter `spring-cloud-azure-starter-servicebus-jms`. -Running this sample will be charged by Azure. You can check the usage and bill at this [link](https://azure.microsoft.com/account/). +## What You Will Build +You will build an application using Spring JMS to send and receive messages for Azure Service Bus Topic. -## Getting started +## What You Need +- [An Azure subscription](https://azure.microsoft.com/free/) +- [Terraform](https://www.terraform.io/) +- [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli) +- [JDK8](https://www.oracle.com/java/technologies/downloads/) or later +- Maven +- You can also import the code straight into your IDE: + - [IntelliJ IDEA](https://www.jetbrains.com/idea/download) +## Provision Azure Resources Required to Run This Sample +This sample will create Azure resources using Terraform. If you choose to run it without using Terraform to provision resources, please pay attention to: +> [!IMPORTANT] +> If you choose to use a security principal to authenticate and authorize with Azure Active Directory for accessing an Azure resource +> please refer to [Authorize access with Azure AD](https://microsoft.github.io/spring-cloud-azure/docs/current/reference/html/index.html#authorize-access-with-azure-active-directory) to make sure the security principal has been granted the sufficient permission to access the Azure resource. -### Create Service Bus on Azure -1. Go to [Azure portal](https://portal.azure.com/) and create the service by following this [link](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-create-namespace-portal). +### Authenticate Using the Azure CLI +Terraform must authenticate to Azure to create infrastructure. +In your terminal, use the Azure CLI tool to setup your account permissions locally. -## Examples -### Config the sample -1. Update [application.properties](https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.properties) +```shell +az login +``` - ```properties - # Fill service bus namespace connection string copied from portal - spring.jms.servicebus.connection-string=[servicebus-namespace-connection-string] - - # The JMS client id needs to be specified when using topic and durable subscription - # Default is empty string - spring.jms.servicebus.topic-client-id=[topic-client-id] - - # The idle timeout in milliseconds after which the connection will be failed if the peer sends no AMQP frames - # Default is 1800000 - spring.jms.servicebus.idle-timeout=[idle-timeout] - - #Fill service bus pricing tier according to the one you created. Supported values are premium and standard. - spring.jms.servicebus.pricing-tier=[pricing-tier] - ``` +Your browser window will open and you will be prompted to enter your Azure login credentials. After successful authentication, your terminal will display your subscription information. You do not need to save this output as it is saved in your system for Terraform to use. -2. Specify your topic name and subscription name. Update `TOPIC_NAME` in [TopicSendController] and [TopicReceiveController], and `SUBSCRIPTION_NAME` in [TopicReceiveController]. +```shell +You have logged in. Now let us find all the subscriptions to which you have access... + +[ + { + "cloudName": "AzureCloud", + "homeTenantId": "home-Tenant-Id", + "id": "subscription-id", + "isDefault": true, + "managedByTenants": [], + "name": "Subscription-Name", + "state": "Enabled", + "tenantId": "0envbwi39-TenantId", + "user": { + "name": "your-username@domain.com", + "type": "user" + } + } +] +``` + +If you have more than one subscription, specify the subscription-id you want to use with command below: +```shell +az account set --subscription +``` + +### Provision the Resources + +After login Azure CLI with your account, now you can use the terraform script to create Azure Resources. + +```shell +# In the root directory of the sample +# Initialize your Terraform configuration +terraform -chdir=./terraform init + +# Apply your Terraform Configuration +# Type `yes` at the confirmation prompt to proceed. +terraform -chdir=./terraform apply + +``` + + + + +It may take a few minutes to run the script. After successful running, you will see prompt information like below: + +```shell -### How to run -1. Run with Maven: - ``` - cd azure-spring-boot-samples/servicebus/spring-cloud-azure-starter-servicebus-jms - mvn spring-boot:run - ``` -2. Send a POST request to service bus topic. +azurecaf_name.azurecaf_name_servicebus: Creating... +azurecaf_name.resource_group: Creating... +azurecaf_name.servicebus_namespace_authorization_rule: Creating... +azurecaf_name.resource_group: Creation complete after 0s ... +azurecaf_name.servicebus_namespace_authorization_rule: Creation complete ... +azurecaf_name.azurecaf_name_servicebus: Creation complete ... +... +azurerm_servicebus_topic.application: Creating... +azurerm_servicebus_namespace_authorization_rule.authorization_rule: Creating... +azurerm_servicebus_topic.application: Creation complete after ... +azurerm_servicebus_subscription.application: Creating... +azurerm_servicebus_namespace_authorization_rule.authorization_rule: Still creating... [10s elapsed] +azurerm_servicebus_subscription.application: Creation complete after ... +azurerm_servicebus_namespace_authorization_rule.authorization_rule: Creation complete ... + +Apply complete! Resources: 8 added, 0 changed, 0 destroyed. + +Outputs: +... + +``` + +You can go to [Azure portal](https://ms.portal.azure.com/) in your web browser to check the resources you created. + +### Export Output to Your Local Environment +Running the command below to export environment values: + +```shell + source ./terraform/setup_env.sh +``` + +## Run Locally + +In your terminal, run `mvn clean spring-boot:run`. + + +```shell +mvn clean spring-boot:run +``` + +## Verify This Sample + +1. Send a POST request to service bus topic. ``` - $ curl -X POST localhost:8080/topic?message=hello + $ curl http://localhost:8080/topic?message=hello -d "" ``` -3. Verify in your app's logs that a similar message was posted: +2. Verify in your app's logs that a similar message was posted: ``` Sending message + ... Received message from topic: hello ``` - -4. Delete the resources on [Azure Portal](https://ms.portal.azure.com/) to avoid extra charges. -## Troubleshooting -## Next steps -Please check the following table for reference links of detailed Service Bus usage. +## Clean Up Resources +After running the sample, if you don't want to run the sample, remember to destroy the Azure resources you created to avoid unnecessary billing. + +The terraform destroy command terminates resources managed by your Terraform project. +To destroy the resources you created. + +```shell +terraform -chdir=./terraform destroy +``` -Type | Reference Link ---- | --- -`Topics` | [https://docs.microsoft.com/azure/service-bus-messaging/service-bus-java-how-to-use-topics-subscriptions](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-java-how-to-use-topics-subscriptions) -`Subscriptions` | [https://docs.microsoft.com/azure/service-bus-messaging/service-bus-java-how-to-use-topics-subscriptions](https://docs.microsoft.com/azure/service-bus-messaging/service-bus-java-how-to-use-topics-subscriptions) -## Contributing - -[TopicSendController]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/java/com/azure/spring/sample/jms/topic/TopicSendController.java -[TopicReceiveController]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/java/com/azure/spring/sample/jms/topic/TopicReceiveController.java diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.properties b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.properties deleted file mode 100644 index c60334621..000000000 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.properties +++ /dev/null @@ -1,7 +0,0 @@ -spring.jms.servicebus.connection-string=[servicebus-namespace-connection-string] - -spring.jms.servicebus.topic-client-id=[topic-client-id] - -spring.jms.servicebus.idle-timeout=[idle-timeout] - -spring.jms.servicebus.pricing-tier=[pricing-tier] diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.yaml b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.yaml new file mode 100644 index 000000000..93c60e4f7 --- /dev/null +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.yaml @@ -0,0 +1,11 @@ +spring: + jms: + servicebus: + connection-string: ${SERVICEBUS_NAMESPACE_CONNECTION_STRING} + idle-timeout: 1800000 + pricing-tier: ${PRICING_TIER} + topic-client-id: ${TOPIC_CLIENT_ID} + + + + diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/main.tf b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/main.tf new file mode 100644 index 000000000..0234cd5fc --- /dev/null +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/main.tf @@ -0,0 +1,83 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 2.75" + } + azurecaf = { + source = "aztfmod/azurecaf" + version = "1.2.10" + } + } +} + +provider "azurerm" { + features {} +} + +resource "azurecaf_name" "resource_group" { + name = var.application_name + resource_type = "azurerm_resource_group" + random_length = 5 + clean_input = true +} + +resource "azurerm_resource_group" "main" { + name = azurecaf_name.resource_group.result + location = var.location + + tags = { + "terraform" = "true" + "application-name" = var.application_name + "spring-cloud-azure-sample" = var.sample_tag_value + } +} + +resource "azurecaf_name" "azurecaf_name_servicebus" { + name = var.application_name + resource_type = "azurerm_servicebus_namespace" + random_length = 5 + clean_input = true +} + +resource "azurerm_servicebus_namespace" "servicebus_namespace" { + name = azurecaf_name.azurecaf_name_servicebus.result + location = var.location + resource_group_name = azurerm_resource_group.main.name + + sku = var.pricing_tier + zone_redundant = false + + tags = { + "spring-cloud-azure-sample" = var.sample_tag_value + } +} + +resource "azurecaf_name" "servicebus_namespace_authorization_rule" { + name = var.application_name + resource_type = "azurerm_servicebus_namespace_authorization_rule" +} + +resource "azurerm_servicebus_namespace_authorization_rule" "authorization_rule" { + name = azurecaf_name.servicebus_namespace_authorization_rule.result + namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name + resource_group_name = azurerm_resource_group.main.name + + listen = true + send = true + manage = true +} + +resource "azurerm_servicebus_topic" "application" { + name = "tpc001" + namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name + resource_group_name = azurerm_resource_group.main.name +} + +resource "azurerm_servicebus_subscription" "application" { + name = "sub001" + resource_group_name = azurerm_resource_group.main.name + namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name + topic_name = azurerm_servicebus_topic.application.name + max_delivery_count = 1 +} diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/outputs.tf b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/outputs.tf new file mode 100644 index 000000000..b4e430ffa --- /dev/null +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/outputs.tf @@ -0,0 +1,15 @@ +output "CONNECTION_STRING" { + value = azurerm_servicebus_namespace.servicebus_namespace.default_primary_connection_string + description = "The connection_string of servicebus namespace." + sensitive = true +} + +output "PRICING_TIER" { + value = var.pricing_tier + description = "The pricing tier of Service Bus." +} + +output "TOPIC_CLIENT_ID" { + value = var.topic_client_id + description = "The topic client id." +} \ No newline at end of file diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/setup_env.sh b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/setup_env.sh new file mode 100644 index 000000000..7c3634e01 --- /dev/null +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/setup_env.sh @@ -0,0 +1,3 @@ +export SERVICEBUS_NAMESPACE_CONNECTION_STRING=$(terraform -chdir=./terraform output -raw CONNECTION_STRING) +export PRICING_TIER=$(terraform -chdir=./terraform output -raw PRICING_TIER) +export TOPIC_CLIENT_ID=$(terraform -chdir=./terraform output -raw TOPIC_CLIENT_ID) diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/variables.tf b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/variables.tf new file mode 100644 index 000000000..cb9eb64c6 --- /dev/null +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/variables.tf @@ -0,0 +1,31 @@ +variable "application_name" { + type = string + description = "The name of your application." + default = "servicebus-jms-topic" +} + +variable "location" { + type = string + description = "The Azure region where all resources in this example should be created." + default = "eastus" +} + +variable "sample_tag_value" { + type = string + description = "The value of spring-cloud-azure-sample tag." + default = "true" +} + +variable "pricing_tier" { + type = string + description = "The pricing tier of Service Bus." + default = "Standard" +} + +variable "topic_client_id" { + type = string + description = "The topic client id." + default = "topic-client-id" +} + + diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md index 490660afa..f86327f28 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md @@ -1,131 +1,170 @@ -# Spring Cloud Azure Stream Binder for Multiple Service Bus Namespaces Code Sample shared library for Java +# Spring Cloud Azure Stream Binder for Multiple Service Bus Namespaces Code Sample shared library for Java -## Key concepts -This code sample demonstrates how to use the Spring Cloud Stream Binder for +This code sample demonstrates how to use the Spring Cloud Stream Binder for multiple Azure Service Bus namespaces. In this sample you will bind to two Service Bus namespaces separately through a queue binder and a topic binder..The sample app has two operating modes. One way is to expose a Restful API to receive string message, another way is to automatically provide string messages. These messages are published to a service bus. The sample will also consume messages from the same service bus. -## Getting started - -Running this sample will be charged by Azure. You can check the usage -and bill at [this link][azure-account]. - - - -### Create Azure resources - -1. Create a queue and a topic in different Service Bus namespaces. - 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 stream binding related properties in - [application.yaml][application.yaml]. If you choose to use - service principal or managed identity, update the [application-sp.yaml][application-sp.yaml] or - [application-mi.yaml][application-mi.yaml] respectively. - - ```yaml - spring: - cloud: - stream: - #To specify which functional bean to bind to the external destination(s) exposed by the bindings - function: - definition: consume1;supply1;consume2;supply2 - bindings: - consume1-in-0: - destination: ${AZURE_SERVICEBUS_TOPIC_NAME} - group: ${AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME} - supply1-out-0: - destination: ${AZURE_SERVICEBUS_TOPIC_NAME} - consume2-in-0: - binder: servicebus-2 - destination: ${AZURE_SERVICEBUS_QUEUE_NAME} - supply2-out-0: - binder: servicebus-2 - destination: ${AZURE_SERVICEBUS_QUEUE_NAME} - binders: - servicebus-1: - type: servicebus - default-candidate: true - environment: - spring: - cloud: - azure: - servicebus: - connection-string: ${AZURE_SERVICEBUS_CONNECTION_STRING_1} - servicebus-2: - type: servicebus - default-candidate: false - environment: - spring: - cloud: - azure: - servicebus: - connection-string: ${AZURE_SERVICEBUS_CONNECTION_STRING_2} - servicebus: - bindings: - consume1-in-0: - consumer: - checkpoint-mode: MANUAL - supply1-out-0: - producer: - entity-type: topic - consume2-in-0: - consumer: - checkpoint-mode: MANUAL - supply2-out-0: - producer: - entity-type: queue - poller: - initial-delay: 0 - fixed-delay: 1000 - - ``` - -> The **defaultCandidate** configuration item: -Whether the binder configuration is a candidate for being considered a -default binder, or can be used only when explicitly referenced. This -allows adding binder configurations without interfering with the default -processing. - ->[!Important] -> -> When using the Restful API to send messages, the **Active profiles** must contain `manual`. - -1. Run the `mvn clean spring-boot:run` in the root of the code sample - to get the app running. - -1. Send a POST request to test the default binder - - $ curl -X POST http://localhost:8080/messages1?message=hello - -1. Verify in your app’s logs that a similar message was posted: - - [1] New message1 received: 'hello' - [1] Message1 'hello' successfully checkpointed - -1. Send another POST request to test the other binder - - $ curl -X POST http://localhost:8080/messages2?message=hello - -1. Verify in your app’s logs that a similar message was posted: +## What You Will Build +You will build an application using Spring Cloud Stream to send and receive messages for multiple Azure Service Bus namespaces. + +## What You Need + +- [An Azure subscription](https://azure.microsoft.com/free/) +- [Terraform](https://www.terraform.io/) +- [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli) +- [JDK8](https://www.oracle.com/java/technologies/downloads/) or later +- Maven +- You can also import the code straight into your IDE: + - [IntelliJ IDEA](https://www.jetbrains.com/idea/download) + +## Provision Azure Resources Required to Run This Sample +This sample will create Azure resources using Terraform. If you choose to run it without using Terraform to provision resources, please pay attention to: +> [!IMPORTANT] +> If you choose to use a security principal to authenticate and authorize with Azure Active Directory for accessing an Azure resource +> please refer to [Authorize access with Azure AD](https://microsoft.github.io/spring-cloud-azure/docs/current/reference/html/index.html#authorize-access-with-azure-active-directory) to make sure the security principal has been granted the sufficient permission to access the Azure resource. + +### Authenticate Using the Azure CLI +Terraform must authenticate to Azure to create infrastructure. + +In your terminal, use the Azure CLI tool to setup your account permissions locally. + +```shell +az login +``` + +Your browser window will open and you will be prompted to enter your Azure login credentials. After successful authentication, your terminal will display your subscription information. You do not need to save this output as it is saved in your system for Terraform to use. + +```shell +You have logged in. Now let us find all the subscriptions to which you have access... + +[ + { + "cloudName": "AzureCloud", + "homeTenantId": "home-Tenant-Id", + "id": "subscription-id", + "isDefault": true, + "managedByTenants": [], + "name": "Subscription-Name", + "state": "Enabled", + "tenantId": "0envbwi39-TenantId", + "user": { + "name": "your-username@domain.com", + "type": "user" + } + } +] +``` + +If you have more than one subscription, specify the subscription-id you want to use with command below: +```shell +az account set --subscription +``` + +### Provision the Resources + +After login Azure CLI with your account, now you can use the terraform script to create Azure Resources. + +```shell +# In the root directory of the sample +# Initialize your Terraform configuration +terraform -chdir=./terraform init + +# Apply your Terraform Configuration +# Type `yes` at the confirmation prompt to proceed. +terraform -chdir=./terraform apply + +``` + + + + +It may take a few minutes to run the script. After successful running, you will see prompt information like below: + +```shell + +azurecaf_name.azurecaf_name_authorization_rule_02: Creating... +azurecaf_name.azurecaf_name_servicebus_02: Creating... +azurecaf_name.resource_group: Creating... +azurecaf_name.servicebus_01: Creating... +azurecaf_name.azurecaf_name_authorization_rule_01: Creating... +... +azurecaf_name.azurecaf_name_servicebus_02: Creation complete after 0s ... +azurecaf_name.resource_group: Creation complete after 0s ... +azurerm_resource_group.main: Creating... +azurerm_resource_group.main: Creation complete after 3s ... +azurerm_servicebus_namespace.servicebus_namespace_02: Creating... +... +azurerm_servicebus_subscription.servicebus_namespace_01_sub: Creation complete ... +azurerm_servicebus_queue.servicebus_namespace_02_queue: Creation complete ... +... +azurerm_role_assignment.role_servicebus_data_owner_01: Creation complete ... +azurerm_role_assignment.role_servicebus_data_owner_02: Creation complete ... + +Apply complete! Resources: 15 added, 0 changed, 0 destroyed. + +Outputs: + +... +``` + +You can go to [Azure portal](https://ms.portal.azure.com/) in your web browser to check the resources you created. + +### Export Output to Your Local Environment +Running the command below to export environment values: + +```shell + source ./terraform/setup_env.sh +``` + +## Run Locally + +In your terminal, run `mvn clean spring-boot:run`. + + +```shell +mvn clean spring-boot:run +``` + +## Verify This Sample + + +1. Verify in your app’s logs that similar messages were posted: + +```shell +... +Message 'Hello world1, 3' successfully checkpointed +... +... +Message 'Hello world1, 4' successfully checkpointed +... +... +Message 'Hello world2, 3' successfully checkpointed +... +... +Message 'Hello world2, 5' successfully checkpointed +... +... +``` [2] New message2 received: 'hello' [2] Message2 'hello' successfully checkpointed -6. Delete the resources on [Azure Portal][azure-portal] - to avoid unexpected charges. + +## Clean Up Resources +After running the sample, if you don't want to run the sample, remember to destroy the Azure resources you created to avoid unnecessary billing. + +The terraform destroy command terminates resources managed by your Terraform project. +To destroy the resources you created. + +```shell +terraform -chdir=./terraform destroy +``` + ## Enhancement -### Configuration Options +### Configuration Options The binder provides the following configuration options: @@ -135,7 +174,7 @@ It supports the following configurations with the format of `spring.cloud.stream **_sync_** -Whether the producer should act in a synchronous manner with respect to writing messages into a stream. If true, the +Whether the producer should act in a synchronous manner with respect to writing messages into a stream. If true, the producer will wait for a response after a send operation. Default: `false` @@ -145,7 +184,7 @@ Default: `false` Effective only if `sync` is set to true. The amount of time to wait for a response after a send operation, in milliseconds. Default: `10000` - + ##### Service Bus Consumer Properties It supports the following configurations with the format of `spring.cloud.stream.servicebus.bindings..consumer`. @@ -195,9 +234,9 @@ Default: `false` **_requeueRejected_** -Controls if is a message that trigger any exception in consumer will be force to DLQ. +Controls if is a message that trigger any exception in consumer will be force to DLQ. Set it to `true` if a message that trigger any exception in consumer will be force to DLQ. -Set it to `false` if a message that trigger any exception in consumer will be re-queued. +Set it to `false` if a message that trigger any exception in consumer will be re-queued. Default: `false` @@ -253,26 +292,5 @@ SessionID | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.SESSION TimeToLive | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.TIME_TO_LIVE | Duration | N/A To | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.TO | String | N/A -## Troubleshooting - -## Next steps - -## Contributing - - - -[azure-account]: https://azure.microsoft.com/account/ -[azure-portal]: https://ms.portal.azure.com/ -[create-service-bus]: https://docs.microsoft.com/azure/service-bus-messaging/service-bus-create-namespace-portal -[create-sp-using-azure-cli]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/create-sp-using-azure-cli.md -[create-managed-identity]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/create-managed-identity.md -[deploy-spring-boot-application-to-app-service]: https://docs.microsoft.com/java/azure/spring-framework/deploy-spring-boot-java-app-with-maven-plugin?toc=%2Fazure%2Fapp-service%2Fcontainers%2Ftoc.json&view=azure-java-stable -[deploy-to-app-service-via-ftp]: https://docs.microsoft.com/azure/app-service/deploy-ftp -[managed-identities]: https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/ -[role-assignment]: https://docs.microsoft.com/azure/role-based-access-control/role-assignments-portal -[application.yaml]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/src/main/resources/application.yaml -[application-mi.yaml]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/src/main/resources/application-mi.yaml -[application-sp.yaml]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/src/main/resources/application-sp.yaml - diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/src/main/resources/application-mi.yaml b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/src/main/resources/application-mi.yaml deleted file mode 100644 index 1a23169f9..000000000 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/src/main/resources/application-mi.yaml +++ /dev/null @@ -1,58 +0,0 @@ -spring: - cloud: - azure: - credential: - managed-identity-client-id: ${AZURE_MANAGED_IDENTITY_CLIENT_ID} - profile: - tenant-id: ${AZURE_TENANT_ID} - stream: - function: - definition: consume1;supply1;consume2;supply2 - bindings: - consume1-in-0: - destination: ${AZURE_SERVICEBUS_TOPIC_NAME} - group: ${AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME} - supply1-out-0: - destination: ${AZURE_SERVICEBUS_TOPIC_NAME} - consume2-in-0: - binder: servicebus-2 - destination: ${AZURE_SERVICEBUS_QUEUE_NAME} - supply2-out-0: - binder: servicebus-2 - destination: ${AZURE_SERVICEBUS_QUEUE_NAME} - binders: - servicebus-1: - type: servicebus - default-candidate: true - environment: - spring: - cloud: - azure: - servicebus: - connection-string: ${AZURE_SERVICEBUS_CONNECTION_STRING_1} - servicebus-2: - type: servicebus - default-candidate: false - environment: - spring: - cloud: - azure: - servicebus: - connection-string: ${AZURE_SERVICEBUS_CONNECTION_STRING_2} - servicebus: - bindings: - consume1-in-0: - consumer: - checkpoint-mode: MANUAL - supply1-out-0: - producer: - entity-type: topic - consume2-in-0: - consumer: - checkpoint-mode: MANUAL - supply2-out-0: - producer: - entity-type: queue - poller: - initial-delay: 0 - fixed-delay: 1000 \ No newline at end of file diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/src/main/resources/application-sp.yaml b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/src/main/resources/application-sp.yaml deleted file mode 100644 index ed24638d3..000000000 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/src/main/resources/application-sp.yaml +++ /dev/null @@ -1,59 +0,0 @@ -spring: - cloud: - azure: - credential: - client-id: ${AZURE_CLIENT_ID} - client-secret: ${AZURE_CLIENT_SECRET} - profile: - tenant-id: ${AZURE_TENANT_ID} - stream: - function: - definition: consume1;supply1;consume2;supply2 - bindings: - consume1-in-0: - destination: ${AZURE_SERVICEBUS_TOPIC_NAME} - group: ${AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME} - supply1-out-0: - destination: ${AZURE_SERVICEBUS_TOPIC_NAME} - consume2-in-0: - binder: servicebus-2 - destination: ${AZURE_SERVICEBUS_QUEUE_NAME} - supply2-out-0: - binder: servicebus-2 - destination: ${AZURE_SERVICEBUS_QUEUE_NAME} - binders: - servicebus-1: - type: servicebus - default-candidate: true - environment: - spring: - cloud: - azure: - servicebus: - connection-string: ${AZURE_SERVICEBUS_CONNECTION_STRING_1} - servicebus-2: - type: servicebus - default-candidate: false - environment: - spring: - cloud: - azure: - servicebus: - connection-string: ${AZURE_SERVICEBUS_CONNECTION_STRING_2} - servicebus: - bindings: - consume1-in-0: - consumer: - checkpoint-mode: MANUAL - supply1-out-0: - producer: - entity-type: topic - consume2-in-0: - consumer: - checkpoint-mode: MANUAL - supply2-out-0: - producer: - entity-type: queue - poller: - initial-delay: 0 - fixed-delay: 1000 \ No newline at end of file diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/src/main/resources/application.yaml b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/src/main/resources/application.yaml index 86b60a00d..e5496a6c5 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/src/main/resources/application.yaml +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/src/main/resources/application.yaml @@ -24,7 +24,7 @@ spring: cloud: azure: servicebus: - connection-string: ${AZURE_SERVICEBUS_CONNECTION_STRING_1} + namespace: ${AZURE_SERVICEBUS_NAMESPACE_01} servicebus-2: type: servicebus default-candidate: false @@ -33,7 +33,7 @@ spring: cloud: azure: servicebus: - connection-string: ${AZURE_SERVICEBUS_CONNECTION_STRING_2} + namespace: ${AZURE_SERVICEBUS_NAMESPACE_02} servicebus: bindings: consume1-in-0: diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/main.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/main.tf new file mode 100644 index 000000000..bfacedd7f --- /dev/null +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/main.tf @@ -0,0 +1,150 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 2.75" + } + azurecaf = { + source = "aztfmod/azurecaf" + version = "1.2.10" + } + } +} + +provider "azurerm" { + features {} +} + +# resource_group +resource "azurecaf_name" "resource_group" { + name = var.application_name + resource_type = "azurerm_resource_group" + random_length = 5 + clean_input = true +} + +resource "azurerm_resource_group" "main" { + name = azurecaf_name.resource_group.result + location = var.location + + tags = { + "terraform" = "true" + "application-name" = var.application_name + "spring-cloud-azure-sample" = var.sample_tag_value + } +} + +data "azurerm_client_config" "client_config" { +} + +# servicebus_namespace_01 with topic and subscription +resource "azurecaf_name" "servicebus_01" { + name = var.application_name + resource_type = "azurerm_servicebus_namespace" + random_length = 5 + clean_input = true +} + +resource "azurerm_servicebus_namespace" "servicebus_namespace_01" { + name = azurecaf_name.servicebus_01.result + location = var.location + resource_group_name = azurerm_resource_group.main.name + + sku = "Standard" + zone_redundant = false + + tags = { + "spring-cloud-azure-sample" = var.sample_tag_value + } +} + +resource "azurecaf_name" "azurecaf_name_authorization_rule_01" { + name = var.application_name + resource_type = "azurerm_servicebus_namespace_authorization_rule" +} + +resource "azurerm_servicebus_namespace_authorization_rule" "namespace_authorization_rule_01" { + name = azurecaf_name.azurecaf_name_authorization_rule_01.result + namespace_name = azurerm_servicebus_namespace.servicebus_namespace_01.name + resource_group_name = azurerm_resource_group.main.name + + listen = true + send = true + manage = true +} + +resource "azurerm_servicebus_topic" "servicebus_namespace_01_topic" { + name = "tpc001" + namespace_name = azurerm_servicebus_namespace.servicebus_namespace_01.name + resource_group_name = azurerm_resource_group.main.name +} + +resource "azurerm_servicebus_subscription" "servicebus_namespace_01_sub" { + name = "sub001" + resource_group_name = azurerm_resource_group.main.name + namespace_name = azurerm_servicebus_namespace.servicebus_namespace_01.name + topic_name = azurerm_servicebus_topic.servicebus_namespace_01_topic.name + max_delivery_count = 1 +} + +resource "azurerm_role_assignment" "role_servicebus_data_owner_01" { + scope = azurerm_servicebus_namespace.servicebus_namespace_01.id + role_definition_name = "Azure Service Bus Data Owner" + principal_id = data.azurerm_client_config.client_config.object_id +} + +# servicebus_namespace_02 with queue +resource "azurecaf_name" "azurecaf_name_servicebus_02" { + name = var.application_name + resource_type = "azurerm_servicebus_namespace" + random_length = 5 + clean_input = true +} + +resource "azurerm_servicebus_namespace" "servicebus_namespace_02" { + name = azurecaf_name.azurecaf_name_servicebus_02.result + location = var.location + resource_group_name = azurerm_resource_group.main.name + + sku = "Standard" + zone_redundant = false + + tags = { + "spring-cloud-azure-sample" = var.sample_tag_value + } +} + +resource "azurecaf_name" "azurecaf_name_authorization_rule_02" { + name = var.application_name + resource_type = "azurerm_servicebus_namespace_authorization_rule" +} + +resource "azurerm_servicebus_namespace_authorization_rule" "namespace_authorization_rule_02" { + name = azurecaf_name.azurecaf_name_authorization_rule_02.result + namespace_name = azurerm_servicebus_namespace.servicebus_namespace_02.name + resource_group_name = azurerm_resource_group.main.name + + listen = true + send = true + manage = true +} + +resource "azurerm_servicebus_queue" "servicebus_namespace_02_queue" { + name = "que001" + namespace_name = azurerm_servicebus_namespace.servicebus_namespace_02.name + resource_group_name = azurerm_resource_group.main.name + + enable_partitioning = false + max_delivery_count = 10 + lock_duration = "PT30S" + max_size_in_megabytes = 1024 + requires_session = false + default_message_ttl = "P14D" +} + +resource "azurerm_role_assignment" "role_servicebus_data_owner_02" { + scope = azurerm_servicebus_namespace.servicebus_namespace_02.id + role_definition_name = "Azure Service Bus Data Owner" + principal_id = data.azurerm_client_config.client_config.object_id +} + diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/outputs.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/outputs.tf new file mode 100644 index 000000000..e370c906c --- /dev/null +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/outputs.tf @@ -0,0 +1,28 @@ +# =======================namespace_01======================= +output "AZURE_SERVICEBUS_NAMESPACE_01" { + value = azurerm_servicebus_namespace.servicebus_namespace_01.name + description = "The service bus namespace 01." +} + +output "AZURE_SERVICEBUS_TOPIC_NAME" { + value = azurerm_servicebus_topic.servicebus_namespace_01_topic.name + description = "The topic name in service bus namespace 01." +} + +output "AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME" { + value = azurerm_servicebus_subscription.servicebus_namespace_01_sub.name + description = "The topic subscription name in service bus namespace 01." +} + +# =======================namespace_02======================= +output "AZURE_SERVICEBUS_NAMESPACE_02" { + value = azurerm_servicebus_namespace.servicebus_namespace_02.name + description = "The service bus namespace 02." +} + +output "AZURE_SERVICEBUS_QUEUE_NAME" { + value = azurerm_servicebus_queue.servicebus_namespace_02_queue.name + description = "The queue name in service bus namespace 02." +} + + diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/setup_env.sh b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/setup_env.sh new file mode 100644 index 000000000..1696e04b1 --- /dev/null +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/setup_env.sh @@ -0,0 +1,6 @@ +export AZURE_SERVICEBUS_NAMESPACE_01=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_NAMESPACE_01) +export AZURE_SERVICEBUS_NAMESPACE_02=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_NAMESPACE_02) +export AZURE_SERVICEBUS_TOPIC_NAME=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_TOPIC_NAME) +export AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME) +export AZURE_SERVICEBUS_QUEUE_NAME=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_QUEUE_NAME) + diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/variables.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/variables.tf new file mode 100644 index 000000000..d2d532a24 --- /dev/null +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/variables.tf @@ -0,0 +1,17 @@ +variable "application_name" { + type = string + description = "The name of your application." + default = "servicebus-multibinders" +} + +variable "location" { + type = string + description = "The Azure region where all resources in this example should be created." + default = "eastus" +} + +variable "sample_tag_value" { + type = string + description = "The value of spring-cloud-azure-sample tag." + default = "true" +} diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/README.md b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/README.md index ac19603b7..a3776301e 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/README.md +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/README.md @@ -1,189 +1,167 @@ -# Spring Cloud Azure Stream Binder for Service Bus queue Sample shared library for Java +# Spring Cloud Azure Stream Binder for Service Bus queue Sample shared library for Java -## Key concepts -This code sample demonstrates how to use the Spring Cloud Stream binder for +This code sample demonstrates how to use the Spring Cloud Stream binder for Azure Service Bus queue. The sample app has two operating modes. One way is to expose a Restful API to receive string message, another way is to automatically provide string messages. These messages are published to a service bus queue. The sample will also consume messages from the same service bus queue. -## Getting started - -Running this sample will be charged by Azure. You can check the usage and bill at -[this link][azure-account]. - - - -### Create Azure resources - -We have several ways to config the Spring Cloud Stream Binder for Service -Bus Queue. You can choose anyone of them. - ->[!Important] -> -> When using the Restful API to send messages, the **Active profiles** must contain `manual`. - -#### Method 1: Connection string based usage - -1. Create Azure Service Bus namespace and queue. - Please see [how to create][create-service-bus]. - -1. Update [application.yaml][application.yaml]. - ```yaml - spring: - cloud: - azure: - servicebus: - connection-string: ${AZURE_SERVICEBUS_CONNECTION_STRING} - stream: - function: - definition: consume;supply - bindings: - consume-in-0: - destination: ${AZURE_SERVICEBUS_QUEUE_NAME} - supply-out-0: - destination: ${AZURE_SERVICEBUS_QUEUE_NAME} - servicebus: - bindings: - consume-in-0: - consumer: - checkpoint-mode: MANUAL - supply-out-0: - producer: - entity-type: queue - poller: - fixed-delay: 1000 - initial-delay: 0 - ``` - -#### Method 2: Service principal based usage - -1. Create a service principal for use in by your app. Please follow - [create service principal from Azure CLI][create-sp-using-azure-cli]. - -1. Create Azure Service Bus namespace and queue. - Please see [how to create][create-service-bus]. - -1. Add Role Assignment for Service Bus. See - [Service principal for Azure resources with Service Bus][role-assignment] - to add role assignment for Service Bus. Assign `Contributor` role for service bus. - -1. Update [application-sp.yaml][application-sp.yaml]. - ```yaml - spring: - cloud: - azure: - credential: - client-id: ${AZURE_CLIENT_ID} - client-secret: ${AZURE_CLIENT_SECRET} - profile: - tenant-id: ${AZURE_TENANT_ID} - servicebus: - namespace: ${AZURE_SERVICEBUS_NAMESPACE} - stream: - function: - definition: consume;supply - bindings: - consume-in-0: - destination: ${AZURE_SERVICEBUS_QUEUE_NAME} - supply-out-0: - destination: ${AZURE_SERVICEBUS_QUEUE_NAME} - servicebus: - bindings: - consume-in-0: - consumer: - checkpoint-mode: MANUAL - supply-out-0: - producer: - entity-type: queue - poller: - fixed-delay: 1000 - initial-delay: 0 - ``` -#### Method 3: MSI credential based usage - -##### Set up managed identity - -Please follow [create managed identity][create-managed-identity] to set up managed identity. - -##### Create other Azure resources - -1. Create Azure Service Bus namespace and queue. - Please see [how to create][create-service-bus]. - -1. Add Role Assignment for Service Bus. See - [Managed identities for Azure resources with Service Bus][role-assignment] - to add role assignment for Service Bus. Assign `Contributor` role for managed identity. - - -##### Update MSI related properties - -1. Update [application-mi.yaml][application-mi.yaml]. - ```yaml - spring: - cloud: - azure: - credential: - managed-identity-client-id: ${AZURE_MANAGED_IDENTITY_CLIENT_ID} - profile: - tenant-id: ${AZURE_TENANT_ID} - servicebus: - namespace: ${AZURE_SERVICEBUS_NAMESPACE} - stream: - function: - definition: consume;supply - bindings: - consume-in-0: - destination: ${AZURE_SERVICEBUS_QUEUE_NAME} - supply-out-0: - destination: ${AZURE_SERVICEBUS_QUEUE_NAME} - servicebus: - bindings: - consume-in-0: - consumer: - checkpoint-mode: MANUAL - supply-out-0: - producer: - entity-type: queue - poller: - fixed-delay: 1000 - initial-delay: 0 - ``` - > We should specify `spring.profiles.active=mi` to run the Spring Boot application. - For App Service, please add a configuration entry for this. - -##### Redeploy Application - -If you update the `spring.cloud.azure.credential.managed-identity-client-id` -property after deploying the app, or update the role assignment for -services, please try to redeploy the app again. - -> You can follow -> [Deploy a Spring Boot JAR file to Azure App Service][deploy-spring-boot-application-to-app-service] -> to deploy this application to App Service - -## Examples - -1. Run the `mvn spring-boot:run` in the root of the code sample to get the app running. - -1. Send a POST request - - $ curl -X POST http://localhost:8080/messages?message=hello - - or when the app runs on App Service or VM - - $ curl -d -X POST https://[your-app-URL]/messages?message=hello - -1. Verify in your app’s logs that a similar message was posted: - - New message received: 'hello' - Message 'hello' successfully checkpointed - -1. Delete the resources on [Azure Portal][azure-portal] to avoid unexpected charges. + +## What You Will Build +You will build an application using Spring Cloud Stream to send and receive messages for Azure Service Bus Queue. + +## What You Need + +- [An Azure subscription](https://azure.microsoft.com/free/) +- [Terraform](https://www.terraform.io/) +- [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli) +- [JDK8](https://www.oracle.com/java/technologies/downloads/) or later +- Maven +- You can also import the code straight into your IDE: + - [IntelliJ IDEA](https://www.jetbrains.com/idea/download) + +## Provision Azure Resources Required to Run This Sample +This sample will create Azure resources using Terraform. If you choose to run it without using Terraform to provision resources, please pay attention to: +> [!IMPORTANT] +> If you choose to use a security principal to authenticate and authorize with Azure Active Directory for accessing an Azure resource +> please refer to [Authorize access with Azure AD](https://microsoft.github.io/spring-cloud-azure/docs/current/reference/html/index.html#authorize-access-with-azure-active-directory) to make sure the security principal has been granted the sufficient permission to access the Azure resource. + +### Authenticate Using the Azure CLI +Terraform must authenticate to Azure to create infrastructure. + +In your terminal, use the Azure CLI tool to setup your account permissions locally. + +```shell +az login +``` + +Your browser window will open and you will be prompted to enter your Azure login credentials. After successful authentication, your terminal will display your subscription information. You do not need to save this output as it is saved in your system for Terraform to use. + +```shell +You have logged in. Now let us find all the subscriptions to which you have access... + +[ + { + "cloudName": "AzureCloud", + "homeTenantId": "home-Tenant-Id", + "id": "subscription-id", + "isDefault": true, + "managedByTenants": [], + "name": "Subscription-Name", + "state": "Enabled", + "tenantId": "0envbwi39-TenantId", + "user": { + "name": "your-username@domain.com", + "type": "user" + } + } +] +``` + +If you have more than one subscription, specify the subscription-id you want to use with command below: +```shell +az account set --subscription +``` + +### Provision the Resources + +After login Azure CLI with your account, now you can use the terraform script to create Azure Resources. + +```shell +# In the root directory of the sample +# Initialize your Terraform configuration +terraform -chdir=./terraform init + +# Apply your Terraform Configuration +# Type `yes` at the confirmation prompt to proceed. +terraform -chdir=./terraform apply + +``` + + + + +It may take a few minutes to run the script. After successful running, you will see prompt information like below: + +```shell + +azurecaf_name.azurecaf_name_authorization_rule: Creating... +azurecaf_name.azurecaf_name_servicebus: Creating... +azurecaf_name.resource_group: Creating... +azurecaf_name.azurecaf_name_servicebus: Creation complete after 0s ... +azurecaf_name.resource_group: Creation complete after 0s ... +azurecaf_name.azurecaf_name_authorization_rule: Creation complete after 0s ... +azurerm_resource_group.main: Creating... +... +azurerm_servicebus_namespace.servicebus_namespace: Creation complete ... +azurerm_role_assignment.role_servicebus_data_owner: Creating... +azurerm_servicebus_namespace_authorization_rule.authorization_rule: Creating... +azurerm_servicebus_queue.queue: Creating... +azurerm_role_assignment.role_servicebus_data_owner: Still creating... +azurerm_servicebus_queue.queue: Still creating... +... +azurerm_role_assignment.role_servicebus_data_owner: Still creating... +azurerm_role_assignment.role_servicebus_data_owner: Creation complete ... + +Apply complete! Resources: 8 added, 0 changed, 0 destroyed. + +Outputs: + +... +``` + +You can go to [Azure portal](https://ms.portal.azure.com/) in your web browser to check the resources you created. + +### Export Output to Your Local Environment +Running the command below to export environment values: + +```shell + source ./terraform/setup_env.sh +``` + +## Run Locally + +In your terminal, run `mvn clean spring-boot:run`. + + +```shell +mvn clean spring-boot:run +``` + +## Verify This Sample + + +1. Verify in your app’s logs that similar messages were posted: + +```shell +... +New message received: 'Hello world, 2' +... +Message 'Hello world, 2' successfully checkpointed +... +... +New message received: 'Hello world, 3' +... +Message 'Hello world, 3' successfully checkpointed +... +... + +``` + + +## Clean Up Resources +After running the sample, if you don't want to run the sample, remember to destroy the Azure resources you created to avoid unnecessary billing. + +The terraform destroy command terminates resources managed by your Terraform project. +To destroy the resources you created. + +```shell +terraform -chdir=./terraform destroy +``` ## Enhancement -### Configuration Options +### Configuration Options The binder provides the following configuration options: @@ -193,7 +171,7 @@ It supports the following configurations with the format of `spring.cloud.stream **_sync_** -Whether the producer should act in a synchronous manner with respect to writing messages into a stream. If true, the +Whether the producer should act in a synchronous manner with respect to writing messages into a stream. If true, the producer will wait for a response after a send operation. Default: `false` @@ -203,7 +181,7 @@ Default: `false` Effective only if `sync` is set to true. The amount of time to wait for a response after a send operation, in milliseconds. Default: `10000` - + ##### Service Bus Consumer Properties It supports the following configurations with the format of `spring.cloud.stream.servicebus.bindings..consumer`. @@ -253,9 +231,9 @@ Default: `false` **_requeueRejected_** -Controls if is a message that trigger any exception in consumer will be force to DLQ. +Controls if is a message that trigger any exception in consumer will be force to DLQ. Set it to `true` if a message that trigger any exception in consumer will be force to DLQ. -Set it to `false` if a message that trigger any exception in consumer will be re-queued. +Set it to `false` if a message that trigger any exception in consumer will be re-queued. Default: `false` @@ -311,23 +289,5 @@ SessionID | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.SESSION TimeToLive | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.TIME_TO_LIVE | Duration | N/A To | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.TO | String | N/A -## Troubleshooting - -## Next steps - -## Contributing - - -[azure-account]: https://azure.microsoft.com/account/ -[azure-portal]: https://ms.portal.azure.com/ -[create-service-bus]: https://docs.microsoft.com/azure/service-bus-messaging/service-bus-create-namespace-portal -[create-azure-storage]: https://docs.microsoft.com/azure/storage/ -[create-sp-using-azure-cli]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/create-sp-using-azure-cli.md -[create-managed-identity]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/create-managed-identity.md -[deploy-spring-boot-application-to-app-service]: https://docs.microsoft.com/java/azure/spring-framework/deploy-spring-boot-java-app-with-maven-plugin?toc=%2Fazure%2Fapp-service%2Fcontainers%2Ftoc.json&view=azure-java-stable -[role-assignment]: https://docs.microsoft.com/azure/role-based-access-control/role-assignments-portal -[application-mi.yaml]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/src/main/resources/application-mi.yaml -[application-sp.yaml]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/src/main/resources/application-sp.yaml -[application.yaml]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/src/main/resources/application.yaml diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/src/main/resources/application-mi.yaml b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/src/main/resources/application-mi.yaml deleted file mode 100644 index 495ffaa05..000000000 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/src/main/resources/application-mi.yaml +++ /dev/null @@ -1,30 +0,0 @@ -spring: - cloud: - azure: - credential: - managed-identity-client-id: ${AZURE_MANAGED_IDENTITY_CLIENT_ID} - profile: - tenant-id: ${AZURE_TENANT_ID} - servicebus: - namespace: ${AZURE_SERVICEBUS_NAMESPACE} - stream: - function: - definition: consume;supply - bindings: - consume-in-0: - destination: ${AZURE_SERVICEBUS_QUEUE_NAME} - supply-out-0: - destination: ${AZURE_SERVICEBUS_QUEUE_NAME} - servicebus: - bindings: - consume-in-0: - consumer: - checkpoint-mode: MANUAL - supply-out-0: - producer: - entity-type: queue - poller: - fixed-delay: 1000 - initial-delay: 0 - - diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/src/main/resources/application-sp.yaml b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/src/main/resources/application-sp.yaml deleted file mode 100644 index 033be17ed..000000000 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/src/main/resources/application-sp.yaml +++ /dev/null @@ -1,29 +0,0 @@ -spring: - cloud: - azure: - credential: - client-id: ${AZURE_CLIENT_ID} - client-secret: ${AZURE_CLIENT_SECRET} - profile: - tenant-id: ${AZURE_TENANT_ID} - servicebus: - namespace: ${AZURE_SERVICEBUS_NAMESPACE} - stream: - function: - definition: consume;supply - bindings: - consume-in-0: - destination: ${AZURE_SERVICEBUS_QUEUE_NAME} - supply-out-0: - destination: ${AZURE_SERVICEBUS_QUEUE_NAME} - servicebus: - bindings: - consume-in-0: - consumer: - checkpoint-mode: MANUAL - supply-out-0: - producer: - entity-type: queue - poller: - fixed-delay: 1000 - initial-delay: 0 diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/src/main/resources/application.yaml b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/src/main/resources/application.yaml index 928e36a4a..b87cc1251 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/src/main/resources/application.yaml +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/src/main/resources/application.yaml @@ -2,7 +2,7 @@ spring: cloud: azure: servicebus: - connection-string: ${AZURE_SERVICEBUS_CONNECTION_STRING} + namespace: ${AZURE_SERVICEBUS_NAMESPACE} stream: function: definition: consume;supply diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/main.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/main.tf new file mode 100644 index 000000000..968a97ec4 --- /dev/null +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/main.tf @@ -0,0 +1,92 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 2.75" + } + azurecaf = { + source = "aztfmod/azurecaf" + version = "1.2.10" + } + } +} + +provider "azurerm" { + features {} +} + +resource "azurecaf_name" "resource_group" { + name = var.application_name + resource_type = "azurerm_resource_group" + random_length = 5 + clean_input = true +} + +resource "azurerm_resource_group" "main" { + name = azurecaf_name.resource_group.result + location = var.location + + tags = { + "terraform" = "true" + "application-name" = var.application_name + "spring-cloud-azure-sample" = var.sample_tag_value + } +} + +resource "azurecaf_name" "azurecaf_name_servicebus" { + name = var.application_name + resource_type = "azurerm_servicebus_namespace" + random_length = 5 + clean_input = true +} + +resource "azurerm_servicebus_namespace" "servicebus_namespace" { + name = azurecaf_name.azurecaf_name_servicebus.result + location = var.location + resource_group_name = azurerm_resource_group.main.name + + sku = "Standard" + zone_redundant = false + + tags = { + "spring-cloud-azure-sample" = var.sample_tag_value + } +} + +resource "azurecaf_name" "azurecaf_name_authorization_rule" { + name = var.application_name + resource_type = "azurerm_servicebus_namespace_authorization_rule" +} + +resource "azurerm_servicebus_namespace_authorization_rule" "authorization_rule" { + name = azurecaf_name.azurecaf_name_authorization_rule.result + namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name + resource_group_name = azurerm_resource_group.main.name + + listen = true + send = true + manage = true +} + +resource "azurerm_servicebus_queue" "queue" { + name = "que001" + namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name + resource_group_name = azurerm_resource_group.main.name + + enable_partitioning = false + max_delivery_count = 10 + lock_duration = "PT30S" + max_size_in_megabytes = 1024 + requires_session = false + default_message_ttl = "P14D" +} + + +data "azurerm_client_config" "current" { +} + +resource "azurerm_role_assignment" "role_servicebus_data_owner" { + scope = azurerm_servicebus_namespace.servicebus_namespace.id + role_definition_name = "Azure Service Bus Data Owner" + principal_id = data.azurerm_client_config.current.object_id +} diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/outputs.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/outputs.tf new file mode 100644 index 000000000..5209d2437 --- /dev/null +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/outputs.tf @@ -0,0 +1,9 @@ +output "AZURE_SERVICEBUS_NAMESPACE" { + value = azurerm_servicebus_namespace.servicebus_namespace.name + description = "The name of service bus namespace." +} + +output "AZURE_SERVICEBUS_QUEUE_NAME" { + value = azurerm_servicebus_queue.queue.name + description = "The name of created queue in the service bus namespace." +} diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/setup_env.sh b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/setup_env.sh new file mode 100644 index 000000000..1910486af --- /dev/null +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/setup_env.sh @@ -0,0 +1,5 @@ +export AZURE_SERVICEBUS_NAMESPACE=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_NAMESPACE) +export AZURE_SERVICEBUS_QUEUE_NAME=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_QUEUE_NAME) + + + diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/variables.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/variables.tf new file mode 100644 index 000000000..6e2a1f191 --- /dev/null +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/variables.tf @@ -0,0 +1,17 @@ +variable "application_name" { + type = string + description = "The name of your application." + default = "servicebus-queue-binder" +} + +variable "location" { + type = string + description = "The Azure region where all resources in this example should be created." + default = "eastus" +} + +variable "sample_tag_value" { + type = string + description = "The value of spring-cloud-azure-sample tag." + default = "true" +} diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/README.md b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/README.md index e4f2f9f68..8ccafc98a 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/README.md +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/README.md @@ -1,193 +1,163 @@ -# Spring Cloud Azure Stream Binder for Service Bus topic Sample shared library for Java +# Spring Cloud Azure Stream Binder for Service Bus topic Sample shared library for Java -## Key concepts This code sample demonstrates how to use the Spring Cloud Stream binder for Azure Service Bus topic. The sample app has two operating modes. One way is to expose a Restful API to receive string message, another way is to automatically provide string messages. These messages are published to a service bus topic. The sample will also consume messages from the same service bus topic. -## Getting started - -Running this sample will be charged by Azure. You can check the usage and bill at -[this link][azure-account]. - - - -### Create Azure resources - -We have several ways to config the Spring Cloud Stream Binder for Azure -Service Bus Topic. You can choose anyone of them. - ->[!Important] -> -> When using the Restful API to send messages, the **Active profiles** must contain `manual`. - -#### Method 1: Connection string based usage - -1. Create Azure Service Bus namespace and topic. - Please see [how to create][create-service-bus]. - -1. Update [application.yaml]. - ```yaml - - spring: - cloud: - azure: - servicebus: - connection-string: ${AZURE_SERVICEBUS_CONNECTION_STRING} - stream: - function: - definition: consume;supply - bindings: - consume-in-0: - destination: ${AZURE_SERVICEBUS_TOPIC_NAME} - group: ${AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME} - supply-out-0: - destination: ${AZURE_SERVICEBUS_TOPIC_NAME} - servicebus: - bindings: - consume-in-0: - consumer: - checkpoint-mode: MANUAL - supply-out-0: - producer: - entity-type: topic - poller: - fixed-delay: 1000 - initial-delay: 0 - ``` - -#### Method 2: Service principal based usage - -1. Create a service principal for use in by your app. Please follow - [create service principal from Azure CLI][create-sp-using-azure-cli]. - -1. Create Azure Service Bus namespace and queue. - Please see [how to create][create-service-bus]. - -1. Add Role Assignment for Service Bus. See - [Service principal for Azure resources with Service Bus][role-assignment] - to add role assignment for Service Bus. Assign `Contributor` role for managed identity. - -1. Update [application-sp.yaml]. - ```yaml - spring: - cloud: - azure: - credential: - client-id: ${AZURE_CLIENT_ID} - client-secret: ${AZURE_CLIENT_SECRET} - profile: - tenant-id: ${AZURE_TENANT_ID} - servicebus: - namespace: ${AZURE_SERVICEBUS_NAMESPACE} - stream: - function: - definition: consume;supply - bindings: - consume-in-0: - destination: ${AZURE_SERVICEBUS_TOPIC_NAME} - group: ${AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME} - supply-out-0: - destination: ${AZURE_SERVICEBUS_TOPIC_NAME} - servicebus: - bindings: - consume-in-0: - consumer: - checkpoint-mode: MANUAL - supply-out-0: - producer: - entity-type: topic - poller: - fixed-delay: 1000 - initial-delay: 0 - ``` - > We should specify `spring.profiles.active=sp` to run the Spring Boot application. - -#### Method 3: MSI credential based usage - -##### Set up managed identity - -Please follow [create managed identity][create-managed-identity] to set up managed identity. - -##### Create other Azure resources - -1. Create Azure Service Bus namespace and queue. - Please see [how to create][create-service-bus]. - -1. Add Role Assignment for Service Bus. See - [Managed identities for Azure resources with Service Bus][role-assignment] - to add role assignment for Service Bus. Assign `Contributor` role for managed identity. - - -##### Update MSI related properties - -1. Update [application-mi.yaml] - ```yaml - spring: - cloud: - azure: - credential: - managed-identity-client-id: ${AZURE_MANAGED_IDENTITY_CLIENT_ID} - profile: - tenant-id: ${AZURE_TENANT_ID} - servicebus: - namespace: ${AZURE_SERVICEBUS_NAMESPACE} - stream: - function: - definition: consume;supply - bindings: - consume-in-0: - destination: ${AZURE_SERVICEBUS_TOPIC_NAME} - group: ${AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME} - supply-out-0: - destination: ${AZURE_SERVICEBUS_TOPIC_NAME} - servicebus: - bindings: - consume-in-0: - consumer: - checkpoint-mode: MANUAL - supply-out-0: - producer: - entity-type: topic - poller: - fixed-delay: 1000 - initial-delay: 0 - ``` - > We should specify `spring.profiles.active=mi` to run the Spring Boot application. - For App Service, please add a configuration entry for this. - -##### Redeploy Application - -If you update the `spring.cloud.azure.credential.managed-identity-client-id` -property after deploying the app, or update the role assignment for -services, please try to redeploy the app again. - -> You can follow -> [Deploy a Spring Boot JAR file to Azure App Service][deploy-spring-boot-application-to-app-service] -> to deploy this application to App Service - -## Examples - -1. Run the `mvn spring-boot:run` in the root of the code sample to get the app running. - -1. Send a POST request - - $ curl -X POST http://localhost:8080/messages?message=hello - - or when the app runs on App Service or VM - - $ curl -d -X POST https://[your-app-URL]/messages?message=hello - -1. Verify in your app’s logs that a similar message was posted: - - New message received: 'hello' - Message 'hello' successfully checkpointed - -1. Delete the resources on [Azure Portal][azure-portal] to avoid unexpected charges. + +## What You Will Build +You will build an application using Spring Cloud Stream to send and receive messages for Azure Service Bus Topic. + +## What You Need + +- [An Azure subscription](https://azure.microsoft.com/free/) +- [Terraform](https://www.terraform.io/) +- [Azure CLI](https://docs.microsoft.com/cli/azure/install-azure-cli) +- [JDK8](https://www.oracle.com/java/technologies/downloads/) or later +- Maven +- You can also import the code straight into your IDE: + - [IntelliJ IDEA](https://www.jetbrains.com/idea/download) + +## Provision Azure Resources Required to Run This Sample +This sample will create Azure resources using Terraform. If you choose to run it without using Terraform to provision resources, please pay attention to: +> [!IMPORTANT] +> If you choose to use a security principal to authenticate and authorize with Azure Active Directory for accessing an Azure resource +> please refer to [Authorize access with Azure AD](https://microsoft.github.io/spring-cloud-azure/docs/current/reference/html/index.html#authorize-access-with-azure-active-directory) to make sure the security principal has been granted the sufficient permission to access the Azure resource. + +### Authenticate Using the Azure CLI +Terraform must authenticate to Azure to create infrastructure. + +In your terminal, use the Azure CLI tool to setup your account permissions locally. + +```shell +az login +``` + +Your browser window will open and you will be prompted to enter your Azure login credentials. After successful authentication, your terminal will display your subscription information. You do not need to save this output as it is saved in your system for Terraform to use. + +```shell +You have logged in. Now let us find all the subscriptions to which you have access... + +[ + { + "cloudName": "AzureCloud", + "homeTenantId": "home-Tenant-Id", + "id": "subscription-id", + "isDefault": true, + "managedByTenants": [], + "name": "Subscription-Name", + "state": "Enabled", + "tenantId": "0envbwi39-TenantId", + "user": { + "name": "your-username@domain.com", + "type": "user" + } + } +] +``` + +If you have more than one subscription, specify the subscription-id you want to use with command below: +```shell +az account set --subscription +``` + +### Provision the Resources + +After login Azure CLI with your account, now you can use the terraform script to create Azure Resources. + +```shell +# In the root directory of the sample +# Initialize your Terraform configuration +terraform -chdir=./terraform init + +# Apply your Terraform Configuration +# Type `yes` at the confirmation prompt to proceed. +terraform -chdir=./terraform apply + +``` + + + + +It may take a few minutes to run the script. After successful running, you will see prompt information like below: + +```shell + +azurecaf_name.azurecaf_name_servicebus: Creating... +azurecaf_name.resource_group: Creating... +azurecaf_name.servicebus_namespace_authorization_rule: Creating... +azurecaf_name.azurecaf_name_servicebus: Creation complete after 0s [id=ggntexahlqdfmbkj] +azurecaf_name.resource_group: Creation complete after 0s [id=euikvcxceagwuaqw] +azurecaf_name.servicebus_namespace_authorization_rule: Creation complete after 0s [id=kifnoeclhdayfgek] +azurerm_resource_group.main: Creating... +azurerm_resource_group.main: Creation complete after 5s ... +... +... +azurerm_servicebus_namespace_authorization_rule.authorization_rule: Creation complete after 15s ... +azurerm_role_assignment.role_servicebus_data_owner: Still creating... +azurerm_servicebus_subscription.servicebus_subscription: Still creating... +azurerm_servicebus_subscription.servicebus_subscription: Creation complete after 15s ... +azurerm_role_assignment.role_servicebus_data_owner: Creation complete after 28s ... + +Apply complete! Resources: 9 added, 0 changed, 0 destroyed. + +Outputs: + +... +``` + +You can go to [Azure portal](https://ms.portal.azure.com/) in your web browser to check the resources you created. + +### Export Output to Your Local Environment +Running the command below to export environment values: + +```shell + source ./terraform/setup_env.sh +``` + +## Run Locally + +In your terminal, run `mvn clean spring-boot:run`. + + +```shell +mvn clean spring-boot:run +``` + +## Verify This Sample + + +1. Verify in your app’s logs that similar messages were posted: + +```shell +... +... +New message received: 'Hello world, 2' +... +Message 'Hello world, 2' successfully checkpointed +... +New message received: 'Hello world, 3' +... +Message 'Hello world, 3' successfully checkpointed +... +... +``` + +## Clean Up Resources +After running the sample, if you don't want to run the sample, remember to destroy the Azure resources you created to avoid unnecessary billing. + +The terraform destroy command terminates resources managed by your Terraform project. +To destroy the resources you created. + +```shell +terraform -chdir=./terraform destroy +``` + + ## Enhancement -### Configuration Options +### Configuration Options The binder provides the following configuration options: @@ -197,7 +167,7 @@ It supports the following configurations with the format of `spring.cloud.stream **_sync_** -Whether the producer should act in a synchronous manner with respect to writing messages into a stream. If true, the +Whether the producer should act in a synchronous manner with respect to writing messages into a stream. If true, the producer will wait for a response after a send operation. Default: `false` @@ -207,7 +177,7 @@ Default: `false` Effective only if `sync` is set to true. The amount of time to wait for a response after a send operation, in milliseconds. Default: `10000` - + ##### Service Bus Consumer Properties It supports the following configurations with the format of `spring.cloud.stream.servicebus.bindings..consumer`. @@ -257,9 +227,9 @@ Default: `false` **_requeueRejected_** -Controls if is a message that trigger any exception in consumer will be force to DLQ. +Controls if is a message that trigger any exception in consumer will be force to DLQ. Set it to `true` if a message that trigger any exception in consumer will be force to DLQ. -Set it to `false` if a message that trigger any exception in consumer will be re-queued. +Set it to `false` if a message that trigger any exception in consumer will be re-queued. Default: `false` @@ -315,22 +285,3 @@ SessionID | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.SESSION TimeToLive | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.TIME_TO_LIVE | Duration | N/A To | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.TO | String | N/A -## Troubleshooting - -## Next steps - -## Contributing - - - -[azure-account]: https://azure.microsoft.com/account/ -[azure-portal]: https://ms.portal.azure.com/ -[create-service-bus]: https://docs.microsoft.com/azure/service-bus-messaging/service-bus-create-namespace-portal -[create-azure-storage]: https://docs.microsoft.com/azure/storage/ -[create-sp-using-azure-cli]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/create-sp-using-azure-cli.md -[create-managed-identity]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/create-managed-identity.md -[deploy-spring-boot-application-to-app-service]: https://docs.microsoft.com/java/azure/spring-framework/deploy-spring-boot-java-app-with-maven-plugin?toc=%2Fazure%2Fapp-service%2Fcontainers%2Ftoc.json&view=azure-java-stable -[role-assignment]: https://docs.microsoft.com/azure/role-based-access-control/role-assignments-portal -[application-mi.yaml]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/src/main/resources/application-mi.yaml -[application-sp.yaml]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/src/main/resources/application-sp.yaml -[application.yaml]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/src/main/resources/application.yaml diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/src/main/resources/application-mi.yaml b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/src/main/resources/application-mi.yaml deleted file mode 100644 index 3cf151c8a..000000000 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/src/main/resources/application-mi.yaml +++ /dev/null @@ -1,29 +0,0 @@ -spring: - cloud: - azure: - credential: - managed-identity-client-id: ${AZURE_MANAGED_IDENTITY_CLIENT_ID} - profile: - tenant-id: ${AZURE_TENANT_ID} - servicebus: - namespace: ${AZURE_SERVICEBUS_NAMESPACE} - stream: - function: - definition: consume;supply - bindings: - consume-in-0: - destination: ${AZURE_SERVICEBUS_TOPIC_NAME} - group: ${AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME} - supply-out-0: - destination: ${AZURE_SERVICEBUS_TOPIC_NAME} - servicebus: - bindings: - consume-in-0: - consumer: - checkpoint-mode: MANUAL - supply-out-0: - producer: - entity-type: topic - poller: - fixed-delay: 1000 - initial-delay: 0 diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/src/main/resources/application-sp.yaml b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/src/main/resources/application-sp.yaml deleted file mode 100644 index 6fae93f13..000000000 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/src/main/resources/application-sp.yaml +++ /dev/null @@ -1,30 +0,0 @@ -spring: - cloud: - azure: - credential: - client-id: ${AZURE_CLIENT_ID} - client-secret: ${AZURE_CLIENT_SECRET} - profile: - tenant-id: ${AZURE_TENANT_ID} - servicebus: - namespace: ${AZURE_SERVICEBUS_NAMESPACE} - stream: - function: - definition: consume;supply - bindings: - consume-in-0: - destination: ${AZURE_SERVICEBUS_TOPIC_NAME} - group: ${AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME} - supply-out-0: - destination: ${AZURE_SERVICEBUS_TOPIC_NAME} - servicebus: - bindings: - consume-in-0: - consumer: - checkpoint-mode: MANUAL - supply-out-0: - producer: - entity-type: topic - poller: - fixed-delay: 1000 - initial-delay: 0 diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/src/main/resources/application.yaml b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/src/main/resources/application.yaml index e8c0a1a85..e4921de97 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/src/main/resources/application.yaml +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/src/main/resources/application.yaml @@ -2,7 +2,7 @@ spring: cloud: azure: servicebus: - connection-string: ${AZURE_SERVICEBUS_CONNECTION_STRING} + namespace: ${AZURE_SERVICEBUS_NAMESPACE} stream: function: definition: consume;supply @@ -22,4 +22,4 @@ spring: entity-type: topic poller: fixed-delay: 1000 - initial-delay: 0 \ No newline at end of file + initial-delay: 0 diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/main.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/main.tf new file mode 100644 index 000000000..582007fd3 --- /dev/null +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/main.tf @@ -0,0 +1,92 @@ +terraform { + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 2.75" + } + azurecaf = { + source = "aztfmod/azurecaf" + version = "1.2.10" + } + } +} + +provider "azurerm" { + features {} +} + +resource "azurecaf_name" "resource_group" { + name = var.application_name + resource_type = "azurerm_resource_group" + random_length = 5 + clean_input = true +} + +resource "azurerm_resource_group" "main" { + name = azurecaf_name.resource_group.result + location = var.location + + tags = { + "terraform" = "true" + "application-name" = var.application_name + "spring-cloud-azure-sample" = var.sample_tag_value + } +} + +resource "azurecaf_name" "azurecaf_name_servicebus" { + name = var.application_name + resource_type = "azurerm_servicebus_namespace" + random_length = 5 + clean_input = true +} + +resource "azurerm_servicebus_namespace" "servicebus_namespace" { + name = azurecaf_name.azurecaf_name_servicebus.result + location = var.location + resource_group_name = azurerm_resource_group.main.name + + sku = "Standard" + zone_redundant = false + + tags = { + "spring-cloud-azure-sample" = var.sample_tag_value + } +} + +resource "azurecaf_name" "servicebus_namespace_authorization_rule" { + name = var.application_name + resource_type = "azurerm_servicebus_namespace_authorization_rule" +} + +resource "azurerm_servicebus_namespace_authorization_rule" "authorization_rule" { + name = azurecaf_name.servicebus_namespace_authorization_rule.result + namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name + resource_group_name = azurerm_resource_group.main.name + + listen = true + send = true + manage = true +} + +resource "azurerm_servicebus_topic" "servicebus_topic" { + name = "tpc001" + namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name + resource_group_name = azurerm_resource_group.main.name +} + +resource "azurerm_servicebus_subscription" "servicebus_subscription" { + name = "sub001" + resource_group_name = azurerm_resource_group.main.name + namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name + topic_name = azurerm_servicebus_topic.servicebus_topic.name + max_delivery_count = 1 +} + +data "azurerm_client_config" "client_config" { +} + +resource "azurerm_role_assignment" "role_servicebus_data_owner" { + scope = azurerm_servicebus_namespace.servicebus_namespace.id + role_definition_name = "Azure Service Bus Data Owner" + principal_id = data.azurerm_client_config.client_config.object_id +} diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/outputs.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/outputs.tf new file mode 100644 index 000000000..1e2c457ed --- /dev/null +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/outputs.tf @@ -0,0 +1,16 @@ +output "AZURE_SERVICEBUS_NAMESPACE" { + value = azurerm_servicebus_namespace.servicebus_namespace.name + description = "The name of service bus namespace." +} + +output "AZURE_SERVICEBUS_TOPIC_NAME" { + value = azurerm_servicebus_topic.servicebus_topic.name + description = "The name of created topic in the service bus namespace." +} + +output "AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME" { + value = azurerm_servicebus_subscription.servicebus_subscription.name + description = "The name of created subscription in the service bus namespace." + +} + diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/setup_env.sh b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/setup_env.sh new file mode 100644 index 000000000..2091a168d --- /dev/null +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/setup_env.sh @@ -0,0 +1,5 @@ +export AZURE_SERVICEBUS_NAMESPACE=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_NAMESPACE) +export AZURE_SERVICEBUS_TOPIC_NAME=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_TOPIC_NAME) +export AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME) + + diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/variables.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/variables.tf new file mode 100644 index 000000000..af412df1a --- /dev/null +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/variables.tf @@ -0,0 +1,17 @@ +variable "application_name" { + type = string + description = "The name of your application." + default = "servicebus-topic-binder" +} + +variable "location" { + type = string + description = "The Azure region where all resources in this example should be created." + default = "eastus" +} + +variable "sample_tag_value" { + type = string + description = "The value of spring-cloud-azure-sample tag." + default = "true" +} From 58a4d2be46f08c1505fe586cdbb6ac25f01019e3 Mon Sep 17 00:00:00 2001 From: zhihaoguo Date: Wed, 12 Jan 2022 00:02:01 +0800 Subject: [PATCH 02/12] update main.tf for "azurerm_servicebus_queue" --- .../multiple-namespaces/terraform/main.tf | 6 ++---- .../single-namespace/terraform/main.tf | 3 +-- .../servicebus-jms-queue/terraform/main.tf | 3 +-- .../servicebus-multibinders/terraform/main.tf | 3 +-- .../servicebus-queue-binder/terraform/main.tf | 3 +-- 5 files changed, 6 insertions(+), 12 deletions(-) diff --git a/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/main.tf b/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/main.tf index c95b54550..0e3b9d37b 100644 --- a/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/main.tf +++ b/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/main.tf @@ -56,8 +56,7 @@ resource "azurerm_servicebus_namespace" "servicebus_namespace_01" { resource "azurerm_servicebus_queue" "application_queue_01" { name = "queue1" - namespace_name = azurerm_servicebus_namespace.servicebus_namespace_01.name - resource_group_name = azurerm_resource_group.main.name + namespace_id = azurerm_servicebus_namespace.servicebus_namespace_01.id enable_partitioning = false max_delivery_count = 10 @@ -90,8 +89,7 @@ resource "azurerm_servicebus_namespace" "servicebus_namespace_02" { resource "azurerm_servicebus_queue" "application_queue_02" { name = "queue2" - namespace_name = azurerm_servicebus_namespace.servicebus_namespace_02.name - resource_group_name = azurerm_resource_group.main.name + namespace_id = azurerm_servicebus_namespace.servicebus_namespace_02.id enable_partitioning = false max_delivery_count = 10 diff --git a/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/main.tf b/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/main.tf index 49bc6a6b5..170212a13 100644 --- a/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/main.tf +++ b/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/main.tf @@ -70,8 +70,7 @@ resource "azurerm_servicebus_namespace_authorization_rule" "authorization_rule" resource "azurerm_servicebus_queue" "application" { name = "queue1" - namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name - resource_group_name = azurerm_resource_group.main.name + namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id enable_partitioning = false max_delivery_count = 10 diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/main.tf b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/main.tf index c63f12694..0cc88520e 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/main.tf +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/main.tf @@ -70,8 +70,7 @@ resource "azurerm_servicebus_namespace_authorization_rule" "authorization_rule" resource "azurerm_servicebus_queue" "queue" { name = "que001" - namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name - resource_group_name = azurerm_resource_group.main.name + namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id enable_partitioning = false max_delivery_count = 10 diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/main.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/main.tf index bfacedd7f..ecd5fcfa1 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/main.tf +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/main.tf @@ -131,8 +131,7 @@ resource "azurerm_servicebus_namespace_authorization_rule" "namespace_authorizat resource "azurerm_servicebus_queue" "servicebus_namespace_02_queue" { name = "que001" - namespace_name = azurerm_servicebus_namespace.servicebus_namespace_02.name - resource_group_name = azurerm_resource_group.main.name + namespace_id = azurerm_servicebus_namespace.servicebus_namespace_02.id enable_partitioning = false max_delivery_count = 10 diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/main.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/main.tf index 968a97ec4..2c901c9fa 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/main.tf +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/main.tf @@ -70,8 +70,7 @@ resource "azurerm_servicebus_namespace_authorization_rule" "authorization_rule" resource "azurerm_servicebus_queue" "queue" { name = "que001" - namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name - resource_group_name = azurerm_resource_group.main.name + namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id enable_partitioning = false max_delivery_count = 10 From b2ae33bb77537f432a9209ffa7f7e3a833f59903 Mon Sep 17 00:00:00 2001 From: zhihaoguo Date: Wed, 12 Jan 2022 12:49:41 +0800 Subject: [PATCH 03/12] update terraform scripts and readme --- .../single-namespace/README.md | 30 ++++++++++----- .../single-namespace/terraform/main.tf | 23 ++--------- .../servicebus-jms-queue/README.md | 19 ++++------ .../servicebus-jms-queue/terraform/main.tf | 15 -------- .../servicebus-jms-topic/README.md | 25 +++++------- .../servicebus-jms-topic/terraform/main.tf | 23 ++--------- .../servicebus-multibinders/README.md | 25 ++++++------ .../servicebus-multibinders/terraform/main.tf | 38 ++----------------- .../terraform/setup_env.sh | 1 - .../servicebus-queue-binder/README.md | 20 ++++------ .../servicebus-queue-binder/terraform/main.tf | 16 -------- .../terraform/setup_env.sh | 3 -- .../servicebus-topic-binder/README.md | 30 +++++++-------- .../servicebus-topic-binder/terraform/main.tf | 23 ++--------- .../terraform/setup_env.sh | 2 - 15 files changed, 83 insertions(+), 210 deletions(-) diff --git a/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/README.md b/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/README.md index 2bdc64703..8ec300b6e 100644 --- a/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/README.md +++ b/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/README.md @@ -73,24 +73,34 @@ terraform -chdir=./terraform apply ``` - - - It may take a few minutes to run the script. After successful running, you will see prompt information like below: ```shell - +azurecaf_name.servicebus: Creating... +azurecaf_name.topic: Creating... +azurecaf_name.resource_group: Creating... +azurecaf_name.resource_group: Creation complete after 0s [id=mvwycgvrvqxrbyiy] +azurecaf_name.servicebus: Creation complete after 0s [id=kfvxhnbckoaabrfh] +azurecaf_name.topic: Creation complete after 0s [id=tixdrtltwgohxbde] ... -azurerm_servicebus_namespace_authorization_rule.application: Creation complete after 13s ... -azurerm_servicebus_subscription.application: Creation complete after 7s ... -azurerm_role_assignment.servicebus_data_owner: Still creating... [20s elapsed] -azurerm_role_assignment.servicebus_data_owner: Creation complete after 28s ... +azurerm_servicebus_namespace.servicebus_namespace: Creating... +... +azurerm_servicebus_namespace.servicebus_namespace: ... +azurerm_servicebus_queue.application: Creating... +azurerm_servicebus_topic.application: Creating... +azurerm_role_assignment.role_servicebus_data_owner: Creating... +... +azurerm_servicebus_subscription.application: Creating... +azurerm_servicebus_queue.application: Creation complete after 9s ... +... +azurerm_role_assignment.role_servicebus_data_owner: Still creating... [30s elapsed] +azurerm_role_assignment.role_servicebus_data_owner: ... -Apply complete! Resources: 11 added, 0 changed, 0 destroyed. +Apply complete! Resources: 9 added, 0 changed, 0 destroyed. Outputs: -SERVICEBUS_NAMESPACE = "${YOUR_SERVICEBUS_NAMESPACE}" +... ``` diff --git a/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/main.tf b/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/main.tf index 170212a13..67bb75b7c 100644 --- a/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/main.tf +++ b/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/terraform/main.tf @@ -53,21 +53,6 @@ resource "azurerm_servicebus_namespace" "servicebus_namespace" { } } -resource "azurecaf_name" "servicebus_namespace_authorization_rule" { - name = var.application_name - resource_type = "azurerm_servicebus_namespace_authorization_rule" -} - -resource "azurerm_servicebus_namespace_authorization_rule" "authorization_rule" { - name = azurecaf_name.servicebus_namespace_authorization_rule.result - namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name - resource_group_name = azurerm_resource_group.main.name - - listen = true - send = true - manage = true -} - resource "azurerm_servicebus_queue" "application" { name = "queue1" namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id @@ -87,15 +72,13 @@ resource "azurecaf_name" "topic" { resource "azurerm_servicebus_topic" "application" { name = "topic1" - namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name - resource_group_name = azurerm_resource_group.main.name + namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id } resource "azurerm_servicebus_subscription" "application" { name = "group1" - resource_group_name = azurerm_resource_group.main.name - namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name - topic_name = azurerm_servicebus_topic.application.name + topic_id = azurerm_servicebus_topic.application.id + max_delivery_count = 1 } diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/README.md b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/README.md index 5f88e135b..0a08594dc 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/README.md +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/README.md @@ -80,24 +80,19 @@ terraform -chdir=./terraform apply It may take a few minutes to run the script. After successful running, you will see prompt information like below: ```shell - -azurecaf_name.resource_group: Creating... azurecaf_name.azurecaf_name_servicebus: Creating... -azurecaf_name.servicebus_namespace_authorization_rule: Creating... -azurecaf_name.servicebus_namespace_authorization_rule: Creation complete after ... -azurecaf_name.azurecaf_name_servicebus: Creation complete after 0s ... -azurecaf_name.resource_group: Creation complete after ... +azurecaf_name.resource_group: Creating... +azurecaf_name.azurecaf_name_servicebus: Creation complete after 0s [id=qikkuohqscnhospw] +azurecaf_name.resource_group: Creation complete after 0s [id=hsgmdikkcuwtxecs] azurerm_resource_group.main: Creating... -azurerm_resource_group.main: Creation complete after ... +azurerm_resource_group.main: Creation complete after 5s ... +azurerm_servicebus_namespace.servicebus_namespace: Creating... ... azurerm_servicebus_namespace.servicebus_namespace: Creation complete after ... azurerm_servicebus_queue.queue: Creating... -azurerm_servicebus_namespace_authorization_rule.authorization_rule: Creating... -azurerm_servicebus_queue.queue: Creation complete after 6s ... -azurerm_servicebus_namespace_authorization_rule.authorization_rule: Still creating... [10s elapsed] -azurerm_servicebus_namespace_authorization_rule.authorization_rule: Creation complete ... +azurerm_servicebus_queue.queue: Creation complete ... -Apply complete! Resources: 7 added, 0 changed, 0 destroyed. +Apply complete! Resources: 5 added, 0 changed, 0 destroyed. Outputs: diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/main.tf b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/main.tf index 0cc88520e..2e58db5ab 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/main.tf +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/main.tf @@ -53,21 +53,6 @@ resource "azurerm_servicebus_namespace" "servicebus_namespace" { } } -resource "azurecaf_name" "servicebus_namespace_authorization_rule" { - name = var.application_name - resource_type = "azurerm_servicebus_namespace_authorization_rule" -} - -resource "azurerm_servicebus_namespace_authorization_rule" "authorization_rule" { - name = azurecaf_name.servicebus_namespace_authorization_rule.result - namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name - resource_group_name = azurerm_resource_group.main.name - - listen = true - send = true - manage = true -} - resource "azurerm_servicebus_queue" "queue" { name = "que001" namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/README.md b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/README.md index 584bd2c26..1e4045ef9 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/README.md +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/README.md @@ -73,34 +73,28 @@ terraform -chdir=./terraform apply ``` - - - It may take a few minutes to run the script. After successful running, you will see prompt information like below: ```shell - - azurecaf_name.azurecaf_name_servicebus: Creating... azurecaf_name.resource_group: Creating... -azurecaf_name.servicebus_namespace_authorization_rule: Creating... azurecaf_name.resource_group: Creation complete after 0s ... -azurecaf_name.servicebus_namespace_authorization_rule: Creation complete ... -azurecaf_name.azurecaf_name_servicebus: Creation complete ... +azurecaf_name.azurecaf_name_servicebus: Creation complete after 0s ... +azurerm_resource_group.main: Creating... +azurerm_resource_group.main: Creation complete ... +azurerm_servicebus_namespace.servicebus_namespace: Creating... ... +azurerm_servicebus_namespace.servicebus_namespace: Creation complete after ... azurerm_servicebus_topic.application: Creating... -azurerm_servicebus_namespace_authorization_rule.authorization_rule: Creating... -azurerm_servicebus_topic.application: Creation complete after ... +azurerm_servicebus_topic.application: Creation complete ... azurerm_servicebus_subscription.application: Creating... -azurerm_servicebus_namespace_authorization_rule.authorization_rule: Still creating... [10s elapsed] -azurerm_servicebus_subscription.application: Creation complete after ... -azurerm_servicebus_namespace_authorization_rule.authorization_rule: Creation complete ... +azurerm_servicebus_subscription.application: Creation complete ... -Apply complete! Resources: 8 added, 0 changed, 0 destroyed. +Apply complete! Resources: 6 added, 0 changed, 0 destroyed. Outputs: -... +... ``` You can go to [Azure portal](https://ms.portal.azure.com/) in your web browser to check the resources you created. @@ -135,7 +129,6 @@ mvn clean spring-boot:run Received message from topic: hello ``` - ## Clean Up Resources After running the sample, if you don't want to run the sample, remember to destroy the Azure resources you created to avoid unnecessary billing. diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/main.tf b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/main.tf index 0234cd5fc..34cb3673a 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/main.tf +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/main.tf @@ -53,31 +53,14 @@ resource "azurerm_servicebus_namespace" "servicebus_namespace" { } } -resource "azurecaf_name" "servicebus_namespace_authorization_rule" { - name = var.application_name - resource_type = "azurerm_servicebus_namespace_authorization_rule" -} - -resource "azurerm_servicebus_namespace_authorization_rule" "authorization_rule" { - name = azurecaf_name.servicebus_namespace_authorization_rule.result - namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name - resource_group_name = azurerm_resource_group.main.name - - listen = true - send = true - manage = true -} - resource "azurerm_servicebus_topic" "application" { name = "tpc001" - namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name - resource_group_name = azurerm_resource_group.main.name + namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id } resource "azurerm_servicebus_subscription" "application" { name = "sub001" - resource_group_name = azurerm_resource_group.main.name - namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name - topic_name = azurerm_servicebus_topic.application.name + topic_id = azurerm_servicebus_topic.application.id + max_delivery_count = 1 } diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md index f86327f28..f17a906bf 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md @@ -84,26 +84,27 @@ terraform -chdir=./terraform apply It may take a few minutes to run the script. After successful running, you will see prompt information like below: ```shell - -azurecaf_name.azurecaf_name_authorization_rule_02: Creating... -azurecaf_name.azurecaf_name_servicebus_02: Creating... -azurecaf_name.resource_group: Creating... azurecaf_name.servicebus_01: Creating... -azurecaf_name.azurecaf_name_authorization_rule_01: Creating... +azurecaf_name.resource_group: Creating... ... -azurecaf_name.azurecaf_name_servicebus_02: Creation complete after 0s ... -azurecaf_name.resource_group: Creation complete after 0s ... azurerm_resource_group.main: Creating... -azurerm_resource_group.main: Creation complete after 3s ... +azurerm_resource_group.main: Creation complete after 4s ... azurerm_servicebus_namespace.servicebus_namespace_02: Creating... +azurerm_servicebus_namespace.servicebus_namespace_01: Creating... ... -azurerm_servicebus_subscription.servicebus_namespace_01_sub: Creation complete ... -azurerm_servicebus_queue.servicebus_namespace_02_queue: Creation complete ... +azurerm_servicebus_namespace.servicebus_namespace_02: Creation complete ... +azurerm_role_assignment.role_servicebus_data_owner_02: Creating... +azurerm_servicebus_queue.servicebus_namespace_02_queue: Creating... +azurerm_servicebus_namespace.servicebus_namespace_01: Creation complete ... +azurerm_role_assignment.role_servicebus_data_owner_01: Creating... +azurerm_servicebus_topic.servicebus_namespace_01_topic: Creating... +... +azurerm_servicebus_subscription.servicebus_namespace_01_sub: Creating... ... -azurerm_role_assignment.role_servicebus_data_owner_01: Creation complete ... azurerm_role_assignment.role_servicebus_data_owner_02: Creation complete ... +azurerm_role_assignment.role_servicebus_data_owner_01: Creation complete ... -Apply complete! Resources: 15 added, 0 changed, 0 destroyed. +Apply complete! Resources: 11 added, 0 changed, 0 destroyed. Outputs: diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/main.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/main.tf index ecd5fcfa1..60859d8bc 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/main.tf +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/main.tf @@ -58,32 +58,15 @@ resource "azurerm_servicebus_namespace" "servicebus_namespace_01" { } } -resource "azurecaf_name" "azurecaf_name_authorization_rule_01" { - name = var.application_name - resource_type = "azurerm_servicebus_namespace_authorization_rule" -} - -resource "azurerm_servicebus_namespace_authorization_rule" "namespace_authorization_rule_01" { - name = azurecaf_name.azurecaf_name_authorization_rule_01.result - namespace_name = azurerm_servicebus_namespace.servicebus_namespace_01.name - resource_group_name = azurerm_resource_group.main.name - - listen = true - send = true - manage = true -} - resource "azurerm_servicebus_topic" "servicebus_namespace_01_topic" { name = "tpc001" - namespace_name = azurerm_servicebus_namespace.servicebus_namespace_01.name - resource_group_name = azurerm_resource_group.main.name + namespace_id = azurerm_servicebus_namespace.servicebus_namespace_01.id } resource "azurerm_servicebus_subscription" "servicebus_namespace_01_sub" { name = "sub001" - resource_group_name = azurerm_resource_group.main.name - namespace_name = azurerm_servicebus_namespace.servicebus_namespace_01.name - topic_name = azurerm_servicebus_topic.servicebus_namespace_01_topic.name + topic_id = azurerm_servicebus_topic.servicebus_namespace_01_topic.id + max_delivery_count = 1 } @@ -114,21 +97,6 @@ resource "azurerm_servicebus_namespace" "servicebus_namespace_02" { } } -resource "azurecaf_name" "azurecaf_name_authorization_rule_02" { - name = var.application_name - resource_type = "azurerm_servicebus_namespace_authorization_rule" -} - -resource "azurerm_servicebus_namespace_authorization_rule" "namespace_authorization_rule_02" { - name = azurecaf_name.azurecaf_name_authorization_rule_02.result - namespace_name = azurerm_servicebus_namespace.servicebus_namespace_02.name - resource_group_name = azurerm_resource_group.main.name - - listen = true - send = true - manage = true -} - resource "azurerm_servicebus_queue" "servicebus_namespace_02_queue" { name = "que001" namespace_id = azurerm_servicebus_namespace.servicebus_namespace_02.id diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/setup_env.sh b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/setup_env.sh index 1696e04b1..2223b55b2 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/setup_env.sh +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/setup_env.sh @@ -3,4 +3,3 @@ export AZURE_SERVICEBUS_NAMESPACE_02=$(terraform -chdir=./terraform output -raw export AZURE_SERVICEBUS_TOPIC_NAME=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_TOPIC_NAME) export AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME) export AZURE_SERVICEBUS_QUEUE_NAME=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_QUEUE_NAME) - diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/README.md b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/README.md index a3776301e..67d0a7f00 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/README.md +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/README.md @@ -84,26 +84,22 @@ terraform -chdir=./terraform apply It may take a few minutes to run the script. After successful running, you will see prompt information like below: ```shell - -azurecaf_name.azurecaf_name_authorization_rule: Creating... -azurecaf_name.azurecaf_name_servicebus: Creating... azurecaf_name.resource_group: Creating... -azurecaf_name.azurecaf_name_servicebus: Creation complete after 0s ... -azurecaf_name.resource_group: Creation complete after 0s ... -azurecaf_name.azurecaf_name_authorization_rule: Creation complete after 0s ... +azurecaf_name.azurecaf_name_servicebus: Creating... +azurecaf_name.azurecaf_name_servicebus: Creation complete ... +azurecaf_name.resource_group: Creation complete ... azurerm_resource_group.main: Creating... +azurerm_resource_group.main: Creation complete ... +azurerm_servicebus_namespace.servicebus_namespace: Creating... ... azurerm_servicebus_namespace.servicebus_namespace: Creation complete ... azurerm_role_assignment.role_servicebus_data_owner: Creating... -azurerm_servicebus_namespace_authorization_rule.authorization_rule: Creating... azurerm_servicebus_queue.queue: Creating... -azurerm_role_assignment.role_servicebus_data_owner: Still creating... -azurerm_servicebus_queue.queue: Still creating... +azurerm_servicebus_queue.queue: Creation complete ... ... -azurerm_role_assignment.role_servicebus_data_owner: Still creating... -azurerm_role_assignment.role_servicebus_data_owner: Creation complete ... +azurerm_role_assignment.role_servicebus_data_owner: ... -Apply complete! Resources: 8 added, 0 changed, 0 destroyed. +Apply complete! Resources: 6 added, 0 changed, 0 destroyed. Outputs: diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/main.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/main.tf index 2c901c9fa..59a456614 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/main.tf +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/main.tf @@ -53,21 +53,6 @@ resource "azurerm_servicebus_namespace" "servicebus_namespace" { } } -resource "azurecaf_name" "azurecaf_name_authorization_rule" { - name = var.application_name - resource_type = "azurerm_servicebus_namespace_authorization_rule" -} - -resource "azurerm_servicebus_namespace_authorization_rule" "authorization_rule" { - name = azurecaf_name.azurecaf_name_authorization_rule.result - namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name - resource_group_name = azurerm_resource_group.main.name - - listen = true - send = true - manage = true -} - resource "azurerm_servicebus_queue" "queue" { name = "que001" namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id @@ -80,7 +65,6 @@ resource "azurerm_servicebus_queue" "queue" { default_message_ttl = "P14D" } - data "azurerm_client_config" "current" { } diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/setup_env.sh b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/setup_env.sh index 1910486af..b79c4fc80 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/setup_env.sh +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/setup_env.sh @@ -1,5 +1,2 @@ export AZURE_SERVICEBUS_NAMESPACE=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_NAMESPACE) export AZURE_SERVICEBUS_QUEUE_NAME=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_QUEUE_NAME) - - - diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/README.md b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/README.md index 8ccafc98a..295031613 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/README.md +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/README.md @@ -77,30 +77,28 @@ terraform -chdir=./terraform apply ``` - - - It may take a few minutes to run the script. After successful running, you will see prompt information like below: ```shell - -azurecaf_name.azurecaf_name_servicebus: Creating... azurecaf_name.resource_group: Creating... -azurecaf_name.servicebus_namespace_authorization_rule: Creating... -azurecaf_name.azurecaf_name_servicebus: Creation complete after 0s [id=ggntexahlqdfmbkj] -azurecaf_name.resource_group: Creation complete after 0s [id=euikvcxceagwuaqw] -azurecaf_name.servicebus_namespace_authorization_rule: Creation complete after 0s [id=kifnoeclhdayfgek] +azurecaf_name.azurecaf_name_servicebus: Creating... +azurecaf_name.resource_group: Creation complete ... +azurecaf_name.azurecaf_name_servicebus: Creation complete ... azurerm_resource_group.main: Creating... -azurerm_resource_group.main: Creation complete after 5s ... +azurerm_resource_group.main: Creation complete ... +azurerm_servicebus_namespace.servicebus_namespace: Creating... +... +azurerm_servicebus_namespace.servicebus_namespace: Creation complete ... +azurerm_role_assignment.role_servicebus_data_owner: Creating... +azurerm_servicebus_topic.servicebus_topic: Creating... +azurerm_servicebus_topic.servicebus_topic: Creation complete ... +azurerm_servicebus_subscription.servicebus_subscription: Creating... ... +azurerm_servicebus_subscription.servicebus_subscription: Creation complete... ... -azurerm_servicebus_namespace_authorization_rule.authorization_rule: Creation complete after 15s ... -azurerm_role_assignment.role_servicebus_data_owner: Still creating... -azurerm_servicebus_subscription.servicebus_subscription: Still creating... -azurerm_servicebus_subscription.servicebus_subscription: Creation complete after 15s ... -azurerm_role_assignment.role_servicebus_data_owner: Creation complete after 28s ... +azurerm_role_assignment.role_servicebus_data_owner: Creation complete ... -Apply complete! Resources: 9 added, 0 changed, 0 destroyed. +Apply complete! Resources: 7 added, 0 changed, 0 destroyed. Outputs: diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/main.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/main.tf index 582007fd3..4f353578b 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/main.tf +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/main.tf @@ -53,32 +53,15 @@ resource "azurerm_servicebus_namespace" "servicebus_namespace" { } } -resource "azurecaf_name" "servicebus_namespace_authorization_rule" { - name = var.application_name - resource_type = "azurerm_servicebus_namespace_authorization_rule" -} - -resource "azurerm_servicebus_namespace_authorization_rule" "authorization_rule" { - name = azurecaf_name.servicebus_namespace_authorization_rule.result - namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name - resource_group_name = azurerm_resource_group.main.name - - listen = true - send = true - manage = true -} - resource "azurerm_servicebus_topic" "servicebus_topic" { name = "tpc001" - namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name - resource_group_name = azurerm_resource_group.main.name + namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id } resource "azurerm_servicebus_subscription" "servicebus_subscription" { name = "sub001" - resource_group_name = azurerm_resource_group.main.name - namespace_name = azurerm_servicebus_namespace.servicebus_namespace.name - topic_name = azurerm_servicebus_topic.servicebus_topic.name + topic_id = azurerm_servicebus_topic.servicebus_topic.id + max_delivery_count = 1 } diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/setup_env.sh b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/setup_env.sh index 2091a168d..c1ec4ae3a 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/setup_env.sh +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/setup_env.sh @@ -1,5 +1,3 @@ export AZURE_SERVICEBUS_NAMESPACE=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_NAMESPACE) export AZURE_SERVICEBUS_TOPIC_NAME=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_TOPIC_NAME) export AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME) - - From 98015d347cbbf4a6859999cd871a65c3f252ab8a Mon Sep 17 00:00:00 2001 From: zhihaoguo Date: Wed, 12 Jan 2022 12:51:22 +0800 Subject: [PATCH 04/12] update shell scripts --- .../single-namespace/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/README.md b/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/README.md index 8ec300b6e..5f9e3ef29 100644 --- a/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/README.md +++ b/servicebus/spring-cloud-azure-starter-integration-servicebus/single-namespace/README.md @@ -126,7 +126,7 @@ mvn clean spring-boot:run 1. Send a POST request to service bus queue - $ curl -X POST http://localhost:8080/queues?message=hello + curl -X POST http://localhost:8080/queues?message=hello 2. Verify in your app’s logs that similar messages were posted: @@ -134,7 +134,7 @@ mvn clean spring-boot:run Message 'hello' successfully checkpointed 3. Send a POST request to service bus topic - $ curl -X POST http://localhost:8080/topics?message=hello + curl -X POST http://localhost:8080/topics?message=hello 4. Verify in your app’s logs that similar messages were posted: From a0e6925710e4657e051bdd14cca4c0d125efdae3 Mon Sep 17 00:00:00 2001 From: zhihaoguo Date: Wed, 12 Jan 2022 13:01:26 +0800 Subject: [PATCH 05/12] format readme files --- .../servicebus-jms-queue/README.md | 2 +- .../servicebus-jms-topic/README.md | 2 +- .../servicebus-queue-binder/README.md | 3 --- .../servicebus-topic-binder/README.md | 4 ---- 4 files changed, 2 insertions(+), 9 deletions(-) diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/README.md b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/README.md index 0a08594dc..f27da4579 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/README.md +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/README.md @@ -123,7 +123,7 @@ mvn clean spring-boot:run 1. Send a POST request to service bus queue. ``` - $ curl -d "" http://localhost:8080/queue?message=hello + curl -d "" http://localhost:8080/queue?message=hello ``` 2. Verify in your app's logs that a similar message was posted: diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/README.md b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/README.md index 1e4045ef9..8755b7db6 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/README.md +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/README.md @@ -119,7 +119,7 @@ mvn clean spring-boot:run 1. Send a POST request to service bus topic. ``` - $ curl http://localhost:8080/topic?message=hello -d "" + curl http://localhost:8080/topic?message=hello -d "" ``` 2. Verify in your app's logs that a similar message was posted: diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/README.md b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/README.md index 67d0a7f00..e500ecb12 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/README.md +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/README.md @@ -78,9 +78,6 @@ terraform -chdir=./terraform apply ``` - - - It may take a few minutes to run the script. After successful running, you will see prompt information like below: ```shell diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/README.md b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/README.md index 295031613..e8ad6d1f5 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/README.md +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/README.md @@ -130,7 +130,6 @@ mvn clean spring-boot:run ```shell ... -... New message received: 'Hello world, 2' ... Message 'Hello world, 2' successfully checkpointed @@ -139,7 +138,6 @@ New message received: 'Hello world, 3' ... Message 'Hello world, 3' successfully checkpointed ... -... ``` ## Clean Up Resources @@ -152,8 +150,6 @@ To destroy the resources you created. terraform -chdir=./terraform destroy ``` - - ## Enhancement ### Configuration Options From 2459b37a930c4bf8537bb18a9e700cc23b5ea5e7 Mon Sep 17 00:00:00 2001 From: zhihaoguo Date: Wed, 12 Jan 2022 13:43:09 +0800 Subject: [PATCH 06/12] delete Enhancement section --- .../servicebus-multibinders/README.md | 133 ------------------ .../servicebus-queue-binder/README.md | 133 ------------------ .../servicebus-topic-binder/README.md | 130 ----------------- 3 files changed, 396 deletions(-) diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md index f17a906bf..ac4aee254 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md @@ -162,136 +162,3 @@ To destroy the resources you created. ```shell terraform -chdir=./terraform destroy ``` - - -## Enhancement -### Configuration Options - -The binder provides the following configuration options: - -##### Service Bus Producer Properties - -It supports the following configurations with the format of `spring.cloud.stream.servicebus.bindings..producer`. - -**_sync_** - -Whether the producer should act in a synchronous manner with respect to writing messages into a stream. If true, the -producer will wait for a response after a send operation. - -Default: `false` - -**_send-timeout_** - -Effective only if `sync` is set to true. The amount of time to wait for a response after a send operation, in milliseconds. - -Default: `10000` - -##### Service Bus Consumer Properties - -It supports the following configurations with the format of `spring.cloud.stream.servicebus.bindings..consumer`. - -**_checkpoint-mode_** - -The mode in which checkpoints are updated. - -`RECORD`, checkpoints occur after each record successfully processed by user-defined message handler without any exception. - -`MANUAL`, checkpoints occur on demand by the user via the `Checkpointer`. You can get `Checkpointer` by `Message.getHeaders.get(AzureHeaders.CHECKPOINTER)`callback. - -Default: `RECORD` - -**_prefetch-count_** - -Prefetch count of underlying service bus client. - -Default: `1` - -**_maxConcurrentCalls_** - -Controls the max concurrent calls of service bus message handler and the size of fixed thread pool that handles user's business logic - -Default: `1` - -**_maxConcurrentSessions_** - -Controls the maximum number of concurrent sessions to process at any given time. - -Default: `1` - -**_concurrency_** - -When `sessionsEnabled` is true, controls the maximum number of concurrent sessions to process at any given time. -When `sessionsEnabled` is false, controls the max concurrent calls of service bus message handler and the size of fixed thread pool that handles user's business logic. - -Deprecated, replaced with `maxConcurrentSessions` when `sessionsEnabled` is true and `maxConcurrentCalls` when `sessionsEnabled` is false - -Default: `1` - -**_sessionsEnabled_** - -Controls if is a session aware consumer. Set it to `true` if is a queue with sessions enabled. - -Default: `false` - -**_requeueRejected_** - -Controls if is a message that trigger any exception in consumer will be force to DLQ. -Set it to `true` if a message that trigger any exception in consumer will be force to DLQ. -Set it to `false` if a message that trigger any exception in consumer will be re-queued. - -Default: `false` - -**_receiveMode_** - -The modes for receiving messages. - -`PEEK_LOCK`, received message is not deleted from the queue or subscription, instead it is temporarily locked to the receiver, making it invisible to other receivers. - -`RECEIVE_AND_DELETE`, received message is removed from the queue or subscription and immediately deleted. - -Default: `PEEK_LOCK` - -**_enableAutoComplete_** - -Enable auto-complete and auto-abandon of received messages. -'enableAutoComplete' is not needed in for RECEIVE_AND_DELETE mode. - -Default: `false` -### Set message headers -The following table illustrates how Spring message headers are mapped to Service Bus message headers and properties. -When creat a message, developers can specify the header or property of a Service Bus message by below constants. - -```java - @Autowired -private Sinks.Many> many; - -@PostMapping("/messages") -public ResponseEntity sendMessage(@RequestParam String message) { - many.emitNext(MessageBuilder.withPayload(message) - .setHeader(SESSION_ID, "group1") - .build(), - Sinks.EmitFailureHandler.FAIL_FAST); - return ResponseEntity.ok("Sent!"); - } -``` - -For some Service Bus headers that can be mapped to multiple Spring header constants, the priority of different Spring headers is listed. - -Service Bus Message Headers and Properties | Spring Message Header Constants | Type | Priority Number (Descending priority) -:---|:---|:---|:--- -ContentType | org.springframework.messaging.MessageHeaders.CONTENT_TYPE | String | N/A -CorrelationId | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.CORRELATION_ID | String | N/A -**MessageId** | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.MESSAGE_ID | String | 1 -**MessageId** | com.azure.spring.messaging.AzureHeaders.RAW_ID | String | 2 -**MessageId** | org.springframework.messaging.MessageHeaders.ID | UUID | 3 -PartitionKey | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.PARTITION_KEY | String | N/A -ReplyTo | org.springframework.messaging.MessageHeaders.REPLY_CHANNEL | String | N/A -ReplyToSessionId | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.REPLY_TO_SESSION_ID | String | N/A -**ScheduledEnqueueTimeUtc** | com.azure.spring.messaging.AzureHeaders.SCHEDULED_ENQUEUE_MESSAGE | Integer | 1 -**ScheduledEnqueueTimeUtc** | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.SCHEDULED_ENQUEUE_TIME | Instant | 2 -SessionID | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.SESSION_ID | String | N/A -TimeToLive | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.TIME_TO_LIVE | Duration | N/A -To | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.TO | String | N/A - - - diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/README.md b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/README.md index e500ecb12..3f88e0e8b 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/README.md +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/README.md @@ -151,136 +151,3 @@ To destroy the resources you created. ```shell terraform -chdir=./terraform destroy ``` - -## Enhancement - -### Configuration Options - -The binder provides the following configuration options: - -##### Service Bus Producer Properties - -It supports the following configurations with the format of `spring.cloud.stream.servicebus.bindings..producer`. - -**_sync_** - -Whether the producer should act in a synchronous manner with respect to writing messages into a stream. If true, the -producer will wait for a response after a send operation. - -Default: `false` - -**_send-timeout_** - -Effective only if `sync` is set to true. The amount of time to wait for a response after a send operation, in milliseconds. - -Default: `10000` - -##### Service Bus Consumer Properties - -It supports the following configurations with the format of `spring.cloud.stream.servicebus.bindings..consumer`. - -**_checkpoint-mode_** - -The mode in which checkpoints are updated. - -`RECORD`, checkpoints occur after each record successfully processed by user-defined message handler without any exception. - -`MANUAL`, checkpoints occur on demand by the user via the `Checkpointer`. You can get `Checkpointer` by `Message.getHeaders.get(AzureHeaders.CHECKPOINTER)`callback. - -Default: `RECORD` - -**_prefetch-count_** - -Prefetch count of underlying service bus client. - -Default: `1` - -**_maxConcurrentCalls_** - -Controls the max concurrent calls of service bus message handler and the size of fixed thread pool that handles user's business logic - -Default: `1` - -**_maxConcurrentSessions_** - -Controls the maximum number of concurrent sessions to process at any given time. - -Default: `1` - -**_concurrency_** - -When `sessionsEnabled` is true, controls the maximum number of concurrent sessions to process at any given time. -When `sessionsEnabled` is false, controls the max concurrent calls of service bus message handler and the size of fixed thread pool that handles user's business logic. - -Deprecated, replaced with `maxConcurrentSessions` when `sessionsEnabled` is true and `maxConcurrentCalls` when `sessionsEnabled` is false - -Default: `1` - -**_sessionsEnabled_** - -Controls if is a session aware consumer. Set it to `true` if is a queue with sessions enabled. - -Default: `false` - -**_requeueRejected_** - -Controls if is a message that trigger any exception in consumer will be force to DLQ. -Set it to `true` if a message that trigger any exception in consumer will be force to DLQ. -Set it to `false` if a message that trigger any exception in consumer will be re-queued. - -Default: `false` - -**_receiveMode_** - -The modes for receiving messages. - -`PEEK_LOCK`, received message is not deleted from the queue or subscription, instead it is temporarily locked to the receiver, making it invisible to other receivers. - -`RECEIVE_AND_DELETE`, received message is removed from the queue or subscription and immediately deleted. - -Default: `PEEK_LOCK` - -**_enableAutoComplete_** - -Enable auto-complete and auto-abandon of received messages. -'enableAutoComplete' is not needed in for RECEIVE_AND_DELETE mode. - -Default: `false` -### Set Service Bus message headers -The following table illustrates how Spring message headers are mapped to Service Bus message headers and properties. -When creat a message, developers can specify the header or property of a Service Bus message by below constants. - -```java - @Autowired -private Sinks.Many> many; - -@PostMapping("/messages") -public ResponseEntity sendMessage(@RequestParam String message) { - many.emitNext(MessageBuilder.withPayload(message) - .setHeader(SESSION_ID, "group1") - .build(), - Sinks.EmitFailureHandler.FAIL_FAST); - return ResponseEntity.ok("Sent!"); - } -``` - -For some Service Bus headers that can be mapped to multiple Spring header constants, the priority of different Spring headers is listed. - -Service Bus Message Headers and Properties | Spring Message Header Constants | Type | Priority Number (Descending priority) -:---|:---|:---|:--- -ContentType | org.springframework.messaging.MessageHeaders.CONTENT_TYPE | String | N/A -CorrelationId | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.CORRELATION_ID | String | N/A -**MessageId** | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.MESSAGE_ID | String | 1 -**MessageId** | com.azure.spring.messaging.AzureHeaders.RAW_ID | String | 2 -**MessageId** | org.springframework.messaging.MessageHeaders.ID | UUID | 3 -PartitionKey | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.PARTITION_KEY | String | N/A -ReplyTo | org.springframework.messaging.MessageHeaders.REPLY_CHANNEL | String | N/A -ReplyToSessionId | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.REPLY_TO_SESSION_ID | String | N/A -**ScheduledEnqueueTimeUtc** | com.azure.spring.messaging.AzureHeaders.SCHEDULED_ENQUEUE_MESSAGE | Integer | 1 -**ScheduledEnqueueTimeUtc** | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.SCHEDULED_ENQUEUE_TIME | Instant | 2 -SessionID | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.SESSION_ID | String | N/A -TimeToLive | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.TIME_TO_LIVE | Duration | N/A -To | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.TO | String | N/A - - - diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/README.md b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/README.md index e8ad6d1f5..dfef10061 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/README.md +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/README.md @@ -149,133 +149,3 @@ To destroy the resources you created. ```shell terraform -chdir=./terraform destroy ``` - -## Enhancement -### Configuration Options - -The binder provides the following configuration options: - -##### Service Bus Producer Properties - -It supports the following configurations with the format of `spring.cloud.stream.servicebus.bindings..producer`. - -**_sync_** - -Whether the producer should act in a synchronous manner with respect to writing messages into a stream. If true, the -producer will wait for a response after a send operation. - -Default: `false` - -**_send-timeout_** - -Effective only if `sync` is set to true. The amount of time to wait for a response after a send operation, in milliseconds. - -Default: `10000` - -##### Service Bus Consumer Properties - -It supports the following configurations with the format of `spring.cloud.stream.servicebus.bindings..consumer`. - -**_checkpoint-mode_** - -The mode in which checkpoints are updated. - -`RECORD`, checkpoints occur after each record successfully processed by user-defined message handler without any exception. - -`MANUAL`, checkpoints occur on demand by the user via the `Checkpointer`. You can get `Checkpointer` by `Message.getHeaders.get(AzureHeaders.CHECKPOINTER)`callback. - -Default: `RECORD` - -**_prefetch-count_** - -Prefetch count of underlying service bus client. - -Default: `1` - -**_maxConcurrentCalls_** - -Controls the max concurrent calls of service bus message handler and the size of fixed thread pool that handles user's business logic - -Default: `1` - -**_maxConcurrentSessions_** - -Controls the maximum number of concurrent sessions to process at any given time. - -Default: `1` - -**_concurrency_** - -When `sessionsEnabled` is true, controls the maximum number of concurrent sessions to process at any given time. -When `sessionsEnabled` is false, controls the max concurrent calls of service bus message handler and the size of fixed thread pool that handles user's business logic. - -Deprecated, replaced with `maxConcurrentSessions` when `sessionsEnabled` is true and `maxConcurrentCalls` when `sessionsEnabled` is false - -Default: `1` - -**_sessionsEnabled_** - -Controls if is a session aware consumer. Set it to `true` if is a queue with sessions enabled. - -Default: `false` - -**_requeueRejected_** - -Controls if is a message that trigger any exception in consumer will be force to DLQ. -Set it to `true` if a message that trigger any exception in consumer will be force to DLQ. -Set it to `false` if a message that trigger any exception in consumer will be re-queued. - -Default: `false` - -**_receiveMode_** - -The modes for receiving messages. - -`PEEK_LOCK`, received message is not deleted from the queue or subscription, instead it is temporarily locked to the receiver, making it invisible to other receivers. - -`RECEIVE_AND_DELETE`, received message is removed from the queue or subscription and immediately deleted. - -Default: `PEEK_LOCK` - -**_enableAutoComplete_** - -Enable auto-complete and auto-abandon of received messages. -'enableAutoComplete' is not needed in for RECEIVE_AND_DELETE mode. - -Default: `false` -### Set Service Bus message headers -The following table illustrates how Spring message headers are mapped to Service Bus message headers and properties. -When creat a message, developers can specify the header or property of a Service Bus message by below constants. - -```java - @Autowired -private Sinks.Many> many; - -@PostMapping("/messages") -public ResponseEntity sendMessage(@RequestParam String message) { - many.emitNext(MessageBuilder.withPayload(message) - .setHeader(SESSION_ID, "group1") - .build(), - Sinks.EmitFailureHandler.FAIL_FAST); - return ResponseEntity.ok("Sent!"); - } -``` - -For some Service Bus headers that can be mapped to multiple Spring header constants, the priority of different Spring headers is listed. - -Service Bus Message Headers and Properties | Spring Message Header Constants | Type | Priority Number (Descending priority) -:---|:---|:---|:--- -ContentType | org.springframework.messaging.MessageHeaders.CONTENT_TYPE | String | N/A -CorrelationId | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.CORRELATION_ID | String | N/A -**MessageId** | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.MESSAGE_ID | String | 1 -**MessageId** | com.azure.spring.messaging.AzureHeaders.RAW_ID | String | 2 -**MessageId** | org.springframework.messaging.MessageHeaders.ID | UUID | 3 -PartitionKey | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.PARTITION_KEY | String | N/A -ReplyTo | org.springframework.messaging.MessageHeaders.REPLY_CHANNEL | String | N/A -ReplyToSessionId | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.REPLY_TO_SESSION_ID | String | N/A -**ScheduledEnqueueTimeUtc** | com.azure.spring.messaging.AzureHeaders.SCHEDULED_ENQUEUE_MESSAGE | Integer | 1 -**ScheduledEnqueueTimeUtc** | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.SCHEDULED_ENQUEUE_TIME | Instant | 2 -SessionID | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.SESSION_ID | String | N/A -TimeToLive | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.TIME_TO_LIVE | Duration | N/A -To | com.azure.spring.servicebus.support.ServiceBusMessageHeaders.TO | String | N/A - From 2d3afb36e5e7d9501a62f276ec6ddd0d9cd812f3 Mon Sep 17 00:00:00 2001 From: zhihaoguo Date: Thu, 13 Jan 2022 17:25:32 +0800 Subject: [PATCH 07/12] update shell log --- .../servicebus-multibinders/README.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md index ac4aee254..20961a170 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md @@ -6,7 +6,6 @@ a queue binder and a topic binder..The sample app has two operating modes. One w another way is to automatically provide string messages. These messages are published to a service bus. The sample will also consume messages from the same service bus. - ## What You Will Build You will build an application using Spring Cloud Stream to send and receive messages for multiple Azure Service Bus namespaces. @@ -78,9 +77,6 @@ terraform -chdir=./terraform apply ``` - - - It may take a few minutes to run the script. After successful running, you will see prompt information like below: ```shell @@ -124,14 +120,12 @@ Running the command below to export environment values: In your terminal, run `mvn clean spring-boot:run`. - ```shell mvn clean spring-boot:run ``` ## Verify This Sample - 1. Verify in your app’s logs that similar messages were posted: ```shell @@ -148,10 +142,12 @@ Message 'Hello world2, 3' successfully checkpointed Message 'Hello world2, 5' successfully checkpointed ... ... -``` - [2] New message2 received: 'hello' - [2] Message2 'hello' successfully checkpointed +Sending message2... +... +New message2 received... + +``` ## Clean Up Resources After running the sample, if you don't want to run the sample, remember to destroy the Azure resources you created to avoid unnecessary billing. From 0bcf18c173ad8b3e694baba38d4483e992586428 Mon Sep 17 00:00:00 2001 From: zhihaoguo Date: Mon, 17 Jan 2022 09:19:06 +0800 Subject: [PATCH 08/12] format main.tf --- .../servicebus-queue-binder/terraform/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/main.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/main.tf index 59a456614..5bb185364 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/main.tf +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/terraform/main.tf @@ -54,8 +54,8 @@ resource "azurerm_servicebus_namespace" "servicebus_namespace" { } resource "azurerm_servicebus_queue" "queue" { - name = "que001" - namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id + name = "que001" + namespace_id = azurerm_servicebus_namespace.servicebus_namespace.id enable_partitioning = false max_delivery_count = 10 From c8cbc9b8f393c25af0d44e39f67782cfb32026b9 Mon Sep 17 00:00:00 2001 From: zhihaoguo Date: Mon, 17 Jan 2022 09:26:07 +0800 Subject: [PATCH 09/12] add or delete empty lines --- .../multiple-namespaces/terraform/outputs.tf | 2 -- .../multiple-namespaces/terraform/variables.tf | 2 +- .../servicebus-jms-queue/README.md | 3 --- .../servicebus-jms-queue/terraform/outputs.tf | 2 +- .../servicebus-jms-queue/terraform/setup_env.sh | 2 +- .../servicebus-jms-queue/terraform/variables.tf | 2 +- .../servicebus-jms-topic/src/main/resources/application.yaml | 4 ---- .../servicebus-jms-topic/terraform/outputs.tf | 2 +- .../servicebus-jms-topic/terraform/variables.tf | 2 -- .../servicebus-multibinders/terraform/main.tf | 1 - .../servicebus-multibinders/terraform/outputs.tf | 2 -- .../servicebus-topic-binder/terraform/outputs.tf | 2 -- 12 files changed, 5 insertions(+), 21 deletions(-) diff --git a/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/outputs.tf b/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/outputs.tf index b2ae36231..abcaa22b5 100644 --- a/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/outputs.tf +++ b/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/outputs.tf @@ -7,5 +7,3 @@ output "AZURE_SERVICEBUS_NAMESPACE_02" { value = azurerm_servicebus_namespace.servicebus_namespace_02.name description = "The name of servicebus_02 namespace." } - - diff --git a/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/variables.tf b/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/variables.tf index 99326c152..9aa805112 100644 --- a/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/variables.tf +++ b/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/variables.tf @@ -14,4 +14,4 @@ variable "sample_tag_value" { type = string description = "The value of spring-cloud-azure-sample tag." default = "true" -} \ No newline at end of file +} diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/README.md b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/README.md index f27da4579..8c3223ea2 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/README.md +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/README.md @@ -74,9 +74,6 @@ terraform -chdir=./terraform apply ``` - - - It may take a few minutes to run the script. After successful running, you will see prompt information like below: ```shell diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/outputs.tf b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/outputs.tf index 27d2bb201..cdd44546f 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/outputs.tf +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/outputs.tf @@ -7,4 +7,4 @@ output "SERVICEBUS_NAMESPACE_CONNECTION_STRING" { output "PRICING_TIER" { value = var.pricing_tier description = "The pricing tier of Service Bus." -} \ No newline at end of file +} diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/setup_env.sh b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/setup_env.sh index fe2880e0b..7d461707b 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/setup_env.sh +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/setup_env.sh @@ -1,2 +1,2 @@ export SERVICEBUS_NAMESPACE_CONNECTION_STRING=$(terraform -chdir=./terraform output -raw SERVICEBUS_NAMESPACE_CONNECTION_STRING) -export PRICING_TIER=$(terraform -chdir=./terraform output -raw PRICING_TIER) \ No newline at end of file +export PRICING_TIER=$(terraform -chdir=./terraform output -raw PRICING_TIER) diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/variables.tf b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/variables.tf index 631172409..8a7994262 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/variables.tf +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-queue/terraform/variables.tf @@ -20,4 +20,4 @@ variable "pricing_tier" { type = string description = "The pricing tier of Service Bus." default = "Standard" -} \ No newline at end of file +} diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.yaml b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.yaml index 93c60e4f7..b600e87d2 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.yaml +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.yaml @@ -5,7 +5,3 @@ spring: idle-timeout: 1800000 pricing-tier: ${PRICING_TIER} topic-client-id: ${TOPIC_CLIENT_ID} - - - - diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/outputs.tf b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/outputs.tf index b4e430ffa..01a701549 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/outputs.tf +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/outputs.tf @@ -12,4 +12,4 @@ output "PRICING_TIER" { output "TOPIC_CLIENT_ID" { value = var.topic_client_id description = "The topic client id." -} \ No newline at end of file +} diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/variables.tf b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/variables.tf index cb9eb64c6..38dcfc24d 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/variables.tf +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/variables.tf @@ -27,5 +27,3 @@ variable "topic_client_id" { description = "The topic client id." default = "topic-client-id" } - - diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/main.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/main.tf index 60859d8bc..adde4d115 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/main.tf +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/main.tf @@ -114,4 +114,3 @@ resource "azurerm_role_assignment" "role_servicebus_data_owner_02" { role_definition_name = "Azure Service Bus Data Owner" principal_id = data.azurerm_client_config.client_config.object_id } - diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/outputs.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/outputs.tf index e370c906c..a17aad149 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/outputs.tf +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/terraform/outputs.tf @@ -24,5 +24,3 @@ output "AZURE_SERVICEBUS_QUEUE_NAME" { value = azurerm_servicebus_queue.servicebus_namespace_02_queue.name description = "The queue name in service bus namespace 02." } - - diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/outputs.tf b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/outputs.tf index 1e2c457ed..2df7cbc84 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/outputs.tf +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/terraform/outputs.tf @@ -11,6 +11,4 @@ output "AZURE_SERVICEBUS_TOPIC_NAME" { output "AZURE_SERVICEBUS_TOPIC_SUBSCRIPTION_NAME" { value = azurerm_servicebus_subscription.servicebus_subscription.name description = "The name of created subscription in the service bus namespace." - } - From 73032870d2ef2b98fc11832f67e67375096cc525 Mon Sep 17 00:00:00 2001 From: zhihaoguo Date: Mon, 17 Jan 2022 16:17:48 +0800 Subject: [PATCH 10/12] format by terraform fmt --- .../multiple-namespaces/terraform/main.tf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/main.tf b/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/main.tf index 0e3b9d37b..67af64089 100644 --- a/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/main.tf +++ b/servicebus/spring-cloud-azure-starter-integration-servicebus/multiple-namespaces/terraform/main.tf @@ -55,8 +55,8 @@ resource "azurerm_servicebus_namespace" "servicebus_namespace_01" { } resource "azurerm_servicebus_queue" "application_queue_01" { - name = "queue1" - namespace_id = azurerm_servicebus_namespace.servicebus_namespace_01.id + name = "queue1" + namespace_id = azurerm_servicebus_namespace.servicebus_namespace_01.id enable_partitioning = false max_delivery_count = 10 @@ -88,8 +88,8 @@ resource "azurerm_servicebus_namespace" "servicebus_namespace_02" { } resource "azurerm_servicebus_queue" "application_queue_02" { - name = "queue2" - namespace_id = azurerm_servicebus_namespace.servicebus_namespace_02.id + name = "queue2" + namespace_id = azurerm_servicebus_namespace.servicebus_namespace_02.id enable_partitioning = false max_delivery_count = 10 From 4a6335eaa125c8b07c7a28f36ddda29d302ec334 Mon Sep 17 00:00:00 2001 From: zhihaoguo Date: Mon, 17 Jan 2022 16:25:12 +0800 Subject: [PATCH 11/12] update topic-client-id --- .../src/main/resources/application.yaml | 2 +- .../servicebus-jms-topic/terraform/outputs.tf | 5 ----- .../servicebus-jms-topic/terraform/variables.tf | 6 ------ .../servicebus-multibinders/README.md | 2 +- 4 files changed, 2 insertions(+), 13 deletions(-) diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.yaml b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.yaml index b600e87d2..f618ed8cb 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.yaml +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/src/main/resources/application.yaml @@ -4,4 +4,4 @@ spring: connection-string: ${SERVICEBUS_NAMESPACE_CONNECTION_STRING} idle-timeout: 1800000 pricing-tier: ${PRICING_TIER} - topic-client-id: ${TOPIC_CLIENT_ID} + topic-client-id: topic-client-id diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/outputs.tf b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/outputs.tf index 01a701549..f93e98f79 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/outputs.tf +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/outputs.tf @@ -8,8 +8,3 @@ output "PRICING_TIER" { value = var.pricing_tier description = "The pricing tier of Service Bus." } - -output "TOPIC_CLIENT_ID" { - value = var.topic_client_id - description = "The topic client id." -} diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/variables.tf b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/variables.tf index 38dcfc24d..0bce33f59 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/variables.tf +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/variables.tf @@ -21,9 +21,3 @@ variable "pricing_tier" { description = "The pricing tier of Service Bus." default = "Standard" } - -variable "topic_client_id" { - type = string - description = "The topic client id." - default = "topic-client-id" -} diff --git a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md index 20961a170..73ee52345 100644 --- a/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md +++ b/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-multibinders/README.md @@ -2,7 +2,7 @@ This code sample demonstrates how to use the Spring Cloud Stream Binder for multiple Azure Service Bus namespaces. In this sample you will bind to two Service Bus namespaces separately through -a queue binder and a topic binder..The sample app has two operating modes. One way is to expose a Restful API to receive string message, +a queue binder and a topic binder.The sample app has two operating modes. One way is to expose a Restful API to receive string message, another way is to automatically provide string messages. These messages are published to a service bus. The sample will also consume messages from the same service bus. From 9f5331e7e6865c2aff7dbed5b253f691626deaa6 Mon Sep 17 00:00:00 2001 From: zhihaoguo Date: Mon, 17 Jan 2022 16:55:05 +0800 Subject: [PATCH 12/12] update setup_env.sh --- .../servicebus-jms-topic/terraform/setup_env.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/setup_env.sh b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/setup_env.sh index 7c3634e01..7af58f7f7 100644 --- a/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/setup_env.sh +++ b/servicebus/spring-cloud-azure-starter-servicebus-jms/servicebus-jms-topic/terraform/setup_env.sh @@ -1,3 +1,2 @@ export SERVICEBUS_NAMESPACE_CONNECTION_STRING=$(terraform -chdir=./terraform output -raw CONNECTION_STRING) export PRICING_TIER=$(terraform -chdir=./terraform output -raw PRICING_TIER) -export TOPIC_CLIENT_ID=$(terraform -chdir=./terraform output -raw TOPIC_CLIENT_ID)