1
0
mirror of synced 2024-12-22 09:13:07 +01:00

Fixed #15: Attribute for mandatory messages

This commit is contained in:
Mark van Renswoude 2019-03-19 11:47:52 +01:00
parent 5b3be481e1
commit ed421361ac
6 changed files with 45 additions and 7 deletions

View File

@ -2,6 +2,7 @@
namespace Tapeti.Annotations
{
/// <inheritdoc />
/// <summary>
/// Binds to an existing durable queue to receive messages. Can be used
/// on an entire MessageController class or on individual methods.
@ -17,6 +18,8 @@ namespace Tapeti.Annotations
public string Name { get; set; }
/// <inheritdoc />
/// <param name="name">The name of the durable queue</param>
public DurableQueueAttribute(string name)
{
Name = name;

View File

@ -2,6 +2,7 @@
namespace Tapeti.Annotations
{
/// <inheritdoc />
/// <summary>
/// Creates a non-durable auto-delete queue to receive messages. Can be used
/// on an entire MessageController class or on individual methods.
@ -12,12 +13,10 @@ namespace Tapeti.Annotations
public string Prefix { get; set; }
/// <summary>
/// If prefix is specified, Tapeti will compose the queue name using the
/// prefix and a unique ID. If not specified, an empty queue name will be passed
/// to RabbitMQ thus letting it create a unique queue name.
/// </summary>
/// <param name="prefix"></param>
/// <inheritdoc />
/// <param name="prefix">An optional prefix. If specified, Tapeti will compose the queue name using the
/// prefix and a unique ID. If not specified, an empty queue name will be passed
/// to RabbitMQ thus letting it create a unique queue name.</param>
public DynamicQueueAttribute(string prefix = null)
{
Prefix = prefix;

View File

@ -0,0 +1,15 @@
using System;
namespace Tapeti.Annotations
{
/// <inheritdoc />
/// <summary>
/// Can be attached to a message class to specify that delivery to a queue must be guaranteed.
/// Publish will fail if no queues bind to the routing key. Publisher confirms must be enabled
/// on the connection for this to work (enabled by default).
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class MandatoryAttribute : Attribute
{
}
}

View File

@ -2,6 +2,11 @@
namespace Tapeti.Annotations
{
/// <inheritdoc />
/// <summary>
/// Attaching this attribute to a class includes it in the auto-discovery of message controllers
/// when using the RegisterAllControllers method. It is not required when manually registering a controller.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class MessageControllerAttribute : Attribute
{

View File

@ -2,6 +2,14 @@
namespace Tapeti.Annotations
{
/// <inheritdoc />
/// <summary>
/// Can be attached to a message class to specify that the receiver of the message must
/// provide a response message of the type specified in the Response attribute. This response
/// must be sent by either returning it from the message handler method or using
/// YieldWithResponse when using Tapeti Flow. These methods will respond directly
/// to the queue specified in the reply-to header automatically added by Tapeti.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class RequestAttribute : Attribute
{

View File

@ -1,6 +1,8 @@
using System;
using System.Reflection;
using System.Threading.Tasks;
using RabbitMQ.Client;
using Tapeti.Annotations;
namespace Tapeti.Connection
{
@ -17,7 +19,7 @@ namespace Tapeti.Connection
public Task Publish(object message)
{
return workerFactory().Publish(message, null, false);
return workerFactory().Publish(message, null, IsMandatory(message));
}
@ -31,5 +33,11 @@ namespace Tapeti.Connection
{
return workerFactory().PublishDirect(message, queueName, properties, mandatory);
}
private static bool IsMandatory(object message)
{
return message.GetType().GetCustomAttribute<MandatoryAttribute>() != null;
}
}
}