Skip to content

Commit

Permalink
Support setting TransportType for ServiceBusClient in Publisher and S…
Browse files Browse the repository at this point in the history
…ubscriber
  • Loading branch information
dstenroejl committed Jan 18, 2024
1 parent 7ea5670 commit 7d08ae4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ public ServiceBusSenderProvider(IOptions<PublisherOptions> options)
}

public ServiceBusSender Instance
=> _serviceBusSender ??= new ServiceBusClient(_options.Value.ServiceBusConnectionString)
=> _serviceBusSender ??= CreateServiceBusClient()
.CreateSender(_options.Value.TopicName);

private ServiceBusClient CreateServiceBusClient()
{
return new ServiceBusClient(
_options.Value.ServiceBusConnectionString,
new ServiceBusClientOptions
{
TransportType = _options.Value.TransportType,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ServiceBusProcessorFactory(IOptions<SubscriberWorkerOptions> options)

public ServiceBusProcessor CreateProcessor(string topicName, string subscriptionName)
{
_serviceBusClient ??= new ServiceBusClient(_options.Value.ServiceBusConnectionString);
_serviceBusClient ??= CreateServiceBusClient();
return _serviceBusClient.CreateProcessor(topicName, subscriptionName, new ServiceBusProcessorOptions
{
ReceiveMode = ServiceBusReceiveMode.PeekLock,
Expand All @@ -47,4 +47,14 @@ public async ValueTask DisposeAsync()
_serviceBusClient = null;
}
}

private ServiceBusClient CreateServiceBusClient()
{
return new ServiceBusClient(
_options.Value.ServiceBusConnectionString,
new ServiceBusClientOptions
{
TransportType = _options.Value.TransportType,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Azure.Messaging.ServiceBus;

namespace Energinet.DataHub.Core.Messaging.Communication.Publisher;

/// <summary>
Expand All @@ -28,4 +30,9 @@ public sealed class PublisherOptions
/// The name of the topic to send integration events to.
/// </summary>
public string TopicName { get; set; } = string.Empty;

/// <summary>
/// The type of protocol and transport that will be used for communicating with the Service Bus.
/// </summary>
public ServiceBusTransportType TransportType { get; set; } = ServiceBusTransportType.AmqpTcp;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using Azure.Messaging.ServiceBus;

namespace Energinet.DataHub.Core.Messaging.Communication.Subscriber;

/// <summary>
Expand All @@ -24,6 +26,11 @@ public sealed class SubscriberWorkerOptions
/// </summary>
public string ServiceBusConnectionString { get; set; } = string.Empty;

/// <summary>
/// The type of protocol and transport that will be used for communicating with the Service Bus.
/// </summary>
public ServiceBusTransportType TransportType { get; set; } = ServiceBusTransportType.AmqpTcp;

/// <summary>
/// The name of the topic from where to receive integration events.
/// </summary>
Expand Down

0 comments on commit 7d08ae4

Please sign in to comment.