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