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