OnRun() EventimWrapper.Start(); EventimWrapper::MessageReceive(msg : Text) MESSAGE(msg);
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())); }
Answers
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!