Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

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

(0) ShareShare
ReportReport
Posted on by 41
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()
        {
            queueClient.Complete(message.LockToken);
        }
 
        public void close()
        {
            queueClient.Close();
        }
    }
 
D365 Code to process the file:
AzureQueueLibrary.ReceiveAzureQueue ReceiveAzureQueue = new AzureQueueLibrary.ReceiveAzureQueue();               
ReceiveAzureQueue.connect(connectionString);       
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
 
Regards,
Monika
  • Monikasree GM Profile Picture
    41 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.
     
    Regards,
    Monika
  • Verified answer
    Martin Dráb Profile Picture
    231,895 Most Valuable Professional 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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,123 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,895 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans