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}"); }
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); }