2019-04-24 16:04:30 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Tapeti.Config;
|
|
|
|
|
|
|
|
|
|
namespace Tapeti.Transient
|
|
|
|
|
{
|
2019-08-13 18:30:04 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Implements a binding for transient request response messages.
|
|
|
|
|
/// Register this binding using the WithTransient config extension method.
|
|
|
|
|
/// </summary>
|
2019-08-15 09:26:55 +00:00
|
|
|
|
internal class TransientGenericBinding : IBinding
|
2019-04-24 16:04:30 +00:00
|
|
|
|
{
|
|
|
|
|
private readonly TransientRouter router;
|
2019-08-13 18:30:04 +00:00
|
|
|
|
private readonly string dynamicQueuePrefix;
|
2019-04-24 16:04:30 +00:00
|
|
|
|
|
2019-08-13 18:30:04 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public string QueueName { get; private set; }
|
|
|
|
|
|
2019-08-19 07:33:07 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public QueueType QueueType => QueueType.Dynamic;
|
|
|
|
|
|
2019-08-13 18:30:04 +00:00
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2019-04-24 16:04:30 +00:00
|
|
|
|
public TransientGenericBinding(TransientRouter router, string dynamicQueuePrefix)
|
|
|
|
|
{
|
|
|
|
|
this.router = router;
|
2019-08-13 18:30:04 +00:00
|
|
|
|
this.dynamicQueuePrefix = dynamicQueuePrefix;
|
2019-04-24 16:04:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-08-13 18:30:04 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public async Task Apply(IBindingTarget target)
|
|
|
|
|
{
|
2019-08-14 18:48:40 +00:00
|
|
|
|
QueueName = await target.BindDynamicDirect(dynamicQueuePrefix);
|
2019-08-13 18:30:04 +00:00
|
|
|
|
router.TransientResponseQueueName = QueueName;
|
|
|
|
|
}
|
2019-04-24 16:04:30 +00:00
|
|
|
|
|
|
|
|
|
|
2019-08-13 18:30:04 +00:00
|
|
|
|
/// <inheritdoc />
|
2019-04-24 16:04:30 +00:00
|
|
|
|
public bool Accept(Type messageClass)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-08-13 18:30:04 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public Task Invoke(IMessageContext context)
|
2019-04-24 16:04:30 +00:00
|
|
|
|
{
|
2019-08-13 18:30:04 +00:00
|
|
|
|
router.HandleMessage(context);
|
2019-04-24 16:04:30 +00:00
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
2019-08-14 18:48:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public Task Cleanup(IMessageContext context, ConsumeResult consumeResult)
|
|
|
|
|
{
|
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
2019-04-24 16:04:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|