Build blob trigger and storage queue for microservice

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.


service architecture


  1. prerequisites create resouce group -> Storage account

  2. create Storage queue for storing the messages(events)

  3. 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 config the event subscription

     the endpoit decides the outgoing of our message.

    choose endpoint

  4. generate the events for example: upload an object

  5. fetch the message from Storage Queue

    using the Azure Storage Queue SDK to fetch the event message, see below

  6. Read the payload and trigger your service

	import azure.functions as func
	from import BlockBlobService
	from import (
	from import QueueMessageFormat
	import os

	queueName = 'my-message-queue'
	accountName = 'my-storage-account'
	accessKey = 'xxxxxxxxx'
	queue_service = QueueService(account_name=storage_account,
	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)

Share Comments
comments powered by Disqus