How to read from Microsoft.Azure.ServiceBus queue populated from CRM 2016












2















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?










share|improve this question























  • So, you can consume messages from the queue, but you dont know how to write to the queue - is that right?

    – iikkoo
    Jan 2 at 19:34











  • Negative. We are writing to the queue. I can read messages off the queue. But I am unsure how to handle the Body property of the Message object when I read from the queue using .NET Core and the new Microsoft.Azure.ServiceBus library. The classes that are in all of the documentation and samples for the older library do not exist in the new. And I cannot find any .NET Core sample apps.

    – Jason
    Jan 3 at 0:36


















2















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?










share|improve this question























  • So, you can consume messages from the queue, but you dont know how to write to the queue - is that right?

    – iikkoo
    Jan 2 at 19:34











  • Negative. We are writing to the queue. I can read messages off the queue. But I am unsure how to handle the Body property of the Message object when I read from the queue using .NET Core and the new Microsoft.Azure.ServiceBus library. The classes that are in all of the documentation and samples for the older library do not exist in the new. And I cannot find any .NET Core sample apps.

    – Jason
    Jan 3 at 0:36
















2












2








2








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?










share|improve this question














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?







.net-core dynamics-crm azure-servicebus-queues






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 19:17









JasonJason

1,10211533




1,10211533













  • So, you can consume messages from the queue, but you dont know how to write to the queue - is that right?

    – iikkoo
    Jan 2 at 19:34











  • Negative. We are writing to the queue. I can read messages off the queue. But I am unsure how to handle the Body property of the Message object when I read from the queue using .NET Core and the new Microsoft.Azure.ServiceBus library. The classes that are in all of the documentation and samples for the older library do not exist in the new. And I cannot find any .NET Core sample apps.

    – Jason
    Jan 3 at 0:36





















  • So, you can consume messages from the queue, but you dont know how to write to the queue - is that right?

    – iikkoo
    Jan 2 at 19:34











  • Negative. We are writing to the queue. I can read messages off the queue. But I am unsure how to handle the Body property of the Message object when I read from the queue using .NET Core and the new Microsoft.Azure.ServiceBus library. The classes that are in all of the documentation and samples for the older library do not exist in the new. And I cannot find any .NET Core sample apps.

    – Jason
    Jan 3 at 0:36



















So, you can consume messages from the queue, but you dont know how to write to the queue - is that right?

– iikkoo
Jan 2 at 19:34





So, you can consume messages from the queue, but you dont know how to write to the queue - is that right?

– iikkoo
Jan 2 at 19:34













Negative. We are writing to the queue. I can read messages off the queue. But I am unsure how to handle the Body property of the Message object when I read from the queue using .NET Core and the new Microsoft.Azure.ServiceBus library. The classes that are in all of the documentation and samples for the older library do not exist in the new. And I cannot find any .NET Core sample apps.

– Jason
Jan 3 at 0:36







Negative. We are writing to the queue. I can read messages off the queue. But I am unsure how to handle the Body property of the Message object when I read from the queue using .NET Core and the new Microsoft.Azure.ServiceBus library. The classes that are in all of the documentation and samples for the older library do not exist in the new. And I cannot find any .NET Core sample apps.

– Jason
Jan 3 at 0:36














1 Answer
1






active

oldest

votes


















1














The old ServiceBus SDK seems to do some deserialization for you, this you will need to do yourself now.



Looking at this example it seems that there is a Dynamics class called RemoteExecutionContext that is documented here and reading this it suggests you can set the data to be sent as JSON, looks like the default might be XML, but I've no idea.



If the data is sent as JSON you can deserialize by doing this:



protected async Task ProcessMessagesAsync(Message message, CancellationToken token) {

var bytesAsString = Encoding.UTF8.GetString(message.Body);
RemoteExecutionContext remoteExecutionContext = JsonConvert.DeserializeObject<RemoteExecutionContext>(bytesAsString);

await queueClient.CompleteAsync(message.SystemProperties.LockToken);
}


Note:



I had to install the nuget package Microsoft.Xrm.SDK.2015 to get a reference to the RemoteExecutionContext class, this package is build using .Net Framework so is not properly compatible with .Net Core






share|improve this answer
























  • Yeah. I ran into the same issue with respect to the classes in Microsoft.Xrm.SDK.* only being for .NET Framework. Seems that MS has no plans to port them over. I guess I could try to reproduce a subset of properties on the RemoteExecutionContext since ultimately all I need is the id of the entity that was created or modified...

    – Jason
    Jan 22 at 22:59












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011972%2fhow-to-read-from-microsoft-azure-servicebus-queue-populated-from-crm-2016%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














The old ServiceBus SDK seems to do some deserialization for you, this you will need to do yourself now.



Looking at this example it seems that there is a Dynamics class called RemoteExecutionContext that is documented here and reading this it suggests you can set the data to be sent as JSON, looks like the default might be XML, but I've no idea.



If the data is sent as JSON you can deserialize by doing this:



protected async Task ProcessMessagesAsync(Message message, CancellationToken token) {

var bytesAsString = Encoding.UTF8.GetString(message.Body);
RemoteExecutionContext remoteExecutionContext = JsonConvert.DeserializeObject<RemoteExecutionContext>(bytesAsString);

await queueClient.CompleteAsync(message.SystemProperties.LockToken);
}


