コード例 #1
0
        public IDisposable SubscribeAsync
        (
            [NotNull] Type type,
            [NotNull] string subscriptionId,
            [NotNull] Func <object, Task> onMessage,
            [NotNull] Action <IAdvancedSubscriptionConfiguration> configure
        )
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (subscriptionId == null)
            {
                throw new ArgumentNullException("subscriptionId");
            }
            if (onMessage == null)
            {
                throw new ArgumentNullException("onMessage");
            }
            if (configure == null)
            {
                throw new ArgumentNullException("configure");
            }

            var configuration = new AdvancedSubscriptionConfiguration();

            configure(configuration);

            var queueName    = conventions.QueueNamingConvention(type, subscriptionId);
            var exchangeName = conventions.ExchangeNamingConvention(type);

            var queue    = advancedBus.QueueDeclare(queueName, durable: configuration.Durable, autoDelete: configuration.AutoDelete);
            var exchange = advancedBus.ExchangeDeclare(exchangeName, ExchangeType.Topic);

            foreach (var topic in configuration.Topics.AtLeastOneWithDefault("#"))
            {
                advancedBus.Bind(exchange, queue, topic);
            }

            Func <IMessage <object>, MessageReceivedInfo, Task> oms = (message, messageRecievedInfo) => onMessage(message.Body);

            return(advancedBus.Consume(queue, x => x.Add(oms)));
        }
コード例 #2
0
        public IDisposable SubscribeAsync(
            [NotNull] Type type,
            [NotNull] string subscriptionId,
            [NotNull] Func<object, Task> onMessage,
            [NotNull] Action<IAdvancedSubscriptionConfiguration> configure
        )
        {
            if (type == null) throw new ArgumentNullException("type");
            if (subscriptionId == null) throw new ArgumentNullException("subscriptionId");
            if (onMessage == null) throw new ArgumentNullException("onMessage");
            if (configure == null) throw new ArgumentNullException("configure");

            var configuration = new AdvancedSubscriptionConfiguration();
            configure(configuration);

            var queueName = conventions.QueueNamingConvention(type, subscriptionId);
            var exchangeName = conventions.ExchangeNamingConvention(type);

            var queue = advancedBus.QueueDeclare(queueName, durable: configuration.Durable, autoDelete: configuration.AutoDelete);
            var exchange = advancedBus.ExchangeDeclare(exchangeName, ExchangeType.Topic);

            foreach (var topic in configuration.Topics.AtLeastOneWithDefault("#"))
            {
                advancedBus.Bind(exchange, queue, topic);
            }

            Func<IMessage<object>, MessageReceivedInfo, Task> oms = (message, messageRecievedInfo) => onMessage(message.Body);

            return advancedBus.Consume(queue, x => x.Add(oms));
        }