/// <summary> /// The get request config. /// </summary> /// <param name="endpointName"> /// The endpoint name. /// </param> /// <param name="key"> /// The key. /// </param> /// <returns> /// The <see cref="IRequestConfiguration"/>. /// </returns> public IRequestConfiguration GetRequestConfig(string endpointName, string key) { EndpointElement endpoint = this.GetEndPointByName(endpointName); OutgoingElement reqDeclaration = endpoint.Outgoing.Cast <OutgoingElement>(). First(x => x.Key == key); return(new RequestConfiguration(reqDeclaration.Timeout, reqDeclaration.Persist, reqDeclaration.Ttl)); }
/// <summary> /// The get event. /// </summary> /// <param name="endpointName"> /// The endpoint name. /// </param> /// <param name="key"> /// The key. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> public string GetEvent(string endpointName, string key) { EndpointElement endpoint = this.GetEndPointByName(endpointName); IEnumerable <MessageElement> messages = endpoint.Outgoing.Cast <MessageElement>(). Concat(endpoint.Incoming.Cast <MessageElement>()); // NOTE: Если такого не будет, упадет соответствующий эксэпшн. return(messages.First(x => x.Key == key). Label); }
/// <summary> /// The get end point by name. /// </summary> /// <param name="endpointName"> /// The endpoint name. /// </param> /// <returns> /// The <see cref="EndpointElement"/>. /// </returns> /// <exception cref="ArgumentException"> /// </exception> private EndpointElement GetEndPointByName(string endpointName) { EndpointElement endpoint = this.endpointsConfig.Endpoints[endpointName]; if (endpoint == null) { throw new ArgumentException(string.Format("Попытка найти конфигурацию для endpoint {0} закончилось провалом, пожалуйста укажите необходимую информацию в конфигурации {1}", endpointName, ServiceBusSectionName)); } return(endpoint); }
/// <summary> /// Конфигурирует клиента шины сообщений. /// </summary> /// <param name="endpointName"> /// Имя точки подключения к шине. /// </param> /// <param name="cfg"> /// Конфигуратор клиента шины. /// </param> /// <returns> /// Конфигуратор клиента шины, после применения к нему всех настроек. /// </returns> public IBusConfigurator Configure(string endpointName, IBusConfigurator cfg) { if (cfg == null) { throw new ArgumentNullException("cfg", "Файл конфигурации не может быть null"); } EndpointElement endpointConfig = this.GetEndPointByName(endpointName); cfg.SetEndpoint(endpointConfig.Name); cfg.SetConnectionString(endpointConfig.ConnectionString); if (!string.IsNullOrWhiteSpace(endpointConfig.LifecycleHandler)) { cfg.HandleLifecycleWith(this.ResolveLifecycleHandler(endpointConfig.LifecycleHandler)); } if (endpointConfig.Caching != null && endpointConfig.Caching.Enabled) { cfg.EnableCaching(); } if (endpointConfig.ParallelismLevel.HasValue) { cfg.UseParallelismLevel(endpointConfig.ParallelismLevel.Value); } if (endpointConfig.Dynamic != null) { if (endpointConfig.Dynamic.Outgoing.HasValue) { if (endpointConfig.Dynamic.Outgoing.Value) { cfg.Route(MessageLabel.Any) .ConfiguredWith(builder => new LambdaRouteResolver( (endpoint, label) => { builder.Topology.Declare( Exchange.Named(label.Name) .Durable.Fanout); return(new RabbitRoute(label.Name)); })); } } } if (endpointConfig.Qos != null) { if (endpointConfig.Qos.PrefetchCount.HasValue) { cfg.SetDefaultQoS(endpointConfig.Qos.PrefetchCount.Value); } } foreach (ValidatorElement validator in endpointConfig.Validators) { if (validator.Group) { MessageValidatorGroup v = this.ResolveValidatorGroup(validator.Name); cfg.RegisterValidators(v); } else { IMessageValidator v = this.ResolveValidator(validator.Name); cfg.RegisterValidator(v); } } foreach (OutgoingElement message in endpointConfig.Outgoing) { ISenderConfigurator senderCfg = cfg.Route(message.Label). WithAlias(message.Key); if (message.Confirm) { senderCfg.WithConfirmation(); } if (message.Persist) { senderCfg.Persistently(); } if (message.Ttl.HasValue) { senderCfg.WithTtl(message.Ttl.Value); } if (message.CallbackEndpoint.Default) { senderCfg.WithDefaultCallbackEndpoint(); } if (message.Timeout.HasValue) { senderCfg.WithRequestTimeout(message.Timeout); } } foreach (IncomingElement message in endpointConfig.Incoming) { IReceiverConfigurator receiver = cfg.On(message.Label). WithAlias(message.Key); if (message.RequiresAccept) { receiver.RequiresAccept(); } Type messageType = typeof(ExpandoObject); if (!string.IsNullOrWhiteSpace(message.Type)) { messageType = ResolveType(message.Type); } var consumerFactory = this.BuildConsumerFactory(message.React, messageType); object consumer = BuildConsumer(consumerFactory, messageType, message.Lifestyle); RegisterConsumer(receiver, messageType, consumer); if (!string.IsNullOrWhiteSpace(message.Validate)) { IMessageValidator validator = this.ResolveValidator(message.Validate, messageType); receiver.WhenVerifiedBy(validator); } } return(cfg); }
private IDictionary <string, CacheConfiguration> GetConfigFromMessageElements(EndpointElement endpoint, IEnumerable configElementsCollection, Func <MessageElement, string> keySelector) { var defaultConfig = this.GetConfiguration(endpoint.ExtensionConfigurations, this.GetDefault()); return(configElementsCollection.Cast <MessageElement>().ToDictionary(keySelector, o => this.GetConfiguration(o.ExtensionConfigurations, defaultConfig))); }
/// <summary> /// Конфигурирует клиента шины сообщений. /// </summary> /// <param name="endpointName"> /// Имя точки подключения к шине. /// </param> /// <param name="cfg"> /// Конфигуратор клиента шины. /// </param> /// <returns> /// Конфигуратор клиента шины, после применения к нему всех настроек. /// </returns> public IBusConfigurator Configure(string endpointName, IBusConfigurator cfg) { if (cfg == null) { throw new ArgumentNullException("cfg", "Файл конфигурации не может быть null"); } EndpointElement endpointConfig = this.GetEndPointByName(endpointName); cfg.SetEndpoint(endpointConfig.Name); cfg.SetConnectionString(endpointConfig.ConnectionString); if (endpointConfig.ReuseConnection.HasValue) { cfg.ReuseConnection(endpointConfig.ReuseConnection.Value); } if (!string.IsNullOrWhiteSpace(endpointConfig.LifecycleHandler)) { cfg.HandleLifecycleWith(this.ResolveLifecycleHandler(endpointConfig.LifecycleHandler)); } if (endpointConfig.Caching != null && endpointConfig.Caching.Enabled) { cfg.EnableCaching(); } if (endpointConfig.ParallelismLevel.HasValue) { cfg.UseParallelismLevel(endpointConfig.ParallelismLevel.Value); } if (endpointConfig.FaultQueueTtl.HasValue) { cfg.UseFaultQueueTtl(endpointConfig.FaultQueueTtl.Value); } if (endpointConfig.FaultQueueLimit.HasValue) { cfg.UseFaultQueueLimit(endpointConfig.FaultQueueLimit.Value); } if (endpointConfig.Dynamic != null) { if (endpointConfig.Dynamic.Outgoing.HasValue) { if (endpointConfig.Dynamic.Outgoing.Value) { cfg.Route(MessageLabel.Any) .ConfiguredWith(builder => new LambdaRouteResolver( (endpoint, label) => { builder.Topology.Declare( Exchange.Named(label.Name) .Durable.Fanout); return(new RabbitRoute(label.Name)); })); } } } if (endpointConfig.Qos != null) { if (endpointConfig.Qos.PrefetchCount.HasValue) { cfg.SetDefaultQoS(endpointConfig.Qos.PrefetchCount.Value); } } foreach (ValidatorElement validator in endpointConfig.Validators) { if (validator.Group) { MessageValidatorGroup v = this.ResolveValidatorGroup(validator.Name); cfg.RegisterValidators(v); } else { IMessageValidator v = this.ResolveValidator(validator.Name); cfg.RegisterValidator(v); } } foreach (OutgoingElement outgoingElement in endpointConfig.Outgoing) { var configurator = cfg.Route(outgoingElement.Label).WithAlias(outgoingElement.Key); if (outgoingElement.Confirm) { configurator.WithConfirmation(); } if (outgoingElement.Persist) { configurator.Persistently(); } if (outgoingElement.Ttl.HasValue) { configurator.WithTtl(outgoingElement.Ttl.Value); } if (outgoingElement.CallbackEndpoint.Default) { configurator.WithDefaultCallbackEndpoint(); } if (outgoingElement.Timeout.HasValue) { configurator.WithRequestTimeout(outgoingElement.Timeout); } // Connection string var connectionString = endpointConfig.ConnectionString; if (!string.IsNullOrEmpty(outgoingElement.ConnectionString)) { connectionString = outgoingElement.ConnectionString; } configurator.WithConnectionString(connectionString); // Reuse connection if (outgoingElement.ReuseConnection.HasValue) { configurator.ReuseConnection(outgoingElement.ReuseConnection.Value); } } foreach (IncomingElement incomingElement in endpointConfig.Incoming) { var configurator = cfg.On(incomingElement.Label).WithAlias(incomingElement.Key); uint size = 0; ushort count = 50; // This should be the default values provided by RabbitMQ configurator (BusConsumerConfigurationEx); var qos = configurator.GetQoS(); if (qos.HasValue) { size = qos.Value.PrefetchSize; count = qos.Value.PrefetchCount; } // Prefetch size if (endpointConfig.Qos.PrefetchSize.HasValue) { size = endpointConfig.Qos.PrefetchSize.Value; } if (incomingElement.Qos.PrefetchSize.HasValue) { size = incomingElement.Qos.PrefetchSize.Value; } // Prefetch count if (endpointConfig.Qos.PrefetchCount.HasValue) { count = endpointConfig.Qos.PrefetchCount.Value; } if (incomingElement.Qos.PrefetchCount.HasValue) { count = incomingElement.Qos.PrefetchCount.Value; } configurator.WithQoS(new QoSParams(count, size)); // Parallelism level if (endpointConfig.ParallelismLevel.HasValue) { configurator.WithParallelismLevel(endpointConfig.ParallelismLevel.Value); } if (incomingElement.ParallelismLevel.HasValue) { configurator.WithParallelismLevel(incomingElement.ParallelismLevel.Value); } // Accept if (incomingElement.RequiresAccept) { configurator.RequiresAccept(); } // Connection string var connectionString = endpointConfig.ConnectionString; if (!string.IsNullOrEmpty(incomingElement.ConnectionString)) { connectionString = incomingElement.ConnectionString; } configurator.WithConnectionString(connectionString); // Reuse connection if (incomingElement.ReuseConnection.HasValue) { configurator.ReuseConnection(incomingElement.ReuseConnection.Value); } Type messageType = typeof(ExpandoObject); if (!string.IsNullOrWhiteSpace(incomingElement.Type)) { messageType = ResolveType(incomingElement.Type); } var consumerFactory = this.BuildConsumerFactory(incomingElement.React, messageType); object consumer = BuildConsumer(consumerFactory, messageType, incomingElement.Lifestyle); RegisterConsumer(configurator, messageType, consumer); if (!string.IsNullOrWhiteSpace(incomingElement.Validate)) { IMessageValidator validator = this.ResolveValidator(incomingElement.Validate, messageType); configurator.WhenVerifiedBy(validator); } } return(cfg); }