Note:



I had to install the nuget package Microsoft.Xrm.SDK.2015 to get a reference to the RemoteExecutionContext class, this package is build using .Net Framework so is not properly compatible with .Net Core






share|improve this answer
























  • Yeah. I ran into the same issue with respect to the classes in Microsoft.Xrm.SDK.* only being for .NET Framework. Seems that MS has no plans to port them over. I guess I could try to reproduce a subset of properties on the RemoteExecutionContext since ultimately all I need is the id of the entity that was created or modified...

    – Jason
    Jan 22 at 22:59
















1














The old ServiceBus SDK seems to do some deserialization for you, this you will need to do yourself now.



Looking at this example it seems that there is a Dynamics class called RemoteExecutionContext that is documented here and reading this it suggests you can set the data to be sent as JSON, looks like the default might be XML, but I've no idea.



If the data is sent as JSON you can deserialize by doing this:



protected async Task ProcessMessagesAsync(Message message, CancellationToken token) {

var bytesAsString = Encoding.UTF8.GetString(message.Body);
RemoteExecutionContext remoteExecutionContext = JsonConvert.DeserializeObject<RemoteExecutionContext>(bytesAsString);

await queueClient.CompleteAsync(message.SystemProperties.LockToken);
}


Note:



I had to install the nuget package Microsoft.Xrm.SDK.2015 to get a reference to the RemoteExecutionContext class, this package is build using .Net Framework so is not properly compatible with .Net Core






share|improve this answer
























  • Yeah. I ran into the same issue with respect to the classes in Microsoft.Xrm.SDK.* only being for .NET Framework. Seems that MS has no plans to port them over. I guess I could try to reproduce a subset of properties on the RemoteExecutionContext since ultimately all I need is the id of the entity that was created or modified...

    – Jason
    Jan 22 at 22:59














1












1








1







The old ServiceBus SDK seems to do some deserialization for you, this you will need to do yourself now.



Looking at this example it seems that there is a Dynamics class called RemoteExecutionContext that is documented here and reading this it suggests you can set the data to be sent as JSON, looks like the default might be XML, but I've no idea.



If the data is sent as JSON you can deserialize by doing this:



protected async Task ProcessMessagesAsync(Message message, CancellationToken token) {

var bytesAsString = Encoding.UTF8.GetString(message.Body);
RemoteExecutionContext remoteExecutionContext = JsonConvert.DeserializeObject<RemoteExecutionContext>(bytesAsString);

await queueClient.CompleteAsync(message.SystemProperties.LockToken);
}


Note:



I had to install the nuget package Microsoft.Xrm.SDK.2015 to get a reference to the RemoteExecutionContext class, this package is build using .Net Framework so is not properly compatible with .Net Core






share|improve this answer













The old ServiceBus SDK seems to do some deserialization for you, this you will need to do yourself now.



Looking at this example it seems that there is a Dynamics class called RemoteExecutionContext that is documented here and reading this it suggests you can set the data to be sent as JSON, looks like the default might be XML, but I've no idea.



If the data is sent as JSON you can deserialize by doing this:



protected async Task ProcessMessagesAsync(Message message, CancellationToken token) {

var bytesAsString = Encoding.UTF8.GetString(message.Body);
RemoteExecutionContext remoteExecutionContext = JsonConvert.DeserializeObject<RemoteExecutionContext>(bytesAsString);

await queueClient.CompleteAsync(message.SystemProperties.LockToken);
}


Note:



I had to install the nuget package Microsoft.Xrm.SDK.2015 to get a reference to the RemoteExecutionContext class, this package is build using .Net Framework so is not properly compatible with .Net Core







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 3 at 17:56









matt_lethargicmatt_lethargic

2,10511227




2,10511227













  • Yeah. I ran into the same issue with respect to the classes in Microsoft.Xrm.SDK.* only being for .NET Framework. Seems that MS has no plans to port them over. I guess I could try to reproduce a subset of properties on the RemoteExecutionContext since ultimately all I need is the id of the entity that was created or modified...

    – Jason
    Jan 22 at 22:59



















  • Yeah. I ran into the same issue with respect to the classes in Microsoft.Xrm.SDK.* only being for .NET Framework. Seems that MS has no plans to port them over. I guess I could try to reproduce a subset of properties on the RemoteExecutionContext since ultimately all I need is the id of the entity that was created or modified...

    – Jason
    Jan 22 at 22:59

















Yeah. I ran into the same issue with respect to the classes in Microsoft.Xrm.SDK.* only being for .NET Framework. Seems that MS has no plans to port them over. I guess I could try to reproduce a subset of properties on the RemoteExecutionContext since ultimately all I need is the id of the entity that was created or modified...

– Jason
Jan 22 at 22:59





Yeah. I ran into the same issue with respect to the classes in Microsoft.Xrm.SDK.* only being for .NET Framework. Seems that MS has no plans to port them over. I guess I could try to reproduce a subset of properties on the RemoteExecutionContext since ultimately all I need is the id of the entity that was created or modified...

– Jason
Jan 22 at 22:59




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54011972%2fhow-to-read-from-microsoft-azure-servicebus-queue-populated-from-crm-2016%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith