Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var message = new ServiceBusMessage

Finally, we send our message to our Service Bus queue.
```C# Snippet:ClaimCheckSendMessage
ServiceBusClient client = new("<service bus fully qualified namespace>", credential);
await using ServiceBusClient client = new("<service bus fully qualified namespace>", credential);
ServiceBusSender sender = client.CreateSender(scope.QueueName);
await sender.SendMessageAsync(message);
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ In the example shown below, the transport is configured to use web sockets and a
```C# Snippet:ServiceBusConfigureTransport
string fullyQualifiedNamespace = "<fully_qualified_namespace>";
DefaultAzureCredential credential = new();
ServiceBusClient client = new(fullyQualifiedNamespace, credential, new ServiceBusClientOptions
await using ServiceBusClient client = new(fullyQualifiedNamespace, credential, new ServiceBusClientOptions
{
TransportType = ServiceBusTransportType.AmqpWebSockets,
WebProxy = new WebProxy("https://myproxyserver:80")
Expand Down Expand Up @@ -62,7 +62,7 @@ static bool ValidateServerCertificate(
return false;
}

ServiceBusClient client = new(fullyQualifiedNamespace, credential, new ServiceBusClientOptions
await using ServiceBusClient client = new(fullyQualifiedNamespace, credential, new ServiceBusClientOptions
{
CertificateValidationCallback = ValidateServerCertificate
});
Expand All @@ -75,7 +75,7 @@ The retry options are used to configure the retry policy for all operations when
```C# Snippet:ServiceBusConfigureRetryOptions
string fullyQualifiedNamespace = "<fully_qualified_namespace>";
DefaultAzureCredential credential = new();
ServiceBusClient client = new(fullyQualifiedNamespace, credential, new ServiceBusClientOptions
await using ServiceBusClient client = new(fullyQualifiedNamespace, credential, new ServiceBusClientOptions
{
RetryOptions = new ServiceBusRetryOptions
{
Expand All @@ -93,7 +93,7 @@ The [prefetch feature](https://learn.microsoft.com/azure/service-bus-messaging/s
```C# Snippet:ServiceBusConfigurePrefetchReceiver
string fullyQualifiedNamespace = "<fully_qualified_namespace>";
DefaultAzureCredential credential = new();
ServiceBusClient client = new(fullyQualifiedNamespace, credential);
await using ServiceBusClient client = new(fullyQualifiedNamespace, credential);
ServiceBusReceiver receiver = client.CreateReceiver("<queue-name>", new ServiceBusReceiverOptions
{
PrefetchCount = 10
Expand All @@ -105,7 +105,7 @@ And when using the processor:
```C# Snippet:ServiceBusConfigurePrefetchProcessor
string fullyQualifiedNamespace = "<fully_qualified_namespace>";
DefaultAzureCredential credential = new();
ServiceBusClient client = new(fullyQualifiedNamespace, credential);
await using ServiceBusClient client = new(fullyQualifiedNamespace, credential);
ServiceBusProcessor processor = client.CreateProcessor("<queue-name>", new ServiceBusProcessorOptions
{
PrefetchCount = 10
Expand All @@ -128,7 +128,7 @@ When using the `ServiceBusProcessor`:
```C# Snippet:ServiceBusProcessorLockLostHandler
string fullyQualifiedNamespace = "<fully_qualified_namespace>";
DefaultAzureCredential credential = new();
ServiceBusClient client = new(fullyQualifiedNamespace, credential);
await using ServiceBusClient client = new(fullyQualifiedNamespace, credential);

// create a processor that we can use to process the messages
await using ServiceBusProcessor processor = client.CreateProcessor("<queue-name>");
Expand Down Expand Up @@ -189,7 +189,7 @@ Here is what the code would look like when using the `ServiceBusSessionProcessor
```C# Snippet:ServiceBusSessionProcessorLockLostHandler
string fullyQualifiedNamespace = "<fully_qualified_namespace>";
DefaultAzureCredential credential = new();
var client = new ServiceBusClient(fullyQualifiedNamespace, credential);
await using var client = new ServiceBusClient(fullyQualifiedNamespace, credential);

// create a processor that we can use to process the messages
await using ServiceBusSessionProcessor processor = client.CreateSessionProcessor("<queue-name>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ else if (amqpMessage.Body.TryGetData(out IEnumerable<ReadOnlyMemory<byte>> data)
If you needed to send a value body, you could do the following:

```C# Snippet:ServiceBusSendValueBody
var client = new ServiceBusClient(fullyQualifiedNamespace, credential);
await using var client = new ServiceBusClient(fullyQualifiedNamespace, credential);
ServiceBusSender sender = client.CreateSender(queueName);

var message = new ServiceBusMessage();
Expand All @@ -43,7 +43,7 @@ await sender.SendMessageAsync(message);
You can also set various properties on the AMQP message that are not exposed on the `ServiceBusMessage` type. These values are not granted special meaning by the Service Bus broker and therefore do not impact the Service Bus service behavior. However, since these are standard AMQP properties, they could impact the behavior of other message brokers that may receive these messages.

```C# Snippet:ServiceBusSetMiscellaneousProperties
var client = new ServiceBusClient(fullyQualifiedNamespace, credential);
await using var client = new ServiceBusClient(fullyQualifiedNamespace, credential);
ServiceBusSender sender = client.CreateSender(queueName);

var message = new ServiceBusMessage("message with AMQP properties set");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ actually part of the AMQP message so it needs to stored separately from the AMQP

```C# Snippet:ServiceBusWriteReceivedMessage
var credential = new DefaultAzureCredential();
ServiceBusClient client1 = new(fullyQualifiedNamespace, credential);
await using ServiceBusClient client1 = new(fullyQualifiedNamespace, credential);
ServiceBusSender sender = client1.CreateSender(queueName);

ServiceBusMessage message = new("some message");
Expand All @@ -32,7 +32,7 @@ In order to rehydrate the message in another process, we would do the following:
AmqpAnnotatedMessage amqpMessage = AmqpAnnotatedMessage.FromBytes(new BinaryData(amqpMessageBytes));
ServiceBusReceivedMessage rehydratedMessage = ServiceBusReceivedMessage.FromAmqpMessage(amqpMessage, new BinaryData(lockTokenBytes));

var client2 = new ServiceBusClient(fullyQualifiedNamespace, credential);
await using var client2 = new ServiceBusClient(fullyQualifiedNamespace, credential);
ServiceBusReceiver receiver2 = client2.CreateReceiver(queueName);
await receiver2.CompleteMessageAsync(rehydratedMessage);
```
Expand All @@ -44,7 +44,7 @@ lock token. In the example below, we store off the lock token using its GUID byt
string if that is easier for your scenario.

```C# Snippet:ServiceBusWriteReceivedMessageLockToken
ServiceBusClient client1 = new(fullyQualifiedNamespace, credential);
await using ServiceBusClient client1 = new(fullyQualifiedNamespace, credential);
ServiceBusSender sender = client1.CreateSender(queueName);

ServiceBusMessage message = new("some message");
Expand All @@ -62,7 +62,7 @@ In order to rehydrate the message in another process using the lock token, we wo
```C# Snippet:ServiceBusReadReceivedMessageLockToken
ServiceBusReceivedMessage rehydratedMessage = ServiceBusModelFactory.ServiceBusReceivedMessage(lockTokenGuid: new Guid(lockTokenBytes.ToArray()));

ServiceBusClient client2 = new(fullyQualifiedNamespace, credential);
await using ServiceBusClient client2 = new(fullyQualifiedNamespace, credential);
ServiceBusReceiver receiver2 = client2.CreateReceiver(queueName);
await receiver2.CompleteMessageAsync(rehydratedMessage);
```
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public async Task GetChildClientFromClosedParentClientThrows(bool useSessions)
{
await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: true, enableSession: useSessions))
{
var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
await using var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
var sender = client.CreateSender(scope.QueueName);

var message = ServiceBusTestUtilities.GetMessage(useSessions ? "sessionId" : null);
Expand Down Expand Up @@ -272,7 +272,7 @@ public async Task GetChildClientFromParentSucceedsOnOpenConnection(bool useSessi
{
await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: true, enableSession: useSessions))
{
var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
await using var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
var sender = client.CreateSender(scope.QueueName);

var message = ServiceBusTestUtilities.GetMessage(useSessions ? "sessionId" : null);
Expand Down Expand Up @@ -311,7 +311,7 @@ public async Task AcceptNextSessionRespectsCancellation()
{
await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: true))
{
var client = CreateClient(60);
await using var client = CreateClient(60);
var duration = TimeSpan.FromSeconds(5);
using var cancellationTokenSource = new CancellationTokenSource(duration);

Expand All @@ -335,7 +335,7 @@ public async Task CanAcceptBlankSession()
{
await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: true))
{
var client = CreateClient();
await using var client = CreateClient();
var receiver = await client.AcceptSessionAsync(scope.QueueName, "");
Assert.AreEqual("", receiver.SessionId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task SenderReceiverActivitiesDisabled(bool useSessions)

await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: useSessions))
{
var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
await using var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
ServiceBusSender sender = client.CreateSender(scope.QueueName);
string sessionId = null;
if (useSessions)
Expand Down Expand Up @@ -96,7 +96,7 @@ public async Task SenderReceiverActivities(bool useSessions)

await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: useSessions))
{
var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
await using var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
ServiceBusSender sender = client.CreateSender(scope.QueueName);
string sessionId = null;
if (useSessions)
Expand Down Expand Up @@ -356,7 +356,7 @@ public async Task SessionProcessorActivities()
});
await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: true))
{
var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
await using var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
ServiceBusSender sender = client.CreateSender(scope.QueueName);
await sender.SendMessagesAsync(messages);
AssertSendActivities(sender, messages, listener);
Expand Down Expand Up @@ -399,7 +399,7 @@ public async Task RuleManagerActivities()

await using (var scope = await ServiceBusScope.CreateWithTopic(enablePartitioning: false, enableSession: false))
{
var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
await using var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
ServiceBusRuleManager ruleManager = client.CreateRuleManager(scope.TopicName, scope.SubscriptionNames.First());
for (int i = 0; i < 100; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task SenderReceiverActivities(bool useSessions)
{
await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: useSessions))
{
var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
await using var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
ServiceBusSender sender = client.CreateSender(scope.QueueName);
string sessionId = null;
if (useSessions)
Expand Down Expand Up @@ -209,7 +209,7 @@ public async Task ProcessorActivities()
});
await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: false))
{
var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
await using var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
ServiceBusSender sender = client.CreateSender(scope.QueueName);
var messageCt = 2;
var msgs = ServiceBusTestUtilities.GetMessages(messageCt);
Expand Down Expand Up @@ -268,7 +268,7 @@ public async Task SessionProcessorActivities()
});
await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: true))
{
var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
await using var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
ServiceBusSender sender = client.CreateSender(scope.QueueName);
var messageCt = 2;
var msgs = ServiceBusTestUtilities.GetMessages(messageCt, "sessionId");
Expand Down Expand Up @@ -312,7 +312,7 @@ public async Task RuleManagerActivities()
{
await using (var scope = await ServiceBusScope.CreateWithTopic(enablePartitioning: false, enableSession: false))
{
var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
await using var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
ServiceBusRuleManager ruleManager = client.CreateRuleManager(scope.TopicName, scope.SubscriptionNames.First());
for (int i = 0; i < 100; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public async Task LogsTransactionEvents()
{
await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: false))
{
var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
await using var client = new ServiceBusClient(TestEnvironment.FullyQualifiedNamespace, TestEnvironment.Credential);
ServiceBusSender sender = client.CreateSender(scope.QueueName);

ServiceBusMessage message = ServiceBusTestUtilities.GetMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ Task ProcessMessage(ProcessMessageEventArgs args)
}
await tcs.Task;

var receiver = CreateNoRetryClient().CreateReceiver(scope.QueueName);
await using var noRetryClient = CreateNoRetryClient();
await using var receiver = noRetryClient.CreateReceiver(scope.QueueName);
var receivedMessages = await receiver.ReceiveMessagesAsync(numMessages);
// can't assert on the exact amount processed due to threads that
// are already in flight when calling StopProcessingAsync, but we can at least verify that there are remaining messages
Expand Down
Loading