In my last blog(here), I have demonstrated how to set up a Blob trigger uing the Microsoft Azure native product: Azure function to handle the events/updates.
but instead of creating an Azure funtion in cloud, we want an on-premise application, or a microservice with the tigger function embeded.
Solution 2: using RESTful API conncets Azure Storage Account.
Architecture:
Steps:
-
prerequisites create resouce group -> Storage account
-
create Storage queue for storing the messages(events)
-
set up Event Grid Subcription Event Subscription is kind of an agent which wires our Storage Account(which is exactaly our monitoring object) wire the Event subscription with specific Storage Blob
the endpoit decides the outgoing of our message.
-
generate the events for example: upload an object
-
fetch the message from Storage Queue
using the Azure Storage Queue SDK to fetch the event message, see below
-
Read the payload and trigger your service
import azure.functions as func
from azure.storage.blob import BlockBlobService
from azure.storage.queue import (
QueueService,
QueuePermissions)
from azure.storage.queue.models import QueueMessageFormat
import os
queueName = 'my-message-queue'
accountName = 'my-storage-account'
accessKey = 'xxxxxxxxx'
queue_service = QueueService(account_name=storage_account,
account_key=storage_access_key,
protocol='https')
queue_service.encode_function = QueueMessageFormat.text_base64encode
queue_service.decode_function = QueueMessageFormat.text_base64decode
msgs = queue_service.get_messages(queue_name, num_messages=1, visibility_timeout=5)
queue_service.delete_messages(queue_name, msgs[0].id, msgs[0].pop_receipt)