Let's simplify publishing new NuGet packages for x++ builds
You are here
Reading From An Azure Queue
Out with the old and in with the new! For those who worked with 2012, files were a default integration option, for better or worse. However, we no longer have access to files and/or a file system. So, how are we going to get data to D365FO from on an on premise source? or a source in a different cloud? or even a source inside Azure? Easy! Enter the Azure Queue. We have an area we can push small messages to for D365FO to consume. There are a few hoops to jump though in order to get everything to work given some of the technical constraints with 4.5.2, 4.6.1 and CORE. My objective was to create a C# project that could live next to my unified operations project. To get all references in place, do the following:
Create a new console app
In the solution explorer, right click on reference and select "Manage NuGet Packages"

Search for WindowsAzure.ServiceBus. Click Install
Next, right click on references then "Add Reference..." then click on the browse button.
Find the Microsoft.ServiceBuss.dll in the following folder located in your projects root directory: packages\WindowsAzure.ServiceBus.5.0.0\lib\net46
Add it to your project.
Next, let's add a method to send a very simple message:
static void sendMessage()
{
string connectionString = "Endpoint=sb://[urlName].servicebus.windows.net/;SharedAccessKeyName=[AccessName];SharedAccessKey=[AccessKey];EntityPath=[QueueName]";
QueueClient queueClient;
string messageBody = "Test Message " + System.Guid.NewGuid();
BrokeredMessage message = new BrokeredMessage(messageBody);queueClient = QueueClient.CreateFromConnectionString(connectionString, ReceiveMode.PeekLock);
String s = message.GetBody<String>();
queueClient.Send(message);
queueClient.Close();
Console.WriteLine("message written: " + s );
}
As you can see, its very simple that we create a message with a unique identifier in the string representation for it then print it to the screen for what was sent successfully. Next, let's get that message back.
static void receiveMessage()
{
string connectionString = "Endpoint=sb://[urlName].servicebus.windows.net/;SharedAccessKeyName=[AccessName];SharedAccessKey=[AccessKey];EntityPath=[QueueName]";
QueueClient queueClient;
BrokeredMessage message;queueClient = QueueClient.CreateFromConnectionString(connectionString, ReceiveMode.PeekLock);
message = queueClient.Receive();
string s = message.GetBody<String>();
queueClient.Complete(message.LockToken);
queueClient.Close();
Console.WriteLine("received message: " + s);
}
Now we're grabbing whatever is next in the queue and displaying it to the screen. Again, a very simple example. Now, let's update Main() to call the methods:
static void Main(string[] args)
{
sendMessage();
receiveMessage();Console.ReadLine();
}
For the specifics of the code and all configurations of the project, the code can also be found on Github.













