zoukankan      html  css  js  c++  java
  • 使用Azure Runbook 发送消息到Azure Storage Queue

    客户需要定时发送信息到Azure Storage Queue,所以尝试使用Azure Runbook实现这个需求。

    首先新增一个Azure Automation Account的资源。

    因为要使用Az.storage模组发送消息到Queue, 但是这个模组并没有包含在默认模组中,所以要手动添加一下。选择 Shared resources 下面的 Modules gallery.

    因为Az.Storage依赖Az.Accounts模组,所以我们先搜索Az.Accounts, 找到后,双击打开新窗口,点击Import。导入大概需要几分钟,导入成功后,我们重复同样的步骤添加Az.Storage模组。

     都添加成功后,我们就可以添加我们的Runbook了

    从左边的菜单栏选择Runbooks,然后Create a runbook, 输入名字,选择类型Powershell

     具体的powershell脚本如下

    $connectionName = "AzureRunAsConnection"
    
    $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName 
    
    Write-Output($servicePrincipalConnection.TenantId)
     
    Connect
    -AzAccount ` -ServicePrincipal ` -Tenant $servicePrincipalConnection.TenantId ` -ApplicationId $servicePrincipalConnection.ApplicationId ` -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint $storageAccount=Get-AzStorageAccount -ResourceGroupName "******" -StorageAccountName "********" #这里输入你自己的resource group名字和storage account的名字。 $ctx=$storageAccount.Context $queue=Get-AzStorageQueue -Name "test-spfx" -Context $ctx $queueMessage = [Microsoft.Azure.Storage.Queue.CloudQueueMessage]::new("This is message from runbook") $queue.CloudQueue.AddMessageAsync($QueueMessage) Write-Output ("Send message to queue.")

    这里的AzureRunAsConnection是使用的资源组默认样例的参数,可以根据自己的实际需要修改或添加。具体位置是在Shared Resources下面的Connections

    最后可以测试runbook,去storage account下面检查,是否成功接收到消息。

  • 相关阅读:
    django监测登录成功事件
    大兔子生小兔子问题
    XML 命名空间(XML Namespaces)介绍以及节点读取方法
    喝汽水问题
    一个女程序员的男友需求说明书(转)
    ASP.NET学习(二)
    字典序排序
    如果说中国的程序员技术偏低,原因可能在这里(转)
    BI(摘)
    肝脏、心脏、脾脏、肺脏、肾脏的毒素表现以及食疗排毒
  • 原文地址:https://www.cnblogs.com/sharepointonline/p/14311383.html
Copyright © 2011-2022 走看看