Skip to content

Commit 8d6858d

Browse files
authored
Additional constructor for SubscriptionClientWrapper allowing to use arbitrary TokenCredential for auth. (#10648)
1 parent 84aa007 commit 8d6858d

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/NuGet.Services.ServiceBus/SubscriptionClientWrapper.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
55
using System.Threading.Tasks;
6+
using Azure.Core;
67
using Azure.Messaging.ServiceBus;
78
using Microsoft.Extensions.Logging;
89

@@ -58,6 +59,22 @@ public SubscriptionClientWrapper(string connectionString, string topicPath, stri
5859
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
5960
}
6061

62+
/// <summary>
63+
/// Creates a new instance of the <see cref="SubscriptionClientWrapper"/> class using specified token credential.
64+
/// </summary>
65+
/// <param name="endpointUrl">Service bus endpoint URL (e.g. "sb://nugetdev.servicebus.windows.net/")</param>
66+
/// <param name="topicPath">Path of the topic name</param>
67+
/// <param name="name">Subscription name</param>
68+
/// <param name="tokenCredential">Credential to use.</param>
69+
/// <param name="logger"><see cref="ILogger"/> instance</param>
70+
public SubscriptionClientWrapper(Uri endpointUrl, string topicPath, string name, TokenCredential tokenCredential, ILogger<SubscriptionClientWrapper> logger)
71+
{
72+
_serviceBusClient = new ServiceBusClient(endpointUrl.Host, tokenCredential);
73+
_topicPath = topicPath ?? throw new ArgumentNullException(nameof(topicPath));
74+
_name = name ?? throw new ArgumentNullException(nameof(name));
75+
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
76+
}
77+
6178
public async Task StartProcessingAsync(Func<IReceivedBrokeredMessage, Task> onMessageAsync)
6279
{
6380
await StartProcessingAsync(onMessageAsync, new OnMessageOptionsWrapper());

0 commit comments

Comments
 (0)