0

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();
}
Ayesh Nipun
  • 568
  • 12
  • 28
  • Look at the overloads for the ServiceBusClient constructor. There are other options. – Skin Dec 21 '22 at 12:03

1 Answers1

0

If the subscriptions are in the same tenant, this is not a problem, you can still easily assign permissions. But I guess what you mean to say is that the subs are in two different tenants.

You could try to add your work account as a guest user in your personal tenant, then you should also be able to assign it permissions.

silent
  • 14,494
  • 4
  • 46
  • 86