public ICloudQueuePublisherBusConfigurationBuilder PublishTo(string queueName, Action<ISubscriptionConfigurationBuilder> configure)
 {
     if (queueName == null) throw new ArgumentNullException("address");
     if (configure == null) throw new ArgumentNullException("configure");
     var builder = new SubscriptionConfigurationBuilder(queueName);
     configure(builder);
     foreach (var subscription in builder.Build())
     {
         _subscriptions.Add(subscription);
     }
     return this;
 }
        public SubscriptionConfiguration GetConfiguration(Type messageType, Action <ISubscriptionConfigurationBuilder> configuration = null)
        {
            configuration = configuration ?? (builder => { });

            // 根据注解属性获取Exchange、Queue和Routing Key值
            configuration = (builder =>
            {
                builder
                .WithExchange(ExchangeAction(messageType))
                .WithQueue(QueueAction(messageType));

                var routingAttr = GetAttribute <RoutingAttribute>(messageType);
                if (routingAttr != null)
                {
                    if (routingAttr.NullableNoAck.HasValue)
                    {
                        builder.WithNoAck(routingAttr.NullableNoAck.Value);
                    }
                    if (routingAttr.PrefetchCount > 0)
                    {
                        builder.WithPrefetchCount(routingAttr.PrefetchCount);
                    }
                    if (routingAttr.RoutingKey != null)
                    {
                        builder.WithRoutingKey(routingAttr.RoutingKey);
                    }
                }
            }) + configuration;

            var routingKey  = _conventions.QueueNamingConvention(messageType);
            var queueConfig = new QueueConfiguration(_clientConfig.Queue)
            {
                QueueName  = routingKey,
                NameSuffix = _conventions.SubscriberQueueSuffix(messageType)
            };

            var exchangeConfig = new ExchangeConfiguration(_clientConfig.Exchange)
            {
                ExchangeName = _conventions.ExchangeNamingConvention(messageType)
            };

            var cfgBuilder = new SubscriptionConfigurationBuilder(queueConfig, exchangeConfig, routingKey);

            configuration?.Invoke(cfgBuilder);
            return(cfgBuilder.Configuration);
        }
Пример #3
0
        public SubscriptionConfiguration GetConfiguration(Type messageType, Action <ISubscriptionConfigurationBuilder> configuration = null)
        {
            var routingKey  = _conventions.QueueNamingConvention(messageType);
            var queueConfig = new QueueConfiguration(_clientConfig.Queue)
            {
                QueueName  = routingKey,
                NameSuffix = _conventions.SubscriberQueueSuffix(messageType)
            };

            var exchangeConfig = new ExchangeConfiguration(_clientConfig.Exchange)
            {
                ExchangeName = _conventions.ExchangeNamingConvention(messageType)
            };

            var builder = new SubscriptionConfigurationBuilder(queueConfig, exchangeConfig, routingKey);

            configuration?.Invoke(builder);
            return(builder.Configuration);
        }