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