Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new <see cref="HandlingRule"/> with the supplied message
 /// <paramref name="specification"/>, <see cref="MessageHandler"/>, and
 /// <paramref name="queueName"/>.
 /// </summary>
 /// <param name="specification">The message specification that selects messages
 /// to which the handling rule applies</param>
 /// <param name="messageHandler">The handler to which messages matching the
 /// specification will be routed</param>
 /// <param name="queueName">(Optional) The name of the queue in which matching
 /// messages will be placed while they await handling</param>
 /// <param name="queueOptions">(Optional) Options for how queued messages for the handler
 /// should be processed</param>
 /// <remarks>
 /// If the <paramref name="queueName"/> is ommitted, a default queue name will
 /// be generated based on the MD5 hash of the full type name of the supplied
 /// <paramref name="messageHandler"/>
 /// </remarks>
 /// <seealso cref="GenerateQueueName"/>
 public HandlingRule(IMessageSpecification specification, IMessageHandler messageHandler, QueueName queueName = null, QueueOptions queueOptions = null)
 {
     Specification  = specification ?? throw new ArgumentNullException(nameof(specification));
     MessageHandler = messageHandler ?? throw new ArgumentNullException(nameof(messageHandler));
     QueueName      = queueName ?? GenerateQueueName(messageHandler);
     QueueOptions   = queueOptions;
 }
        /// <summary>
        /// Adds a handling rule based on the supplied message specification and
        /// action delegate
        /// </summary>
        /// <typeparam name="TContent">The type of deserialized message
        /// content expected</typeparam>
        /// <param name="configuration">The configuration object to which the
        /// handling rule is being added</param>
        /// <param name="specification">The message specification used to match
        /// messages for the handler</param>
        /// <param name="handleContent">An action delegate that will be used to
        /// handle messages</param>
        /// <param name="queueName">(Optional) The name of the queue to which
        /// the handler will be attached</param>
        /// <param name="queueOptions">(Optional) Options for how queued messages for the handler
        /// should be processed</param>
        public static void AddHandlingRule <TContent>(this PlatibusConfiguration configuration,
                                                      IMessageSpecification specification, Action <TContent, IMessageContext> handleContent,
                                                      QueueName queueName = null, QueueOptions queueOptions = null)
        {
            var messageHandler = DelegateMessageHandler.For(handleContent);
            var handlingRule   = new HandlingRule(specification, messageHandler, queueName, queueOptions);

            configuration.AddHandlingRule(handlingRule);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new <see cref="HandlingRule"/> with the supplied message
 /// <paramref name="specification"/>, <see cref="MessageHandler"/>, and
 /// <paramref name="queueName"/>.
 /// </summary>
 /// <param name="specification">The message specification that selects messages 
 /// to which the handling rule applies</param>
 /// <param name="messageHandler">The handler to which messages matching the
 /// specification will be routed</param>
 /// <param name="queueName">(Optional) The name of the queue in which matching
 /// messages will be placed while they await handling</param>
 /// <remarks>
 /// If the <paramref name="queueName"/> is ommitted, a default queue name will
 /// be generated based on the MD5 hash of the full type name of the supplied
 /// <paramref name="messageHandler"/>
 /// </remarks>
 /// <seealso cref="GenerateQueueName"/>
 public HandlingRule(IMessageSpecification specification, IMessageHandler messageHandler,
     QueueName queueName = null)
 {
     if (specification == null) throw new ArgumentNullException("specification");
     if (messageHandler == null) throw new ArgumentNullException("messageHandler");
     _specification = specification;
     _messageHandler = messageHandler;
     _queueName = queueName ?? GenerateQueueName(messageHandler);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new <see cref="SendRule"/> with the provided
        /// <paramref name="specification"/> and <paramref name="endpoints"/>
        /// </summary>
        /// <param name="specification">The message specification used to
        /// determine whether this rule applies to a particular message</param>
        /// <param name="endpoints">The endpoints to which messages matching
        /// the specification will be sent</param>
        /// <exception cref="ArgumentNullException">If either argument is <c>null</c></exception>
        /// <exception cref="EndpointRequiredException">If <paramref name="endpoints"/>
        /// is empty or contains only <c>null</c> elements</exception>
        public SendRule(IMessageSpecification specification, IEnumerable<EndpointName> endpoints)
        {
            if (specification == null) throw new ArgumentNullException("specification");
            if (endpoints == null) throw new ArgumentNullException("endpoints");

            var endpointList = endpoints as IList<EndpointName> ?? endpoints.ToList();
            if (endpointList.All(x => x == null)) throw new EndpointRequiredException();

            _specification = specification;
            _endpoints = endpointList.Where(x => x != null).ToList();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new <see cref="SendRule"/> with the provided
        /// <paramref name="specification"/> and <paramref name="endpoints"/>
        /// </summary>
        /// <param name="specification">The message specification used to
        /// determine whether this rule applies to a particular message</param>
        /// <param name="endpoints">The endpoints to which messages matching
        /// the specification will be sent</param>
        /// <exception cref="ArgumentNullException">If either argument is <c>null</c></exception>
        /// <exception cref="EndpointRequiredException">If <paramref name="endpoints"/>
        /// is empty or contains only <c>null</c> elements</exception>
        public SendRule(IMessageSpecification specification, IEnumerable <EndpointName> endpoints)
        {
            if (endpoints == null)
            {
                throw new ArgumentNullException(nameof(endpoints));
            }

            var endpointList = endpoints as IList <EndpointName> ?? endpoints.ToList();

            if (endpointList.All(x => x == null))
            {
                throw new EndpointRequiredException();
            }

            Specification = specification ?? throw new ArgumentNullException(nameof(specification));
            Endpoints     = endpointList.Where(x => x != null).ToList();
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new <see cref="SendRule"/> with the provided
 /// <paramref name="specification"/> and <paramref name="endpoints"/>
 /// </summary>
 /// <param name="specification">The message specification used to
 /// determine whether this rule applies to a particular message</param>
 /// <param name="endpoints">The endpoints to which messages matching
 /// the specification will be sent</param>
 /// <exception cref="ArgumentNullException">If either argument is <c>null</c></exception>
 /// <exception cref="EndpointRequiredException">If <paramref name="endpoints"/>
 /// is empty or contains only <c>null</c> elements</exception>
 public SendRule(IMessageSpecification specification, params EndpointName[] endpoints)
     : this(specification, (IEnumerable <EndpointName>)endpoints)
 {
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new <see cref="SendRule"/> with the provided
 /// <paramref name="specification"/> and <paramref name="endpoints"/>
 /// </summary>
 /// <param name="specification">The message specification used to
 /// determine whether this rule applies to a particular message</param>
 /// <param name="endpoints">The endpoints to which messages matching
 /// the specification will be sent</param>
 /// <exception cref="ArgumentNullException">If either argument is <c>null</c></exception>
 /// <exception cref="EndpointRequiredException">If <paramref name="endpoints"/>
 /// is empty or contains only <c>null</c> elements</exception>
 public SendRule(IMessageSpecification specification, params EndpointName[] endpoints)
     : this(specification, (IEnumerable<EndpointName>) endpoints)
 {
 }