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);
        }
示例#2
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);
        }