Exemple #1
0
        public void TopicIsProperlyTranslatedToRegex(string topic, string expectedRegex)
        {
            // Act
            TopicAttribute attribute = new TopicAttribute(topic);

            // Assert
            Assert.AreEqual(expectedRegex, attribute.TopicRegularExpression.ToString());
        }
Exemple #2
0
        public void TopicIsProperlySet(string topic)
        {
            // Act
            TopicAttribute attribute = new TopicAttribute(topic);

            // Assert
            Assert.AreEqual(topic, attribute.TopicPattern);
        }
Exemple #3
0
        private ConsumerExecutorDescriptor InitDescriptor(TopicAttribute attr, MethodInfo methodInfo, TypeInfo implType)
        {
            var descriptor = new ConsumerExecutorDescriptor
            {
                Attribute    = attr,
                MethodInfo   = methodInfo,
                ImplTypeInfo = implType
            };

            return(descriptor);
        }
Exemple #4
0
 private void SetSubscribeAttribute(TopicAttribute attribute)
 {
     if (attribute.Group == null)
     {
         attribute.Group = CapOptions.DefaultGroup + "." + CapOptions.Version;
     }
     else
     {
         attribute.Group = attribute.Group + "." + CapOptions.Version;
     }
 }
Exemple #5
0
 protected virtual void SetSubscribeAttribute(TopicAttribute attribute)
 {
     if (attribute.Group == null)
     {
         attribute.Group = _capOptions.DefaultGroup + "." + _capOptions.Version;
     }
     else
     {
         attribute.Group = attribute.Group + "." + _capOptions.Version;
     }
 }
Exemple #6
0
 private static ConsumerExecutorDescriptor InitDescriptor(TopicAttribute attr, MethodInfo methodInfo, TypeInfo implType, TypeInfo serviceTypeInfo, IList <ParameterDescriptor> parameters, TopicAttribute classAttr = null)
 {
     return(new ConsumerExecutorDescriptor
     {
         Attribute = attr,
         ClassAttribute = classAttr,
         MethodInfo = methodInfo,
         ImplTypeInfo = implType,
         ServiceTypeInfo = serviceTypeInfo,
         Parameters = parameters
     });
 }
        private string GetTopic(Type type)
        {
            string topicName = type.Name;

            var topicAttr = TopicAttribute.GetTopicAttribute(type);

            if (topicAttr != null && !string.IsNullOrEmpty(topicAttr.Name))
            {
                topicName = topicAttr.Name;
            }
            return($"{_options.TopicPrefix ?? ""}{topicName}");
        }
        private ConsumerExecutorDescriptor InitDescriptor(TopicAttribute attr, MethodInfo methodInfo, TypeInfo implHandler,
                                                          TypeInfo serviceHandlerInfo, List <ParameterDescriptor> parameters)
        {
            var descriptor = new ConsumerExecutorDescriptor
            {
                Attribute       = attr,
                MethodInfo      = methodInfo,
                ImplTypeInfo    = implHandler,
                ServiceTypeInfo = serviceHandlerInfo,
                Parameters      = parameters
            };

            return(descriptor);
        }
        private static ConsumerExecutorDescriptor InitDescriptor(
            TopicAttribute attr,
            MethodInfo methodInfo,
            TypeInfo implType,
            TypeInfo serviceTypeInfo)
        {
            var descriptor = new ConsumerExecutorDescriptor
            {
                Attribute       = attr,
                MethodInfo      = methodInfo,
                ImplTypeInfo    = implType,
                ServiceTypeInfo = serviceTypeInfo
            };

            return(descriptor);
        }
        /// <summary>
        ///     Builds the methodTopic
        /// </summary>
        /// <param name="classType"></param>
        /// <param name="eventListener"></param>
        /// <param name="methodInfo"></param>
        /// <param name="topicAttribute"></param>
        /// <param name="firstParam"></param>
        private void BuildMethodTopic(Type classType, EventListener eventListener, MethodInfo methodInfo,
                                      TopicAttribute topicAttribute, ParameterInfo firstParam)
        {
            var hasDefaultConstructor = classType.GetConstructor(Type.EmptyTypes) != null;

            var methodTopicInfo = new MethodTopicInfo(classType, hasDefaultConstructor,
                                                      topicAttribute.TopicPattern, methodInfo, firstParam);

            if (eventListener.Topics.ContainsKey(topicAttribute))
            {
                eventListener.Topics[topicAttribute].Add(methodTopicInfo);
            }
            else
            {
                eventListener.Topics.Add(topicAttribute, new List <MethodTopicInfo> {
                    methodTopicInfo
                });
            }
        }
        public static string GetTopic(KafkaMessageBusOptions options, Type type)
        {
            string topicName = null;

            if (TopicCache.TryGetValue(type, out topicName))
            {
                return(topicName);
            }

            if (!string.IsNullOrEmpty(options.Topic))
            {
                topicName = options.Topic;
                topicName = $"{options.TopicPrefix ?? ""}{topicName}";
            }
            else
            {
                topicName = type.Name; //默认等于该类型的名称
                var topicAttr = TopicAttribute.GetTopicAttribute(type);
                if (topicAttr != null && !string.IsNullOrEmpty(topicAttr.Name))
                {
                    topicName = topicAttr.Name;
                }
                else
                {
                    var displayAttr = AttributeUtils.GetAttribute <DisplayAttribute>(type);
                    if (displayAttr != null && !string.IsNullOrEmpty(displayAttr.Name))
                    {
                        topicName = displayAttr.Name;
                    }
                }
                topicName = $"{options.TopicPrefix ?? ""}{topicName}";
            }


            TopicCache.TryAdd(type, topicName);

            return(topicName);
        }