1
0
mirror of synced 2024-11-14 06:29:17 +00:00
Tapeti/Tapeti.Transient/TransientGenericBinding.cs
Mark van Renswoude a0c9d97694 Added ConfigureAwait to (hopefully) all awaits
Ugly as heck, but it's recommended for libraries
2024-04-08 14:20:15 +02:00

61 lines
1.6 KiB
C#

using System;
using System.Threading.Tasks;
using Tapeti.Config;
namespace Tapeti.Transient
{
/// <summary>
/// Implements a binding for transient request response messages.
/// Register this binding using the WithTransient config extension method.
/// </summary>
internal class TransientGenericBinding : IBinding
{
private readonly TransientRouter router;
private readonly string dynamicQueuePrefix;
/// <inheritdoc />
public string? QueueName { get; private set; }
/// <inheritdoc />
public QueueType? QueueType => Config.QueueType.Dynamic;
/// <summary>
/// </summary>
public TransientGenericBinding(TransientRouter router, string dynamicQueuePrefix)
{
this.router = router;
this.dynamicQueuePrefix = dynamicQueuePrefix;
}
/// <inheritdoc />
public async ValueTask Apply(IBindingTarget target)
{
QueueName = await target.BindDynamicDirect(dynamicQueuePrefix, null).ConfigureAwait(false);
router.TransientResponseQueueName = QueueName;
}
/// <inheritdoc />
public bool Accept(Type messageClass)
{
return true;
}
/// <inheritdoc />
public ValueTask Invoke(IMessageContext context)
{
router.HandleMessage(context);
return default;
}
/// <inheritdoc />
public ValueTask Cleanup(IMessageContext context, ConsumeResult consumeResult)
{
return default;
}
}
}