Skip to content

Commit

Permalink
Fix the ability to connect using an EntityPath connection string (#693)
Browse files Browse the repository at this point in the history
* Updated nugets

* Preserve complete connection string

* Bypass SKU check if the connection string contains an EntityPath
  • Loading branch information
ErikMogensen committed Oct 19, 2022
1 parent 75dde48 commit 7d60855
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 30 deletions.
42 changes: 16 additions & 26 deletions src/Common/Helpers/ServiceBusHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,19 @@ public string ServicePath
}
}

public string ConnectionStringWithoutEntityPath
{
get
{
var builder = new ServiceBusConnectionStringBuilder(connectionString)
{
EntityPath = string.Empty
};

return builder.ToString();
}
}

/// <summary>
/// Gets or sets the connection string.
/// </summary>
Expand Down Expand Up @@ -677,7 +690,7 @@ public MessagingFactory CreateMessagingFactory()
MessagingFactory factory;
if (!string.IsNullOrEmpty(ConnectionString))
{
factory = MessagingFactory.CreateFromConnectionString(ConnectionString);
factory = MessagingFactory.CreateFromConnectionString(ConnectionStringWithoutEntityPath);
}
else
{
Expand Down Expand Up @@ -732,18 +745,7 @@ public bool Connect(ServiceBusNamespace serviceBusNamespace)
// such as queues, topics, subscriptions, and rules, in your service namespace.
// You must provide service namespace address and access credentials in order
// to manage your service namespace.
if (serviceBusNamespace.EntityPath != string.Empty)
{
var csBuilder = new ServiceBusConnectionStringBuilder(connectionString)
{
EntityPath = string.Empty
};
namespaceManager = Microsoft.ServiceBus.NamespaceManager.CreateFromConnectionString(connectionString = csBuilder.ToString());
}
else
{
namespaceManager = Microsoft.ServiceBus.NamespaceManager.CreateFromConnectionString(connectionString);
}
namespaceManager = Microsoft.ServiceBus.NamespaceManager.CreateFromConnectionString(ConnectionStringWithoutEntityPath);
// Set retry count
if (namespaceManager.Settings.RetryPolicy is Microsoft.ServiceBus.RetryExponential defaultServiceBusRetryExponential)
Expand Down Expand Up @@ -779,7 +781,7 @@ public bool Connect(ServiceBusNamespace serviceBusNamespace)
// As the name suggests, the MessagingFactory class is a Factory class that allows to create
// instances of the QueueClient, TopicClient and SubscriptionClient classes.
MessagingFactory = MessagingFactory.CreateFromConnectionString(connectionString);
MessagingFactory = MessagingFactory.CreateFromConnectionString(ConnectionStringWithoutEntityPath);
WriteToLogIf(traceEnabled, MessageFactorySuccessfullyCreated);
return true;
});
Expand Down Expand Up @@ -5308,18 +5310,6 @@ public void ReceiveMessages(EntityDescription entityDescription, int? messageCou
}
}

public string GetHostWithoutNamespace()
{
if (namespaceUri == null ||
string.IsNullOrWhiteSpace(namespaceUri.Host))
{
return null;
}
var host = namespaceUri.Host;
var index = host.IndexOf('.');
return host.Substring(index);
}

public string GetAddressRelativeToNamespace(string address)
{
if (Uri.IsWellFormedUriString(address, UriKind.Absolute))
Expand Down
2 changes: 1 addition & 1 deletion src/EventHubs/EventHubs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


<ItemGroup>
<PackageReference Include="Azure.Messaging.EventHubs" Version="5.7.0" />
<PackageReference Include="Azure.Messaging.EventHubs" Version="5.7.3" />
</ItemGroup>


Expand Down
12 changes: 12 additions & 0 deletions src/ServiceBus/Helpers/ServiceBusHelper2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ public class ServiceBusHelper2
public string ConnectionString { get; set; }
public ServiceBusTransportType TransportType { get; set; }

public bool ConnectionStringContainsEntityPath()
{
var connectionStringProperties = ServiceBusConnectionStringProperties.Parse(ConnectionString);

if (connectionStringProperties?.EntityPath != null)
{
return true;
}

return false;
}

public async Task<bool> IsPremiumNamespace()
{
var administrationClient = new ServiceBusAdministrationClient(ConnectionString);
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceBus/ServiceBus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


<ItemGroup>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.8.1" />
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.11.0" />
</ItemGroup>


Expand Down
7 changes: 6 additions & 1 deletion src/ServiceBusExplorer/Controls/HandleQueueControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,12 @@ public HandleQueueControl(WriteToLogDelegate writeToLog, ServiceBusHelper servic
this.serviceBusHelper2 = serviceBusHelper.GetServiceBusHelper2();
this.path = path;
this.queueDescription = queueDescription;
this.premiumNamespace = serviceBusHelper2.IsPremiumNamespace().GetAwaiter().GetResult();

if (!serviceBusHelper2.ConnectionStringContainsEntityPath())
{
this.premiumNamespace = serviceBusHelper2.IsPremiumNamespace().GetAwaiter().GetResult();
}

this.duplicateQueue = duplicateQueue;

InitializeComponent();
Expand Down
7 changes: 6 additions & 1 deletion src/ServiceBusExplorer/Controls/HandleTopicControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ public HandleTopicControl(WriteToLogDelegate writeToLog, ServiceBusHelper servic
this.writeToLog = writeToLog;
this.serviceBusHelper = serviceBusHelper;
this.serviceBusHelper2 = serviceBusHelper.GetServiceBusHelper2();
this.premiumNamespace = serviceBusHelper2.IsPremiumNamespace().GetAwaiter().GetResult();

if (!serviceBusHelper2.ConnectionStringContainsEntityPath())
{
this.premiumNamespace = serviceBusHelper2.IsPremiumNamespace().GetAwaiter().GetResult();
}

this.topicDescription = topicDescription;
this.path = path;

Expand Down

0 comments on commit 7d60855

Please sign in to comment.