I am using Azure Service bus to pass messages between two .Net core Web API services. I am suceesfully able to set up topic/subscription in Azure and also able to send the message to topic, using the Web API post method. I m stuck when I am trying to read the message using the subscription. I have written an API method which is trying to read the message and it should also display the message after reading it from topic. When I use .Net core Console APP I am able to read the message , but when using API, message is not displayed as API output.
Any leads as to what I am missing ? Thanks in advance.
Code is below :
public async Task Get Subscription() {
subscriptionClient = new SubscriptionClient(ServiceBusConnectionString, TopicName, SubscriptionName);
RegisterOnMessageHandlerAndReceiveMessages();
await subscriptionClient.CloseAsync();
}
public void RegisterOnMessageHandlerAndReceiveMessages() {
var messageHandlerOptions = new MessageHandlerOptions(ExceptionReceivedHandler);
subscriptionClient.RegisterMessageHandler(ProcessMessagesAsync, messageHandlerOptions);
}
private async Task ProcessMessagesAsync(Message message, CancellationToken token)
{
var messageBody = Encoding.UTF8.GetString(message.Body);
var serviceBusMessage = JsonConvert.DeserializeObject<ServiceBusMessage>(messageBody);
}