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
|
|
|
|
/// <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 />
|
2022-11-23 09:13:38 +01:00
|
|
|
|
public string? QueueName { get; private set; }
|
2019-08-13 20:30:04 +02:00
|
|
|
|
|
2019-08-19 09:33:07 +02:00
|
|
|
|
/// <inheritdoc />
|
2022-11-23 09:13:38 +01:00
|
|
|
|
public QueueType? QueueType => Config.QueueType.Dynamic;
|
2019-08-19 09:33:07 +02:00
|
|
|
|
|
2019-08-13 20:30:04 +02:00
|
|
|
|
|
2021-05-29 21:51:58 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// </summary>
|
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 />
|
2022-02-09 12:42:05 +01:00
|
|
|
|
public async ValueTask Apply(IBindingTarget target)
|
2019-08-13 20:30:04 +02:00
|
|
|
|
{
|
2022-11-17 16:47:07 +01:00
|
|
|
|
QueueName = await target.BindDynamicDirect(dynamicQueuePrefix, null);
|
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 />
|
2022-02-09 12:42:05 +01:00
|
|
|
|
public ValueTask Invoke(IMessageContext context)
|
2019-04-24 18:04:30 +02:00
|
|
|
|
{
|
2019-08-13 20:30:04 +02:00
|
|
|
|
router.HandleMessage(context);
|
2022-02-09 12:42:05 +01:00
|
|
|
|
return default;
|
2019-04-24 18:04:30 +02:00
|
|
|
|
}
|
2019-08-14 20:48:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2022-02-09 12:42:05 +01:00
|
|
|
|
public ValueTask Cleanup(IMessageContext context, ConsumeResult consumeResult)
|
2019-08-14 20:48:40 +02:00
|
|
|
|
{
|
2022-02-09 12:42:05 +01:00
|
|
|
|
return default;
|
2019-08-14 20:48:40 +02:00
|
|
|
|
}
|
2019-04-24 18:04:30 +02:00
|
|
|
|
}
|
|
|
|
|
}
|