I created a service bus for a learning purpose, and I want to pass messages to it. I went through the official Microsoft documentation which teaches to use the DefaultAzureCredential
so that the stored credentials in Visual Studio are gonna get used.
The problem is, I have logged in to Visual studio from my work email, which I use daily. And the new service bus is in a different subscription, and it's attached to my personal email.
So, is there a way to get the service bus to work, without logging in with my personal email, and CLI configurations? Any alternatives for this DefaultAzureCredential
object?
Sample code (From Microsoft documentation)
ServiceBusClient client;
const int numOfMessages = 3;
var clientOptions = new ServiceBusClientOptions
{
TransportType = ServiceBusTransportType.AmqpWebSockets
};
client = new ServiceBusClient("asb-test.servicebus.windows.net",
new DefaultAzureCredential(),
clientOptions);
sender = client.CreateSender("email");
using ServiceBusMessageBatch messageBatch = await
sender.CreateMessageBatchAsync();
var result = messageBatch.TryAddMessage(new ServiceBusMessage($"Message"));
if (!result)
{
throw new Exception($"The message is too large to fit in the batch.");
}
try
{
await sender.SendMessagesAsync(messageBatch);
Console.WriteLine($"A batch of {numOfMessages} messages has been published to the queue.");
}
finally
{
await sender.DisposeAsync();
await client.DisposeAsync();
}