using System; using System.Threading.Tasks; namespace Tapeti.Config { /// /// Determines the type of queue the binding registers /// public enum QueueType { /// /// The consumed queue is durable /// Durable, /// /// The consumed queue is dynamic /// Dynamic } /// /// Represents a registered binding to handle incoming messages. /// public interface IBinding { /// /// The name of the queue the binding is consuming. May change after a reconnect for dynamic queues. /// string QueueName { get; } /// /// Determines the type of queue the binding registers /// QueueType QueueType { get; } /// /// Called after a connection is established to set up the binding. /// /// Task Apply(IBindingTarget target); /// /// Determines if the message as specified by the message class can be handled by this binding. /// /// bool Accept(Type messageClass); /// /// Invokes the handler for the message as specified by the context. /// /// Task Invoke(IMessageContext context); /// /// Called after the handler is invoked and any exception handling has been done. /// /// /// /// Task Cleanup(IMessageContext context, ConsumeResult consumeResult); } /// /// Allows the binding to specify to which queue it should bind to and how. /// At most one of these methods can be called, calling a second method will result in an exception. /// public interface IBindingTarget { /// /// Binds the messageClass to the specified durable queue. /// /// The message class to be bound to the queue /// The name of the durable queue Task BindDurable(Type messageClass, string queueName); /// /// Binds the messageClass to a dynamic auto-delete queue. /// /// /// Dynamic bindings for different messageClasses will be bundled into a single dynamic queue. /// Specifying a different queuePrefix is a way to force bindings into separate queues. /// /// The message class to be bound to the queue /// An optional prefix for the dynamic queue's name. If not provided, RabbitMQ's default logic will be used to create an amq.gen queue. /// The generated name of the dynamic queue Task BindDynamic(Type messageClass, string queuePrefix = null); /// /// Declares a durable queue but does not add a binding for a messageClass' routing key. /// Used for direct-to-queue messages. /// /// The name of the durable queue Task BindDurableDirect(string queueName); /// /// Declares a dynamic queue but does not add a binding for a messageClass' routing key. /// Used for direct-to-queue messages. The messageClass is used to ensure each queue only handles unique message types. /// /// The message class which will be handled on the queue. It is not actually bound to the queue. /// An optional prefix for the dynamic queue's name. If not provided, RabbitMQ's default logic will be used to create an amq.gen queue. /// The generated name of the dynamic queue Task BindDynamicDirect(Type messageClass = null, string queuePrefix = null); /// /// Declares a dynamic queue but does not add a binding for a messageClass' routing key. /// Used for direct-to-queue messages. Guarantees a unique queue. /// /// An optional prefix for the dynamic queue's name. If not provided, RabbitMQ's default logic will be used to create an amq.gen queue. /// The generated name of the dynamic queue Task BindDynamicDirect(string queuePrefix = null); /// /// Marks the specified durable queue as having an obsolete binding. If after all bindings have subscribed, the queue only contains obsolete /// bindings and is empty, it will be removed. /// /// The name of the durable queue Task BindDurableObsolete(string queueName); } }