web
You’re offline. This is a read only version of the page.
close
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
I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,878 Most Valuable Professional on at
    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.
  • Monikasree GM Profile Picture
    41 on at
    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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 646 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans