Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / How to Receive all fil...
Finance forum
Answered

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

Posted on by 33
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
    Monikasree GM 33 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
    Martin Dráb 225,864 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

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,584 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,864 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans