Exemplo n.º 1
0
        /// <summary>
        /// Build a subscription using common options
        /// </summary>
        /// <typeparam name="TPayload">The type of object to listen for</typeparam>
        /// <param name="messageBus">The message bus</param>
        /// <param name="build">Lambda function to setup the subscription builder.</param>
        /// <returns>The subscription token which, when disposed, cancels the subscription.</returns>
        public static IDisposable Subscribe <TPayload>(this IPubSubBus messageBus, Action <ITopicSubscriptionBuilder <TPayload> > build)
        {
            Assert.ArgumentNotNull(messageBus, nameof(messageBus));
            Assert.ArgumentNotNull(build, nameof(build));

            var builder = new SubscriptionBuilder <TPayload>(messageBus, messageBus.WorkerPool);

            build(builder);
            var subscription = builder.BuildSubscription();

            var token = messageBus.Subscribe(builder.Topics, subscription);

            return(builder.WrapToken(token));
        }