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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        public override Task InvokeAsync(IPipeContext context, CancellationToken token)
        {
            var config = GetGetConfiguration(context);

            if (!string.IsNullOrWhiteSpace(config.QueueName))
            {
                return(Next.InvokeAsync(context, token));
            }

            var messageType = GetMessageType(context);

            config.QueueName = _conventions.QueueNamingConvention(messageType);
            return(Next.InvokeAsync(context, token));
        }
        public QueueDeclaration Create(Type messageType)
        {
            var queueName = _conventions.QueueNamingConvention(messageType);

            return(Create(queueName));
        }
Exemplo 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))));
 }