Skip to content

Commit

Permalink
Add resource manager usage for sample readme (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
moarychan authored Feb 8, 2022
1 parent 16be0a4 commit ab48b75
Show file tree
Hide file tree
Showing 35 changed files with 220 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Running the command below to export environment values:
#### Run with Bash

```shell
source ./terraform/setup_env.sh
source ./terraform/setup_env.sh
```

#### Run with Powershell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Running the command below to export environment values:
#### Run with Bash

```shell
source ./terraform/setup_env.sh
source ./terraform/setup_env.sh
```

#### Run with Powershell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Running the command below to export environment values:
#### Run with Bash

```shell
source ./terraform/setup_env.sh
source ./terraform/setup_env.sh
```

#### Run with Powershell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Running the command below to export environment values:
#### Run with Bash

```shell
source ./terraform/setup_env.sh
source ./terraform/setup_env.sh
```

#### Run with Powershell
Expand Down Expand Up @@ -172,6 +172,23 @@ terraform -chdir=./terraform destroy -auto-approve
terraform -chdir=terraform destroy -auto-approve
```

## (Optional) Use Azure Resource Manager to Retrieve Connection String

If you don't want to configure the connection string in your application, it's also possible to use Azure Resource Manager to retrieve the connection string. Just make sure the principal has sufficient permission to read resource metadata.

1. Uncomment the Azure Resource Manager dependency in the *pom.xml* file.

```xml
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-resourcemanager</artifactId>
</dependency>
```

2. Run locally with the command `mvn clean spring-boot:run -Dspring-boot.run.profiles=rm` to activate the [application-rm.yaml][application-rm.yaml] profile file.

3. [Verify This Sample](#verify-this-sample).

## Troubleshooting

- Meet with `Creating topics with default partitions/replication factor are only supported in CreateTopicRequest version 4+` error.
Expand All @@ -184,4 +201,4 @@ terraform -chdir=terraform destroy -auto-approve
When this error is found, add this configuration item `spring.cloud.stream.kafka.binder.replicationFactor`, with the value set to at least 1. For more information, see [Spring Cloud Stream Kafka Binder Reference Guide](https://docs.spring.io/spring-cloud-stream-binder-kafka/docs/current/reference/html/spring-cloud-stream-binder-kafka.html).



[application-rm.yaml]: https://github.com/Azure-Samples/azure-spring-boot-samples/tree/spring-cloud-azure_4.0.0-beta.4/eventhubs/spring-cloud-azure-starter/spring-cloud-azure-sample-eventhubs-kafka/src/main/resources/application-rm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
spring:
cloud:
azure:
profile:
subscription-id: ${AZURE_EVENTHUBS_SUBSCRIPTION_ID}
eventhubs:
namespace: ${AZURE_EVENTHUBS_NAMESPACE}
resource:
resource-group: ${AZURE_EVENTHUBS_RESOURCE_GROUP}
stream:
function:
definition: consume;supply
bindings:
consume-in-0:
destination: ${EVENTHUBS_KAFKA}
group: $Default
supply-out-0:
destination: ${EVENTHUBS_KAFKA}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ resource "azurerm_resource_group" "main" {
}

# =================== eventhubs ================
data "azurerm_subscription" "current" { }

resource "azurecaf_name" "azurecaf_name_eventhubs" {
name = var.application_name
resource_type = "azurerm_eventhub_namespace"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ output "EVENTHUBS_KAFKA" {
description = "The name of created event hubs."
}

output "RESOURCE_GROUP_NAME" {
output "AZURE_EVENTHUBS_RESOURCE_GROUP" {
value = azurerm_resource_group.main.name
description = "The resource group name."
description = "The Event Hubs resource group name."
}

output "AZURE_EVENTHUBS_SUBSCRIPTION_ID" {
value = data.azurerm_subscription.current.subscription_id
description = "The subscription ID of the resource."
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
$env:AZURE_EVENTHUBS_CONNECTION_STRING=$(terraform -chdir=terraform output -raw AZURE_EVENTHUBS_CONNECTION_STRING)
$env:EVENTHUBS_KAFKA=$(terraform -chdir=terraform output -raw EVENTHUBS_KAFKA)
$env:AZURE_EVENTHUBS_SUBSCRIPTION_ID=$(terraform -chdir=terraform output -raw AZURE_EVENTHUBS_SUBSCRIPTION_ID)
$env:AZURE_EVENTHUBS_RESOURCE_GROUP=$(terraform -chdir=terraform output -raw AZURE_EVENTHUBS_RESOURCE_GROUP)
$env:AZURE_EVENTHUBS_NAMESPACE=$(terraform -chdir=terraform output -raw AZURE_EVENTHUBS_NAMESPACE)

echo AZURE_EVENTHUBS_CONNECTION_STRING=$env:AZURE_EVENTHUBS_CONNECTION_STRING
echo EVENTHUBS_KAFKA=$env:EVENTHUBS_KAFKA
echo AZURE_EVENTHUBS_SUBSCRIPTION_ID=$env:AZURE_EVENTHUBS_SUBSCRIPTION_ID
echo AZURE_EVENTHUBS_RESOURCE_GROUP=$env:AZURE_EVENTHUBS_RESOURCE_GROUP
echo AZURE_EVENTHUBS_NAMESPACE=$env:AZURE_EVENTHUBS_NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
export AZURE_EVENTHUBS_CONNECTION_STRING=$(terraform -chdir=./terraform output -raw AZURE_EVENTHUBS_CONNECTION_STRING)
export EVENTHUBS_KAFKA=$(terraform -chdir=./terraform output -raw EVENTHUBS_KAFKA)
export AZURE_EVENTHUBS_SUBSCRIPTION_ID=$(terraform -chdir=./terraform output -raw AZURE_EVENTHUBS_SUBSCRIPTION_ID)
export AZURE_EVENTHUBS_RESOURCE_GROUP=$(terraform -chdir=./terraform output -raw AZURE_EVENTHUBS_RESOURCE_GROUP)
export AZURE_EVENTHUBS_NAMESPACE=$(terraform -chdir=./terraform output -raw AZURE_EVENTHUBS_NAMESPACE)


echo AZURE_EVENTHUBS_CONNECTION_STRING=$AZURE_EVENTHUBS_CONNECTION_STRING
echo EVENTHUBS_KAFKA=$EVENTHUBS_KAFKA
echo AZURE_EVENTHUBS_SUBSCRIPTION_ID=AZURE_EVENTHUBS_SUBSCRIPTION_ID
echo AZURE_EVENTHUBS_RESOURCE_GROUP=AZURE_EVENTHUBS_RESOURCE_GROUP
echo AZURE_EVENTHUBS_NAMESPACE=AZURE_EVENTHUBS_NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Running the command below to export environment values:
#### Run with Bash

```shell
source ./terraform/setup_env.sh
source ./terraform/setup_env.sh
```

#### Run with Powershell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Running the command below to export environment values:
#### Run with Bash

```shell
source ./terraform/setup_env.sh
source ./terraform/setup_env.sh
```

#### Run with Powershell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Running the command below to export environment values:
#### Run with Bash

```shell
source ./terraform/setup_env.sh
source ./terraform/setup_env.sh
```

#### Run with Powershell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Running the command below to export environment values:
#### Run with Bash

```shell
source ./terraform/setup_env.sh
source ./terraform/setup_env.sh
```

#### Run with Powershell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Running the command below to export environment values:
#### Run with Bash

```shell
source ./terraform/setup_env.sh
source ./terraform/setup_env.sh
```

#### Run with Powershell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ Running the command below to export environment values:
#### Run with Bash

```shell
source ./terraform/setup_env.sh
source ./terraform/setup_env.sh
```

#### Run with Powershell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Running the command below to export environment values:
#### Run with Bash

```shell
source ./terraform/setup_env.sh
source ./terraform/setup_env.sh
```

#### Run with Powershell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Running the command below to export environment values:
#### Run with Bash

```shell
source ./terraform/setup_env.sh
source ./terraform/setup_env.sh
```

#### Run with Powershell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Running the command below to export environment values:
#### Run with Bash

```shell
source ./terraform/setup_env.sh
source ./terraform/setup_env.sh
```

#### Run with Powershell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Running the command below to export environment values:
#### Run with Bash

```shell
source ./terraform/setup_env.sh
source ./terraform/setup_env.sh
```

#### Run with Powershell
Expand Down Expand Up @@ -180,3 +180,22 @@ terraform -chdir=./terraform destroy -auto-approve
```shell
terraform -chdir=terraform destroy -auto-approve
```

## (Optional) Use Azure Resource Manager to Retrieve Connection String

If you don't want to configure the connection string in your application, it's also possible to use Azure Resource Manager to retrieve the connection string. Just make sure the principal has sufficient permission to read resource metadata.

1. Uncomment the Azure Resource Manager dependency in the *pom.xml* file.

```xml
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-resourcemanager</artifactId>
</dependency>
```

2. Run locally with the command `mvn clean spring-boot:run -Dspring-boot.run.profiles=rm` to activate the [application-rm.yaml][application-rm.yaml] profile file.

3. [Verify This Sample](#verify-this-sample).

[application-rm.yaml]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0.0-beta.4/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-queue-binder/src/main/resources/application-rm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@


<dependencies>
<!-- Add the spring-cloud-azure-resourcemanager dependency when want to use the Azure Resource Manager to retrieve connection string -->
<!--
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-resourcemanager</artifactId>
</dependency>
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
spring:
cloud:
azure:
profile:
subscription-id: ${AZURE_SERVICEBUS_SUBSCRIPTION_ID}
servicebus:
namespace: ${AZURE_SERVICEBUS_NAMESPACE}
resource:
resource-group: ${AZURE_SERVICEBUS_RESOURCE_GROUP}
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
entity-type: queue
supply-out-0:
producer:
entity-type: queue
poller:
fixed-delay: 1000
initial-delay: 0
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ provider "azurerm" {
features {}
}

data "azurerm_subscription" "current" { }

resource "azurecaf_name" "resource_group" {
name = var.application_name
resource_type = "azurerm_resource_group"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ output "AZURE_SERVICEBUS_QUEUE_NAME" {
description = "The name of created queue in the service bus namespace."
}

output "RESOURCE_GROUP_NAME" {
output "AZURE_SERVICEBUS_RESOURCE_GROUP" {
value = azurerm_resource_group.main.name
description = "The resource group name."
description = "The Service Bus resource group name."
}

output "AZURE_SERVICEBUS_SUBSCRIPTION_ID" {
value = data.azurerm_subscription.current.subscription_id
description = "The subscription ID of the resource."
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
$env:AZURE_SERVICEBUS_NAMESPACE=$(terraform -chdir=terraform output -raw AZURE_SERVICEBUS_NAMESPACE)
$env:AZURE_SERVICEBUS_QUEUE_NAME=$(terraform -chdir=terraform output -raw AZURE_SERVICEBUS_QUEUE_NAME)
$env:AZURE_SERVICEBUS_SUBSCRIPTION_ID=$(terraform -chdir=terraform output -raw AZURE_SERVICEBUS_SUBSCRIPTION_ID)
$env:AZURE_SERVICEBUS_RESOURCE_GROUP=$(terraform -chdir=terraform output -raw AZURE_SERVICEBUS_RESOURCE_GROUP)

echo AZURE_SERVICEBUS_NAMESPACE=$env:AZURE_SERVICEBUS_NAMESPACE
echo AZURE_SERVICEBUS_QUEUE_NAME=$env:AZURE_SERVICEBUS_QUEUE_NAME
echo AZURE_SERVICEBUS_SUBSCRIPTION_ID=$env:AZURE_SERVICEBUS_SUBSCRIPTION_ID
echo AZURE_SERVICEBUS_RESOURCE_GROUP=$env:AZURE_SERVICEBUS_RESOURCE_GROUP
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
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)
export AZURE_SERVICEBUS_SUBSCRIPTION_ID=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_SUBSCRIPTION_ID)
export AZURE_SERVICEBUS_RESOURCE_GROUP=$(terraform -chdir=./terraform output -raw AZURE_SERVICEBUS_RESOURCE_GROUP)

echo AZURE_SERVICEBUS_NAMESPACE=$AZURE_SERVICEBUS_NAMESPACE
echo AZURE_SERVICEBUS_QUEUE_NAME=$AZURE_SERVICEBUS_QUEUE_NAME
echo AZURE_SERVICEBUS_SUBSCRIPTION_ID=AZURE_SERVICEBUS_SUBSCRIPTION_ID
echo AZURE_SERVICEBUS_RESOURCE_GROUP=AZURE_SERVICEBUS_RESOURCE_GROUP
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Running the command below to export environment values:
#### Run with Bash

```shell
source ./terraform/setup_env.sh
source ./terraform/setup_env.sh
```

#### Run with Powershell
Expand Down Expand Up @@ -178,3 +178,22 @@ terraform -chdir=./terraform destroy -auto-approve
```shell
terraform -chdir=terraform destroy -auto-approve
```

## (Optional) Use Azure Resource Manager to Retrieve Connection String

If you don't want to configure the connection string in your application, it's also possible to use Azure Resource Manager to retrieve the connection string. Just make sure the principal has sufficient permission to read resource metadata.

1. Uncomment the Azure Resource Manager dependency in the *pom.xml* file.

```xml
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-resourcemanager</artifactId>
</dependency>
```

2. Run locally with the command `mvn clean spring-boot:run -Dspring-boot.run.profiles=rm` to activate the [application-rm.yaml][application-rm.yaml] profile file.

3. [Verify This Sample](#verify-this-sample).

[application-rm.yaml]: https://github.com/Azure-Samples/azure-spring-boot-samples/blob/spring-cloud-azure_4.0.0-beta.4/servicebus/spring-cloud-azure-stream-binder-servicebus/servicebus-topic-binder/src/main/resources/application-rm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
<name>Communicate to a Single Service Bus Topic via Spring Cloud Stream</name>

<dependencies>
<!-- Add the spring-cloud-azure-resourcemanager dependency when want to use the Azure Resource Manager to retrieve connection string -->
<!--
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-resourcemanager</artifactId>
</dependency>
-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
Loading

0 comments on commit ab48b75

Please sign in to comment.