Spring Cloud Azure Storage Queue Integration Code Sample

赵嘉悦
2023-12-01

This code sample demonstrates how to use Spring Integration for Azure Storage Queue.

Running this sample will be charged by Azure. You can check the usage and bill at this link.
Access key based usage

此代码示例演示如何对Azure存储队列使用Spring集成。
运行此示例将由Azure收费。你可以在这个链接上查看用法和帐单。
基于访问密钥的使用

Create Azure Storage

Update application.properties

spring.cloud.azure.storage.account=[storage-account-name]

# Fill storage account access key copied from portal
spring.cloud.azure.storage.access-key=[storage-account-accesskey]

Credential file based usage

Create azure credential file. Please see how to create credential file.

$  az login
$  az account set --subscription <name or id>
$  az ad sp create-for-rbac --sdk-auth > my.azureauth

Make sure my.azureauth is encoded with UTF-8.

Put credential file under src/main/resources/.

Create Azure Storage. Or enable auto create resources feature in application.properties:

spring.cloud.azure.auto-create-resources=true

# Example region is westUS, northchina
spring.cloud.azure.region=[region]

Update application.properties

# Enter 'my.azureauth' here if following step 1 and 2
spring.cloud.azure.credential-file-path=[credential-file-path]

spring.cloud.azure.resource-group=[resource-group]

spring.cloud.azure.storage.account=[account-name]

How to run

Update environment if not is Global in application.properties

# Default environment is GLOBAL. Provide your own if in another environment
# Example environment is China, GLOBAL
# spring.cloud.azure.environment=[environment]

Update queue name in SendController and ReceiveController

Run the mvn clean spring-boot:run in the root of the code sample to get the app running.

Send a POST request

$ curl -X POST localhost:8080/messages?message=hello

Verify in your app’s logs that a similar message was posted:

New message received: 'hello'
Message 'hello' successfully checkpointed

Delete the resources on Azure Portal to avoid unexpected charges.

如果不是全局的,则更新环境应用程序.属性
#默认环境是全局的。在另一个环境中提供您自己的if
#例如环境是中国,全球
更新SendController和ReceiveController中的队列名称
运行mvn清洁弹簧-启动:磨合运行应用程序的代码示例的根。
发送POST请求
$curl-X柱本地主机:8080/消息?message=你好
在应用程序日志中验证是否已发布类似消息:
收到新消息:“你好”
消息“hello”已成功检查点
删除Azure门户上的资源以避免意外收费。

 类似资料:

相关阅读

相关文章

相关问答