-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publisher confirms as PublishMiddleware
- Loading branch information
1 parent
e23325a
commit e7955dd
Showing
23 changed files
with
135 additions
and
239 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
9 changes: 9 additions & 0 deletions
9
src/RabbitMQ.Next.Consumer.Abstractions/IConsumerMiddleware.cs
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,9 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace RabbitMQ.Next.Consumer; | ||
|
||
public interface IConsumerMiddleware | ||
{ | ||
ValueTask InvokeAsync(IDeliveredMessage message, CancellationToken cancellation); | ||
} |
35 changes: 0 additions & 35 deletions
35
src/RabbitMQ.Next.Publisher.Abstractions/DelegatePublishMiddleware.cs
This file was deleted.
Oops, something went wrong.
5 changes: 4 additions & 1 deletion
5
src/RabbitMQ.Next.Publisher.Abstractions/IPublishMiddleware.cs
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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using RabbitMQ.Next.Channels; | ||
|
||
namespace RabbitMQ.Next.Publisher; | ||
|
||
public interface IPublishMiddleware | ||
{ | ||
ValueTask InvokeAsync<TContent>(TContent content, IMessageBuilder message, CancellationToken cancellation); | ||
ValueTask InitAsync(IChannel channel, CancellationToken cancellation); | ||
|
||
ValueTask<ulong> InvokeAsync<TContent>(TContent content, IMessageBuilder message, CancellationToken cancellation); | ||
} |
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
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,41 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using RabbitMQ.Next.Channels; | ||
using RabbitMQ.Next.Transport.Methods.Basic; | ||
using RabbitMQ.Next.Transport.Methods.Confirm; | ||
|
||
namespace RabbitMQ.Next.Publisher; | ||
|
||
internal class ConfirmMessageMiddleware : IPublishMiddleware | ||
{ | ||
private readonly IPublishMiddleware next; | ||
private ConfirmMessageHandler confirms; | ||
|
||
public ConfirmMessageMiddleware(IPublishMiddleware next) | ||
{ | ||
this.next = next; | ||
} | ||
|
||
public ValueTask InitAsync(IChannel channel, CancellationToken cancellation) | ||
{ | ||
this.confirms = new ConfirmMessageHandler(); | ||
channel.WithMessageHandler<AckMethod>(this.confirms); | ||
channel.WithMessageHandler<NackMethod>(this.confirms); | ||
|
||
return new ValueTask(channel.SendAsync<SelectMethod, SelectOkMethod>(new SelectMethod(), cancellation)); | ||
} | ||
|
||
public async ValueTask<ulong> InvokeAsync<TContent>(TContent content, IMessageBuilder message, CancellationToken cancellation) | ||
{ | ||
var deliveryTag = await this.next.InvokeAsync(content, message, cancellation); | ||
|
||
var confirmed = await this.confirms.WaitForConfirmAsync(deliveryTag, cancellation); | ||
if (!confirmed) | ||
{ | ||
// todo: provide some useful info here | ||
throw new DeliveryFailedException(); | ||
} | ||
|
||
return deliveryTag; | ||
} | ||
} |
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.