{Azure Logic Apps}チュートリアル: Azure Logic Apps を使用して、スケジュールに基づいて実行される自動化ワークフローを作成する

 

https://learn.microsoft.com/ja-jp/azure/logic-apps/tutorial-build-schedule-recurring-logic-app-workflow
https://learn.microsoft.com/ja-jp/azure/logic-apps/concepts-schedule-automated-recurring-tasks-workflows


Azure Logic Apps は、自動化された定期的なワークフローを作成し、スケジュールに従って実行するのに役立ちます。


-- 1. 前作業

az login --use-device-code
az account show

az version

az configure --list-defaults
az configure --defaults location=japaneast
az configure --list-defaults

az group create \
--name rg9999999 \
--location japaneast

az group list
az upgrade

 


-- 2. Service Bus 名前空間を作成

az servicebus namespace create \
--resource-group rg9999999 \
--name ns123 \
--location japaneast \
--sku Basic

az servicebus namespace list \
--resource-group rg9999999


-- 3. 名前空間にキューを作成

az servicebus queue create \
--resource-group rg9999999 \
--namespace-name ns123 \
--name queue01

az servicebus queue list \
--resource-group rg9999999 \
--namespace-name ns123

 

-- 4. 名前空間のプライマリ接続文字列を取得

az servicebus namespace authorization-rule keys list \
--resource-group rg9999999 \
--namespace-name ns123 \
--name RootManageSharedAccessKey \
--query primaryConnectionString \
--output tsv

 

-- 5. ロジック アプリを作成する


トリガー: スケジュール
アクション: キューにメッセージ送信

 

※リソースとして、API接続servicebusが必要であるが、
コマンドで作成する方法が不明、API接続のコンソールでも作成ボタンがないため、
コンソールからロジック アプリを作成する


az logic workflow list \
--resource-group rg9999999 \
--filter "(State eq 'Enabled')" \
--output "table"

az logic workflow show \
--resource-group rg9999999 \
--name flow123


-- 6. キュー確認アプリを実行する

pip install azure-servicebus

vim a.py

from azure.servicebus import ServiceBusClient, ServiceBusMessage

CONNECTION_STR = "Endpoint=sb://ns123.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=11111111111111111111111111111111111111111111"
QUEUE_NAME = "queue01"


# create a Service Bus client using the connection string
servicebus_client = ServiceBusClient.from_connection_string(conn_str=CONNECTION_STR, logging_enable=True)

with servicebus_client:
    # get the Queue Receiver object for the queue
    receiver = servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME, max_wait_time=3600)
    with receiver:
        for msg in receiver:
            print("Received: " + str(msg))
            # complete the message so that the message is removed from the queue
            receiver.complete_message(msg)


python a.py


-- 7. クリーンアップ

az logic workflow delete \
--resource-group rg9999999 \
--name flow123 \
--yes

 

az group list

az group delete \
--name rg9999999 \
--yes