This project implements Azure Storage Queues in Business Central
Create Azure Storage Account and get your endpoint and Shared access Signature token
- Create new queue:
- Create new Sas token:
Fill out credentials in 'Setup Azure Store Queue Service'
Copy the Sas token and the first part of the endpoint into the Azure Storage Queue Service Setup in BC.
Test the connection.
You are ready to go.
Why use queues at all and not integrated via Odata/Soap etc?
Using message queues gives lots of flexibility. It allows you to process data asynchronously. Maybe you have IoT application that wants to post 10000 messages to Business Central in minute? Use message queues etc.
Theres codeunit codeunit 50100 "AzureStorageQueuesSdk"
which has following methods:
- PostMessageToQueue
- GetNextMessageFromQueue
- DeleteMessageFromQueue
- TestConnection
- EnsureQueueExists
- GetMessageIdFromXmlText
- GetMessagePopReceiptFromXmlText
- GetMessageTextFromXmlText
Theres also page 'Important Test page for queues'
which allowes to play around with the queues.
Example of how to use the SDK is below. This is probably not good idea to run in production yet but gives a idea how to work with the Azure queues and how to poll messages.
codeunit 50101 "Manage Queues"
{
procedure ProcessMessagesFromQueue(Queue: Text)
begin
if Process(Queue) then begin
Sleep(2000);
ProcessMessagesFromQueue(Queue);
end;
end;
local procedure Process(Queue: Text): Boolean
var
AzureStorageQueueSdk: Codeunit AzureStorageQueuesSdk;
MessageBody: Text;
MessageId:
509A
Text;
MessageText: Text;
MessagePopreceipt: Text;
ImportantTestTable: Record ImportantTestTable;
begin
MessageBody := AzureStorageQueueSdk.GetNextMessageFromQueue(Queue);
MessageId := AzureStorageQueueSdk.GetMessageIdFromXmlText(MessageBody);
MessageText := AzureStorageQueueSdk.GetMessageTextFromXmlText(MessageBody);
MessagePopreceipt := AzureStorageQueueSdk.GetMessagePopReceiptFromXmlText(MessageBody);
if (MessageId <> '') AND (MessageText <> '') then begin
ImportantTestTable.Init();
ImportantTestTable."Entry No." := ImportantTestTable.GetNextEntryNo();
ImportantTestTable.Message := MessageText;
if ImportantTestTable.Insert() then begin
//important here to check if delete is succesful and then commit. Otherwise we end in loop where messages are reappearing
if AzureStorageQueueSdk.DeleteMessageFromQueue(Queue, MessageId, MessagePopreceipt) then
Commit();
Process(Queue);
end;
end;
exit(true);
end;
procedure GenerateMessagesToQueue(Queue: Text; NumberOfMessages: Integer)
var
AzureStorageSdk: Codeunit AzureStorageQueuesSdk;
Counter: Integer;
begin
for Counter := 0 to NumberOfMessages do begin
AzureStorageSdk.PostMessageToQueue(Queue, 'This is important business data that needs queue: ' + format(Counter))
end;
end;
}