init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
|
@ -0,0 +1,113 @@
|
|||
using System.Configuration;
|
||||
using Kreta.Core.MessageBroker.Logging.Serilog.Configuration;
|
||||
using Serilog.Events;
|
||||
using Serilog.Sinks.Elasticsearch;
|
||||
|
||||
namespace Kreta.MessageBroker.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Elastic search configuration element
|
||||
/// </summary>
|
||||
public class ElasticSearchConfigurationElement : ConfigurationElement, IElasticSearchConfiguration
|
||||
{
|
||||
#region [Properties]
|
||||
|
||||
/// <summary>
|
||||
/// Use custom back-off logic
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(UseCustomBackOffLogic), IsRequired = true)]
|
||||
public bool UseCustomBackOffLogic
|
||||
{
|
||||
get
|
||||
{
|
||||
return (bool)base[nameof(UseCustomBackOffLogic)];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// URI - s to send log
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(NodeUris), IsRequired = true)]
|
||||
public string NodeUris
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)base[nameof(NodeUris)];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elastic search index format
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(IndexFormat), IsRequired = true)]
|
||||
public string IndexFormat
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)base[nameof(IndexFormat)];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Minimum log event level
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(MinimumLogEventLevel), IsRequired = false, DefaultValue = LogEventLevel.Information)]
|
||||
public LogEventLevel MinimumLogEventLevel
|
||||
{
|
||||
get
|
||||
{
|
||||
return (LogEventLevel)base[nameof(MinimumLogEventLevel)];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The connection timeout when sending bulk operations to elasticsearch in seconds
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(ConnectionTimeoutInSeconds), IsRequired = false)]
|
||||
public int? ConnectionTimeoutInSeconds
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int?)base[nameof(ConnectionTimeoutInSeconds)];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Seconds wait between checking event batches
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(WaitBetweenForCheckingEventBatchesInSeconds), IsRequired = false)]
|
||||
public int? WaitBetweenForCheckingEventBatchesInSeconds
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int?)base[nameof(WaitBetweenForCheckingEventBatchesInSeconds)];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The maximum number of events to post in a single batch.
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(BatchPostingLimit), IsRequired = false)]
|
||||
public int? BatchPostingLimit
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int?)base[nameof(BatchPostingLimit)];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Auto register template version
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(AutoRegisterTemplateVersion), IsRequired = false)]
|
||||
public AutoRegisterTemplateVersion? AutoRegisterTemplateVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
return (AutoRegisterTemplateVersion?)base[nameof(AutoRegisterTemplateVersion)];
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
using System.Configuration;
|
||||
using Kreta.Core.MessageBroker.Azure.EventHub.Client.Configuration;
|
||||
using Validators = Kreta.Core.Configuration.Validators;
|
||||
|
||||
namespace Kreta.MessageBroker.Configuration
|
||||
{
|
||||
public class EventHubClientConfigurationElement : ConfigurationElement, IAzureEventHubClientConfiguration
|
||||
{
|
||||
#region [Properties]
|
||||
|
||||
/// <summary>
|
||||
/// Event hub name
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(Name), IsRequired = true, DefaultValue = Validators.StringValidator.SkipValidationForDefaultValue)]
|
||||
[Validators.StringValidator(false, MaxLength = Constants.Azure.EventHub.NameMaximumLength)]
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)this[nameof(Name)];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event hub entity connection string
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(ConnectionString), IsRequired = true, DefaultValue = Validators.StringValidator.SkipValidationForDefaultValue)]
|
||||
[Validators.StringValidator(false, MaxLength = Constants.Azure.EventHub.ConnectionStringMaximumLength)]
|
||||
public string ConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)this[nameof(ConnectionString)];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event hub entity path
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(EntityPath), IsRequired = true, DefaultValue = Validators.StringValidator.SkipValidationForDefaultValue)]
|
||||
[Validators.StringValidator(false, MaxLength = Constants.Azure.EventHub.EntityPathMaximumLength)]
|
||||
public string EntityPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)this[nameof(EntityPath)];
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using Kreta.Core.MessageBroker.Azure.EventHub.Client.Configuration;
|
||||
|
||||
namespace Kreta.MessageBroker.Configuration
|
||||
{
|
||||
public class EventHubClientConfigurationElementCollection : ConfigurationElementCollection, IEnumerable<IAzureEventHubClientConfiguration>
|
||||
{
|
||||
#region [Properties]
|
||||
|
||||
/// <summary>
|
||||
/// Collection type
|
||||
/// </summary>
|
||||
public override ConfigurationElementCollectionType CollectionType
|
||||
{
|
||||
get { return ConfigurationElementCollectionType.BasicMap; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get element name
|
||||
/// </summary>
|
||||
protected override string ElementName
|
||||
{
|
||||
get { return "EventHub"; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region [Private/Protected Methods]
|
||||
|
||||
/// <summary>
|
||||
/// Create new element
|
||||
/// </summary>
|
||||
/// <returns>Configuration element</returns>
|
||||
protected override ConfigurationElement CreateNewElement()
|
||||
{
|
||||
return new EventHubClientConfigurationElement();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get element key
|
||||
/// </summary>
|
||||
/// <param name="element">Element</param>
|
||||
/// <returns>Element key</returns>
|
||||
protected override object GetElementKey(ConfigurationElement element)
|
||||
{
|
||||
return ((EventHubClientConfigurationElement)element).Name;
|
||||
}
|
||||
|
||||
IEnumerator<IAzureEventHubClientConfiguration> IEnumerable<IAzureEventHubClientConfiguration>.GetEnumerator()
|
||||
{
|
||||
var enumerator = base.GetEnumerator();
|
||||
|
||||
var eventHubClientConfiguration = new List<IAzureEventHubClientConfiguration>();
|
||||
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
eventHubClientConfiguration.Add((IAzureEventHubClientConfiguration)enumerator.Current);
|
||||
}
|
||||
|
||||
return eventHubClientConfiguration.GetEnumerator();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
namespace Kreta.MessageBroker.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Notification configuration section
|
||||
/// </summary>
|
||||
interface IMessageBrokerConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// Clients
|
||||
/// </summary>
|
||||
MessageClientConfigurationElementCollection Clients { get; }
|
||||
}
|
||||
}
|
8
Kreta.MessageBroker/Configuration/LoggerType.cs
Normal file
8
Kreta.MessageBroker/Configuration/LoggerType.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace Kreta.MessageBroker.Configuration
|
||||
{
|
||||
public enum LoggerType
|
||||
{
|
||||
Log4Net,
|
||||
Serilog
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using Kreta.Core.MessageBroker.Azure.EventHub.Client.Configuration;
|
||||
|
||||
namespace Kreta.MessageBroker.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Message client configuration section
|
||||
/// </summary>
|
||||
public class MessageBrokerConfigurationSection : ConfigurationSection, IMessageBrokerConfiguration, IAzureEventHubClientsConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of section
|
||||
/// </summary>
|
||||
const string SectionName = "MessageBroker";
|
||||
|
||||
/// <summary>
|
||||
/// The instance
|
||||
/// </summary>
|
||||
static Lazy<MessageBrokerConfigurationSection> instance;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The instance.
|
||||
/// </value>
|
||||
public static MessageBrokerConfigurationSection Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
return instance.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clients
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(Clients))]
|
||||
[ConfigurationCollection(typeof(MessageClientConfigurationElement))]
|
||||
public MessageClientConfigurationElementCollection Clients
|
||||
{
|
||||
get
|
||||
{
|
||||
return (MessageClientConfigurationElementCollection)base[nameof(Clients)];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clients
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(EventHubs))]
|
||||
[ConfigurationCollection(typeof(EventHubClientConfigurationElement))]
|
||||
public EventHubClientConfigurationElementCollection EventHubs
|
||||
{
|
||||
get
|
||||
{
|
||||
return (EventHubClientConfigurationElementCollection)base[nameof(EventHubs)];
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerable<IAzureEventHubClientConfiguration> IAzureEventHubClientsConfiguration.EventHubs => this.EventHubs;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MessageBrokerConfigurationSection"/> class.
|
||||
/// </summary>
|
||||
static MessageBrokerConfigurationSection()
|
||||
{
|
||||
instance = new Lazy<MessageBrokerConfigurationSection>(() =>
|
||||
{
|
||||
var section = (MessageBrokerConfigurationSection)ConfigurationManager.GetSection(SectionName);
|
||||
|
||||
if (section == null)
|
||||
{
|
||||
throw new ConfigurationErrorsException($"{SectionName} configuration section was not found");
|
||||
}
|
||||
|
||||
return section;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
using System.Configuration;
|
||||
using Kreta.Core.MessageBroker.Configuration.IntegratedMessageClient;
|
||||
using Validators = Kreta.Core.Configuration.Validators;
|
||||
|
||||
namespace Kreta.MessageBroker.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Message client configuration element
|
||||
/// </summary>
|
||||
class MessageClientConfigurationElement : ConfigurationElement, IIntegratedMessageClientConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// Element name
|
||||
/// </summary>
|
||||
public const string ElementName = "Client";
|
||||
|
||||
/// <summary>
|
||||
/// Client name
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(Name), IsRequired = true, DefaultValue = Validators.StringValidator.SkipValidationForDefaultValue)]
|
||||
[Validators.StringValidator(false, MaxLength = 128)]
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)this[nameof(Name)];
|
||||
}
|
||||
}
|
||||
|
||||
string IIntegratedMessageClientConfiguration.EndpointClientName => this.Name;
|
||||
|
||||
/// <summary>
|
||||
/// Message signature key
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(MessageSignatureKey), IsRequired = true, DefaultValue = Validators.StringValidator.SkipValidationForDefaultValue)]
|
||||
[Validators.StringValidator(false, MinLength = 32, MaxLength = 128)]
|
||||
public string MessageSignatureKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)this[nameof(MessageSignatureKey)];
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(nameof(QueueSize), DefaultValue = 0)]
|
||||
public int QueueSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)this[nameof(QueueSize)];
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(nameof(ClientPoolSize), DefaultValue = 8)]
|
||||
[Validators.IntegerValidator(MinValue = 1)]
|
||||
public int ClientPoolSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)this[nameof(ClientPoolSize)];
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(nameof(CreateNewClientAfterErrorsCount), DefaultValue = 20)]
|
||||
[Validators.IntegerValidator(MinValue = 3)]
|
||||
public int CreateNewClientAfterErrorsCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)this[nameof(CreateNewClientAfterErrorsCount)];
|
||||
}
|
||||
}
|
||||
|
||||
int? IIntegratedMessageClientConfiguration.CreateNewClientAfterErrorsCount => this.CreateNewClientAfterErrorsCount == 0 ? (int?)null : this.CreateNewClientAfterErrorsCount;
|
||||
|
||||
/// <summary>
|
||||
/// Enable logging
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(EnableLogging), IsRequired = true)]
|
||||
public bool EnableLogging
|
||||
{
|
||||
get
|
||||
{
|
||||
return (bool)this[nameof(EnableLogging)];
|
||||
}
|
||||
}
|
||||
|
||||
bool IIntegratedMessageClientConfiguration.IsLoggingEnabled => this.EnableLogging;
|
||||
|
||||
[ConfigurationProperty(nameof(LoggerType), DefaultValue = LoggerType.Log4Net)]
|
||||
public LoggerType LoggerType
|
||||
{
|
||||
get
|
||||
{
|
||||
return (LoggerType)this[nameof(LoggerType)];
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(nameof(SerilogLogger))]
|
||||
public SerilogConfigurationElement SerilogLogger
|
||||
{
|
||||
get
|
||||
{
|
||||
return (SerilogConfigurationElement)this[nameof(SerilogLogger)];
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(nameof(CalculateBackOffTimeSpan), DefaultValue = true)]
|
||||
public bool CalculateBackOffTimeSpan
|
||||
{
|
||||
get
|
||||
{
|
||||
return (bool)this[nameof(CalculateBackOffTimeSpan)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
using System.Configuration;
|
||||
|
||||
namespace Kreta.MessageBroker.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Message client configuration element collection
|
||||
/// </summary>
|
||||
public class MessageClientConfigurationElementCollection : ConfigurationElementCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Collection type
|
||||
/// </summary>
|
||||
public override ConfigurationElementCollectionType CollectionType
|
||||
{
|
||||
get { return ConfigurationElementCollectionType.BasicMap; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create new element
|
||||
/// </summary>
|
||||
/// <returns>Configuration element</returns>
|
||||
protected override ConfigurationElement CreateNewElement()
|
||||
{
|
||||
return new MessageClientConfigurationElement();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get element key
|
||||
/// </summary>
|
||||
/// <param name="element">Element</param>
|
||||
/// <returns>Element key</returns>
|
||||
protected override object GetElementKey(ConfigurationElement element)
|
||||
{
|
||||
return ((MessageClientConfigurationElement)element).Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get element name
|
||||
/// </summary>
|
||||
protected override string ElementName
|
||||
{
|
||||
get { return MessageClientConfigurationElement.ElementName; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
using System.Configuration;
|
||||
using Kreta.Core.MessageBroker.Logging.Serilog.Configuration;
|
||||
|
||||
namespace Kreta.MessageBroker.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Serilog - Elastic search konfiguráció
|
||||
/// </summary>
|
||||
public class SerilogConfigurationElement : ConfigurationElement, ISerilogConfiguration
|
||||
{
|
||||
#region [Properties]
|
||||
|
||||
/// <summary>
|
||||
/// Lossy buffer count
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(LossyBufferSize), IsRequired = true)]
|
||||
public int LossyBufferSize
|
||||
{
|
||||
get
|
||||
{
|
||||
return (int)base[nameof(LossyBufferSize)];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serilog loggers
|
||||
/// </summary>
|
||||
[ConfigurationProperty(nameof(ElasticSearch), IsRequired = false)]
|
||||
public ElasticSearchConfigurationElement ElasticSearch
|
||||
{
|
||||
get
|
||||
{
|
||||
return (ElasticSearchConfigurationElement)base[nameof(ElasticSearch)];
|
||||
}
|
||||
}
|
||||
|
||||
IElasticSearchConfiguration ISerilogConfiguration.ElasticSearch
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.ElasticSearch;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region [Protected methods]
|
||||
|
||||
/// <summary>
|
||||
/// Custom validations
|
||||
/// </summary>
|
||||
protected override void PostDeserialize()
|
||||
{
|
||||
if (!this.ElasticSearch.ElementInformation.IsPresent)
|
||||
{
|
||||
throw new ConfigurationErrorsException($"At least one logger sink must be defined. (e.g:{nameof(ElasticSearch)})");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue