-
Notifications
You must be signed in to change notification settings - Fork 592
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track publisher confirmations automatically
Fixes #1682 * Remove `ConfirmSelectAsync` from `IChannel` * Add parameters to enable confirmations on `IConnection.CreateChannelAsync` * Remove / comment out all use of `WaitForConfirms...` methods. * Dispose -> DisposeAsync * Implement confirmation tracking and await-ing in `BasicPublishAsync` * Ensure exceptions make into inner exception for `HardProtocolException` * Remove commented-out code related to `WaitForConfirms...` methods. * Unblock so that `CloseAsync` can succeed. * Introduce channel creation options * Allow cancellation of final await for publisher confirmation in `BasicPublishAsync` * Fix `dotnet format` verification error * Make `ConfirmSelectAsync` `private` and assume that semaphore is held. * Track sequence number for basic.return * Implement `basic.return` support. * Fix the code that adds OTel and publish sequence number headers. * Add publish sequence number as long as `_publisherConfirmationsEnabled` is true * Fix the `PublisherConfirms` test program * Add license headers * Enable publisher confirms * Spike an exception based approach (misses removing the bool value return type) * Extend the use of `_confirmSemaphore` to the duration of when exceptions could be caught. * Restore how @danielmarbach serialized the publish sequence number. * Fix bug in how headers are added to `BasicProperties` that don't already have them. * Use `ValueTask` as the `BasicPublishAsync` return value. --------- Co-authored-by: Daniel Marbach <danielmarbach@users.noreply.github.com> Co-authored-by: Luke Bakken <luke@bakken.io> * Add `PublishException` class. * Test that non-routable messages result in `PublishException` with `IsReturn = true` * Code documentation Simplify code.
- Loading branch information
1 parent
c82e567
commit e93adfa
Showing
52 changed files
with
892 additions
and
858 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace RabbitMQ.Client | ||
{ | ||
/// <summary> | ||
/// Channel creation options. | ||
/// </summary> | ||
public sealed class CreateChannelOptions | ||
{ | ||
/// <summary> | ||
/// Enable or disable publisher confirmations on this channel. Defaults to <c>false</c> | ||
/// </summary> | ||
public bool PublisherConfirmationsEnabled { get; set; } = false; | ||
|
||
/// <summary> | ||
/// Should this library track publisher confirmations for you? Defaults to <c>false</c> | ||
/// </summary> | ||
public bool PublisherConfirmationTrackingEnabled { get; set; } = false; | ||
|
||
/// <summary> | ||
/// Set to a value greater than one to enable concurrent processing. For a concurrency greater than one <see cref="IAsyncBasicConsumer"/> | ||
/// will be offloaded to the worker thread pool so it is important to choose the value for the concurrency wisely to avoid thread pool overloading. | ||
/// <see cref="IAsyncBasicConsumer"/> can handle concurrency much more efficiently due to the non-blocking nature of the consumer. | ||
/// | ||
/// Defaults to <c>null</c>, which will use the value from <see cref="IConnectionFactory.ConsumerDispatchConcurrency"/> | ||
/// | ||
/// For concurrency greater than one this removes the guarantee that consumers handle messages in the order they receive them. | ||
/// In addition to that consumers need to be thread/concurrency safe. | ||
/// </summary> | ||
public ushort? ConsumerDispatchConcurrency { get; set; } = null; | ||
|
||
/// <summary> | ||
/// The default channel options. | ||
/// </summary> | ||
public static CreateChannelOptions Default { get; } = new CreateChannelOptions(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// This source code is dual-licensed under the Apache License, version | ||
// 2.0, and the Mozilla Public License, version 2.0. | ||
// | ||
// The APL v2.0: | ||
// | ||
//--------------------------------------------------------------------------- | ||
// Copyright (c) 2007-2024 Broadcom. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
//--------------------------------------------------------------------------- | ||
// | ||
// The MPL v2.0: | ||
// | ||
//--------------------------------------------------------------------------- | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
// | ||
// Copyright (c) 2007-2024 Broadcom. All Rights Reserved. | ||
//--------------------------------------------------------------------------- | ||
|
||
using System; | ||
|
||
namespace RabbitMQ.Client.Exceptions | ||
{ | ||
/// <summary> | ||
/// Class for exceptions related to publisher confirmations | ||
/// or the <c>mandatory</c> flag. | ||
/// </summary> | ||
public class PublishException : RabbitMQClientException | ||
{ | ||
private bool _isReturn = false; | ||
private ulong _publishSequenceNumber = ulong.MinValue; | ||
|
||
public PublishException(ulong publishSequenceNumber, bool isReturn) : base() | ||
{ | ||
if (publishSequenceNumber == ulong.MinValue) | ||
{ | ||
throw new ArgumentException($"{nameof(publishSequenceNumber)} must not be 0"); | ||
} | ||
|
||
_isReturn = isReturn; | ||
_publishSequenceNumber = publishSequenceNumber; | ||
} | ||
|
||
/// <summary> | ||
/// <c>true</c> if this exception is due to a <c>basic.return</c> | ||
/// </summary> | ||
public bool IsReturn => _isReturn; | ||
|
||
/// <summary> | ||
/// Retrieve the publish sequence number. | ||
/// </summary> | ||
public ulong PublishSequenceNumber => _publishSequenceNumber; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.