I am looking to create a .NET Core 2.2 console app that reads from a Azure Service Bus Queue. Messages are put on the queue by a CRM 2016 instance. The plan is to use the queue to notify externals when entities are created and/or updated.
I am able to read from the queue without issue using the following sample code.
var queueClient = new QueueClient(serviceBusConnectionString, queueName);
...
var messageHandlerOptions = new MessageHandlerOptions(this.ExceptionReceivedHandler) {
MaxConcurrentCalls = 1,
AutoComplete = false
};
queueClient.RegisterMessageHandler(this.ProcessMessagesAsync, messageHandlerOptions);
...
protected async Task ProcessMessagesAsync(Message message, CancellationToken token) {
// do something ??? with message body
byte[] body = message.Body;
await queueClient.CompleteAsync(message.SystemProperties.LockToken);
}
I have no problems reading from the queue and getting the message but I am unsure what to do next. All of the examples documentation I have found seems to work with an older version of the Azure Bus library and .NET Framework.
Once I have the Body property, what do I do with it? I assume I need to deserialize or cast it as a class but what class?
The samples on this site (https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/sample-one-way-listener) deal with the older library (https://www.nuget.org/packages/WindowsAzure.ServiceBus/). The samples include references to RemoteExecutionContext, BrokeredMessage (along with a GetBody() method) which does not seem to apply to newer library.
The samples on this site (https://github.com/Azure/azure-service-bus/tree/master/samples) are about Azure Bus in general and do not deal with CRM.
Am I using the correct library? Should I not be using Core? Can anybody point me to sample code that runs in .NET Core and interacts with queues and CRM?