Microsoft has deprecated the package named Microsoft.Azure.ServiceBus and updated the package as Azure.Messaging.ServiceBus but in the recent update they have removed the QueueClient class. So what is the alternative for this QueueClient class.
public IQueueClient GetQueueClient(string queueName)
{
return new QueueClient(ConnectionString.Trim('"'), queueName);
}
In the new version you do the same thing with two classes ServiceBusClient andserviceBusSender. After you install Azure.Messaging.ServiceBus you need to update QueueClient with its alternative as below:
public ServiceBusSender PutintoQueueClient(string queueName)
{
var serviceBusClient = new ServiceBusClient(ConnectionString.Trim('"'));
return serviceBusClient.CreateSender(queueName)
}
Now you can send your messages into Queue like
var serviceBusSender = PutintoQueueClient(queueName);
await serviceBusSender.SendMessageAsync(message).ConfigureAwait(false);
For receiving Messages it will be like
public ServiceBusReceiver GetQueueClient(string queueName)
{
var serviceBusClient = new ServiceBusClient(ConnectionString.Trim('"'));
return serviceBusClient.CreateReceiver(queueName)
}
Now you can send your messages into Queue like
var serviceBusSender = GetQueueClient(queueName);
ServiceBusReceivedMessage receivedMessage = await
serviceBusSender.ReceiveMessageAsync().ConfigureAwait(false);
Reference: Guide for migrating to Azure.Messaging.ServiceBus from Microsoft.Azure.ServiceBus
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With