Skip to main content
Dynamics 365 Community / Forums / Finance forum / How to Receive all fil...
Finance forum

How to Receive all files from Azure Service Bus Queue in D365 FO

editSubscribe (0) ShareShare
Posted on by 32
Hello All,
I have a scenario to pick all the available Files (Invoice files) from Azure service bus queue and process the file inside D365 FO.
As of now with the code below I am able to pick 1 file(First file)
For Example if the Queue has 5 Invoice files, my code should pick 5 invoice files  together and process it.
.Net code to read message: class name /AzureQueueLibrary/
public class ReceiveAzureQueue
        QueueClient queueClient;
        BrokeredMessage message;
        public void connect(string connectionString)
            queueClient = QueueClient.CreateFromConnectionString(connectionString, ReceiveMode.PeekLock);
        public Stream readMessage()
            message = queueClient.Receive();            
            var stream = message.GetBody<Stream>();          
            return (stream);
        public void completeMessage()
        public void close()
D365 Code to process the file:
AzureQueueLibrary.ReceiveAzureQueue ReceiveAzureQueue = new AzureQueueLibrary.ReceiveAzureQueue();               
var stream = ReceiveAzureQueue.readMessage();
Above readMessage() picks only first file now. How to check the count of files and get all the files into D365 and process the same.
Let me know if any sample code/reference available
  • Monikasree GM Profile Picture
    Monikasree GM 32 on at
    How to Receive all files from Azure Service Bus Queue in D365 FO
    Hello @Martin Dráb ,
    Thank you for providing the clarity. 
    Now I am able to iterate the queue and process messages at a time and finally once I do not have any message in queue, I am closing the queue connection.
  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 222,601 Super User on at
    How to Receive all files from Azure Service Bus Queue in D365 FO
    You shouldn't try to check the number of messages. It's a queue, therefore you remove messages at one end and new messages may be being added at the other end. Let's say that there are three messages, but before you process them, two more are added. With your solution, you'd ignore the last two.
    You should simply take a message from a queue, process it, then take another message from a queue and so on, until there is no message remaining.

Helpful resources

Quick Links

New Blog Features Released!

Check out the new community blog features for viewers and authors…

Setting Up Knowledge Sources for Copilot…

Look at how configuring a comprehensive knowledge base is crucial…

Demystifying Copilot with Georg Glantschnig…

Industry experts answer burning questions directly from our amazing Community…


Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,080 Super User

Martin Dráb Profile Picture

Martin Dráb 222,601 Super User

nmaenpaa Profile Picture

nmaenpaa 101,138

Featured topics

Product updates

Dynamics 365 release plans