Is there a way, using the Microsoft.Azure.ServiceBus
package, to wait on your current thread to receive a message from a queue?
This may more be a problem with my understanding and a desire to use the technology in a way it is not intended to be used, but what I would like to do is combine the send and receive examples from the following Microsoft example so that you can send message(s) off to various queues, and be able to listen in and handle "replies" (just messages that you're listening to on a queue) and close the connection when you are done receiving messages.
Some pseudo-code here:
// send message(s) that will be consumed by other processes / applications, and by doing so later on we will expect some messages back
await SendMessagesAsync(numberOfMessages);
var receivedMessages = 0;
while (receivedMessages < numberOfMessages)
{
// there is no "ReceiveAsync" method, this is what I would be looking for
Message message = await queueClient.ReceiveAsync(TimeSpan.FromSeconds(30));
receivedMessages++;
// do something with the message here
}
await queueClient.CloseAsync();
Is this possible or am I "doing it wrong"?
In the new library
ReceiveAsync
method is available onMessageReceiver
class:See a full example at Get started sending and receiving messages from Service Bus queues using MessageSender and MessageReceiver.
In
Microsoft.Azure.ServiceBus
library, there is no such a thing calledReceiveAsync
. In this, you can process or receive the message by usingRegisterOnMessageHandlerAndReceiveMessages()
. With this you can receive the message with an event. With thisRegisterOnMessageHandlerAndReceiveMessages()
likequeueClient.RegisterMessageHandler(ReceiveOrProcessMessagesAsync, messageHandlerOptions);
and you have to seprately create this event for receiveMessages, in our case it isReceiveOrProcessMessagesAsync
and you refer the below link for know about
Microsoft.Azure.ServiceBus
https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-get-started-with-queues