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 => QueueType.Dynamic;
///
public TransientGenericBinding(TransientRouter router, string dynamicQueuePrefix)
{
this.router = router;
this.dynamicQueuePrefix = dynamicQueuePrefix;
}
///
public async Task Apply(IBindingTarget target)
{
QueueName = await target.BindDynamicDirect(dynamicQueuePrefix);
router.TransientResponseQueueName = QueueName;
}
///
public bool Accept(Type messageClass)
{
return true;
}
///
public Task Invoke(IMessageContext context)
{
router.HandleMessage(context);
return Task.CompletedTask;
}
///
public Task Cleanup(IMessageContext context, ConsumeResult consumeResult)
{
return Task.CompletedTask;
}
}
}