public static void CreateProducerRegistration(string solutionDirectory, string srcDirectory, Producer producer, string projectBaseName) { var className = $@"{producer.EndpointRegistrationMethodName}Registration"; var classPath = ClassPathHelper.WebApiProducersServiceExtensionsClassPath(srcDirectory, $"{className}.cs", projectBaseName); if (!Directory.Exists(classPath.ClassDirectory)) { Directory.CreateDirectory(classPath.ClassDirectory); } if (File.Exists(classPath.FullClassPath)) { throw new FileAlreadyExistsException(classPath.FullClassPath); } using FileStream fs = File.Create(classPath.FullClassPath); var data = ""; if (ExchangeTypeEnum.FromName(producer.ExchangeType) == ExchangeTypeEnum.Direct || ExchangeTypeEnum.FromName(producer.ExchangeType) == ExchangeTypeEnum.Topic) { data = GetDirectOrTopicProducerRegistration(solutionDirectory, classPath.ClassNamespace, className, producer); } else { data = GetFanoutProducerRegistration(solutionDirectory, classPath.ClassNamespace, className, producer); } fs.Write(Encoding.UTF8.GetBytes(data)); }
public static string GetDirectOrTopicConsumerRegistration(string classNamespace, string className, Consumer consumer, string lazyText, string quorumText, string consumerFeatureUsing) { var exchangeType = ExchangeTypeEnum.FromName(consumer.ExchangeType) == ExchangeTypeEnum.Direct ? "ExchangeType.Direct" : "ExchangeType.Topic"; return(@$ "namespace {classNamespace}; using MassTransit; using MassTransit.RabbitMqTransport; using RabbitMQ.Client; using {consumerFeatureUsing};
public static string GetDirectOrTopicProducerRegistration(string solutionDirectory, string classNamespace, string className, Producer producer) { var exchangeType = ExchangeTypeEnum.FromName(producer.ExchangeType) == ExchangeTypeEnum.Direct ? "ExchangeType.Direct" : "ExchangeType.Topic"; var messagesClassPath = ClassPathHelper.MessagesClassPath(solutionDirectory, ""); return(@$ "namespace {classNamespace}; using MassTransit; using MassTransit.RabbitMqTransport; using {messagesClassPath.ClassNamespace}; using RabbitMQ.Client;
public static void CreateConsumerRegistration(string solutionDirectory, Consumer consumer, string projectBaseName) { var className = $@"{consumer.EndpointRegistrationMethodName}Registration"; var classPath = ClassPathHelper.WebApiConsumersServiceExtensionsClassPath(solutionDirectory, $"{className}.cs", projectBaseName); var consumerFeatureClassPath = ClassPathHelper.ConsumerFeaturesClassPath(solutionDirectory, $"{consumer.ConsumerName}.cs", consumer.DomainDirectory, projectBaseName); if (!Directory.Exists(classPath.ClassDirectory)) { Directory.CreateDirectory(classPath.ClassDirectory); } if (File.Exists(classPath.FullClassPath)) { throw new FileAlreadyExistsException(classPath.FullClassPath); } var quorumText = consumer.IsQuorum ? $@" // a replicated queue to provide high availability and data safety. available in RMQ 3.8+ re.SetQuorumQueue();" : ""; var lazyText = consumer.IsLazy ? $@" // enables a lazy queue for more stable cluster with better predictive performance. // Please note that you should disable lazy queues if you require really high performance, if the queues are always short, or if you have set a max-length policy. re.SetQueueArgument(""declare"", ""lazy"");" : ""; //re.Lazy = true;" : ""; using FileStream fs = File.Create(classPath.FullClassPath); var data = ""; if (ExchangeTypeEnum.FromName(consumer.ExchangeType) == ExchangeTypeEnum.Direct || ExchangeTypeEnum.FromName(consumer.ExchangeType) == ExchangeTypeEnum.Topic) { data = GetDirectOrTopicConsumerRegistration(classPath.ClassNamespace, className, consumer, lazyText, quorumText, consumerFeatureClassPath.ClassNamespace); } else { data = GetFanoutConsumerRegistration(classPath.ClassNamespace, className, consumer, lazyText, quorumText, consumerFeatureClassPath.ClassNamespace); } fs.Write(Encoding.UTF8.GetBytes(data)); }