Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resource manager usage for sample readme #169

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ terraform -chdir=./terraform apply -auto-approve

```




It may take a few minutes to run the script. After successful running, you will see prompt information like below:

```shell
Expand Down Expand Up @@ -107,7 +104,7 @@ You can go to [Azure portal](https://ms.portal.azure.com/) in your web browser t
Running the command below to export environment values:

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

## Run Locally
Expand Down Expand Up @@ -145,6 +142,41 @@ To destroy the resources you created.
terraform -chdir=./terraform destroy -auto-approve
```

### Use Azure Resource Manager to retrieve connection string
saragluna marked this conversation as resolved.
Show resolved Hide resolved

saragluna marked this conversation as resolved.
Show resolved Hide resolved
If you don't want to configure connection string in your application, it's also possible to use Azure Resource Manager to retrieve the connection string. Just make sure the principal have sufficient permission to read resource metadata.

1. After [Provision the Resources](#provision-the-resources) step, active the [application-rm.yaml][application-rm.yaml] profile file.

```yaml
spring:
cloud:
azure:
profile:
subscription-id: ${AZURE_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}
```
2. Add the Azure Resource Manager dependency
```xml
<dependency>
<groupId>com.azure.spring</groupId>
<artifactId>spring-cloud-azure-resourcemanager</artifactId>
</dependency>
```
3. Repeat steps [Run Locally](#run-locally) with the command `mvn clean spring-boot:run -Dspring-boot.run.profiles=rm` and [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 @@ -156,5 +188,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_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_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,2 +1,5 @@
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 EVENTHUBS_KAFKA=$(terraform -chdir=./terraform output -raw EVENTHUBS_KAFKA)
export AZURE_SUBSCRIPTION_ID=$(terraform -chdir=./terraform output -raw AZURE_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)