1
0
mirror of synced 2024-11-22 01:13:49 +00:00
Tapeti/Tapeti.Transient/TransientGenericBinding.cs
Mark van Renswoude 3aee6f1c53 Fixed #38 Durable queues are verified more than once
Caused by non thread-safe code when applying bindings. Replaced Task.WhenAll with a simple loop, as the performance benefits are negligable and it's only at startup anyways.
Also changed binding methods to use ValueTask.
2022-02-09 12:42:05 +01:00

62 lines
1.6 KiB
C#

using System;
using System.Threading.Tasks;
using Tapeti.Config;
namespace Tapeti.Transient
{
/// <inheritdoc />
/// <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 => 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);
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;
}
}
}