Skip to content

Commit

Permalink
Refactor samples with terraform and defaultCredential for Servicebus …
Browse files Browse the repository at this point in the history
…samples (#138)
  • Loading branch information
backwind1233 authored Jan 17, 2022
1 parent 52b2f02 commit 1c7e4df
Show file tree
Hide file tree
Showing 46 changed files with 1,247 additions and 1,250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ mvn clean spring-boot:run
## Verify This Sample


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.
...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -55,9 +55,8 @@ 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
name = "queue1"
namespace_id = azurerm_servicebus_namespace.servicebus_namespace_01.id

enable_partitioning = false
max_delivery_count = 10
Expand Down Expand Up @@ -89,9 +88,8 @@ 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
name = "queue2"
namespace_id = azurerm_servicebus_namespace.servicebus_namespace_02.id

enable_partitioning = false
max_delivery_count = 10
Expand All @@ -104,13 +102,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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
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."
}


Original file line number Diff line number Diff line change
@@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
...

```

Expand All @@ -116,17 +126,17 @@ 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 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
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 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -53,25 +53,9 @@ 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" "application" {
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_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
Expand All @@ -88,22 +72,20 @@ 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
}

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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
output "SERVICEBUS_NAMESPACE" {
value = azurerm_servicebus_namespace.servicebus_namespace.name
description = "The servicebus namespace."
description = "The name of servicebus namespace."
}

Original file line number Diff line number Diff line change
@@ -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"
}
Loading

0 comments on commit 1c7e4df

Please sign in to comment.