Receive a Message from Service Bus Queue via .NET DLL

PierreC
Member Posts: 2
Dear all,
I would like to use a .NET DLL to process Azure Service Bus messages in NAV 2017.
I have imagined that I receive Service Bus Messages from a queue via the DLL, then fire an event in the DLL, which is caught in NAV via an event handler.
The event handler has a string as parameter, which contains the message.
Here is the code of the .NET DLL and the NAV code (see below).
My problem is that as soon as I start the Codeunit, NAV hangs completely or is blocked.
The problem will be that in the DLL _resetEvent.Wait(); is executed.
In a .NET console app this works fine and it behaves as I expect it to.
Unfortunately, however, it does not with the DLL and NAV.
If I omit the resetEvent.Wait();, the Start() function exits too quickly and the event handler cannot execute.
Do you guys have any other idea how I can solve this problem?
I need a solution where the function does not terminate too fast and at the same time does not block NAV.
NAV Code:
.NET Code:
I would like to use a .NET DLL to process Azure Service Bus messages in NAV 2017.
I have imagined that I receive Service Bus Messages from a queue via the DLL, then fire an event in the DLL, which is caught in NAV via an event handler.
The event handler has a string as parameter, which contains the message.
Here is the code of the .NET DLL and the NAV code (see below).
My problem is that as soon as I start the Codeunit, NAV hangs completely or is blocked.
The problem will be that in the DLL _resetEvent.Wait(); is executed.
In a .NET console app this works fine and it behaves as I expect it to.
Unfortunately, however, it does not with the DLL and NAV.
If I omit the resetEvent.Wait();, the Start() function exits too quickly and the event handler cannot execute.
Do you guys have any other idea how I can solve this problem?
I need a solution where the function does not terminate too fast and at the same time does not block NAV.
NAV Code:
OnRun() EventimWrapper.Start(); EventimWrapper::MessageReceive(msg : Text) MESSAGE(msg);
.NET Code:
public static void Start() { _resetEvent = new ManualResetEventSlim(false); ReceiveMessagesAsync().GetAwaiter().GetResult(); } static async Task ReceiveMessagesAsync() { _client = new ServiceBusClient(AZURE_SERVICE_BUS_CONNECTIONSTRING, new ServiceBusClientOptions { TransportType = ServiceBusTransportType.AmqpWebSockets }); _processor = _client.CreateSessionProcessor(QUEUE_NAME, new ServiceBusSessionProcessorOptions { MaxConcurrentSessions = 1, AutoCompleteMessages = false }); // add handler to process messages _processor.ProcessMessageAsync += MessageHandler; // add handler to process any errors _processor.ProcessErrorAsync += ErrorHandler; // start processing await _processor.StartProcessingAsync(); _resetEvent.Wait(); } static async Task MessageHandler(ProcessSessionMessageEventArgs arg) { SessionMessageEventArgs = arg; await Task.Run(() => OnMessageReceive(arg.Message.Body.ToString())); }
0
Answers
-
Hi PierreC,
I am currently developing a solution for Azure Service Bus Communication between Microsoft Dynamics BC 14 Version.
For your question, I am advised to use Await command and Async Communication so that the particular DLL Function would eventually wait for any Response from Azure Service Bus.
You can find valuable examples here, should you still need it:
<link>https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Azure.Messaging.ServiceBus/samples/Sample01_HelloWorld.md</link>
Which .NET Version are you using for communicating between NAV and ASB? Did you also use Azure.Core Nuget Package as well? Did you also received any "DLL Missing Error" in NAV for Microsoft.Bcl maybe?
Thank you for your feedback!
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions