public IExchangeUpdateBuilder ExchangeForMessage <TMessage>()
 {
     _current = new ExchangeUpdateConfiguration
     {
         ExchangeName = _conventions.ExchangeNamingConvention(typeof(TMessage))
     };
     return(this);
 }
        public ConsumerConfiguration Create(Type messageType)
        {
            var queueName    = _conventions.QueueNamingConvention(messageType);
            var exchangeName = _conventions.ExchangeNamingConvention(messageType);
            var routingKey   = _conventions.RoutingKeyConvention(messageType);

            return(Create(queueName, exchangeName, routingKey));
        }
        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);
        }
Esempio n. 4
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);
        }
 protected virtual string GetExchangeName(Type type)
 {
     return(_conventions.ExchangeNamingConvention(type));
 }
Esempio n. 6
0
 public IConventions Get <T>() where T : class
 {
     return(new Conventions(typeof(T), _conventions.RoutingKeyConvention(typeof(T)),
                            _conventions.ExchangeNamingConvention(typeof(T)), _conventions.QueueNamingConvention(typeof(T))));
 }
        public ExchangeDeclaration Create(Type messageType)
        {
            var exchangeName = _conventions.ExchangeNamingConvention(messageType);

            return(Create(exchangeName));
        }