diff --git a/code/MessengerBroker.Configuration/MessengerBroker.Configuration.csproj b/code/MessengerBroker.Configuration/MessengerBroker.Configuration.csproj
new file mode 100644
index 0000000..bbcaa09
--- /dev/null
+++ b/code/MessengerBroker.Configuration/MessengerBroker.Configuration.csproj
@@ -0,0 +1,13 @@
+
+
+
+ net9.0
+ enable
+ disable
+
+
+
+
+
+
+
diff --git a/code/MessengerBroker.Configuration/Model/BrokerConfiguration.cs b/code/MessengerBroker.Configuration/Model/BrokerConfiguration.cs
new file mode 100644
index 0000000..62c3f18
--- /dev/null
+++ b/code/MessengerBroker.Configuration/Model/BrokerConfiguration.cs
@@ -0,0 +1,51 @@
+using MessengerApi.Configuration.Model.Persistence.Base;
+using MessengerApi.Configuration.Parsers;
+using MessengerApi.Configuration.Sources.Environment;
+using MessengerBroker.Configuration.Model.Servers;
+using MessengerBroker.Configuration.Parsers;
+using MessengerBroker.Configuration.Sources.Environment;
+
+namespace MessengerBroker.Configuration.Model
+{
+ public class BrokerConfiguration
+ {
+ public PersistenceConfiguration ApiPersistenceConfiguration { get; set; }
+
+ public PersistenceConfiguration BrokerPersistenceConfiguration { get; set; }
+
+ ///
+ /// List of proxies that are trusted to provide forwarding headers.
+ ///
+ public string[] Proxies { get; set; }
+
+ public Guid BrokerId { get; set; }
+
+ public MasterServer[] MasterServers { get; set; }
+
+ public SlaveServer[] SlaveServers { get; set; }
+
+ public BrokerConfiguration(
+ PersistenceConfiguration apiPersistenceConfiguration,
+ PersistenceConfiguration broPersistenceConfiguration,
+ Guid brokerId,
+ MasterServer[] masters,
+ SlaveServer[] slaves)
+ {
+ this.ApiPersistenceConfiguration = apiPersistenceConfiguration;
+ this.BrokerPersistenceConfiguration = broPersistenceConfiguration;
+ this.BrokerId = brokerId;
+ this.MasterServers = masters;
+ this.SlaveServers = slaves;
+ this.Proxies = [];
+ }
+
+ public BrokerConfiguration(IEnvironmentConfigurationSource config):this(
+ ApiEnvironmentPersistenceConfigurationParser.Parse(config),
+ EnvironmentPersistenceConfigurationParser.Parse(config),
+ config.GetValue(Constants.EnvironmentVariables.BROKER_ID),
+ MasterServerParser.Parse(config.GetValue(Constants.EnvironmentVariables.MASTER_SERVERS)),
+ SlaveServerParser.Parse(config.GetValue(Constants.EnvironmentVariables.SLAVE_SERVERS)))
+ {
+ }
+ }
+}
\ No newline at end of file
diff --git a/code/MessengerBroker.Configuration/Model/Servers/Base/Server.cs b/code/MessengerBroker.Configuration/Model/Servers/Base/Server.cs
new file mode 100644
index 0000000..900a369
--- /dev/null
+++ b/code/MessengerBroker.Configuration/Model/Servers/Base/Server.cs
@@ -0,0 +1,9 @@
+namespace MessengerBroker.Configuration.Model.Servers.Base
+{
+ public class Server
+ {
+ public Guid BrokerId { get; set; }
+
+ public string Name { get; set; }
+ }
+}
diff --git a/code/MessengerBroker.Configuration/Model/Servers/MasterServer.cs b/code/MessengerBroker.Configuration/Model/Servers/MasterServer.cs
new file mode 100644
index 0000000..3cc650a
--- /dev/null
+++ b/code/MessengerBroker.Configuration/Model/Servers/MasterServer.cs
@@ -0,0 +1,15 @@
+using MessengerBroker.Configuration.Model.Servers.Base;
+
+namespace MessengerBroker.Configuration.Model.Servers
+{
+ ///
+ /// Server that we have to pull data from and provide alternate service for.
+ ///
+ public class MasterServer : Server
+ {
+ ///
+ /// Url of the Broker API we use to download the data.
+ ///
+ public string BrokerUrl { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/code/MessengerBroker.Configuration/Model/Servers/SlaveServer.cs b/code/MessengerBroker.Configuration/Model/Servers/SlaveServer.cs
new file mode 100644
index 0000000..4a80029
--- /dev/null
+++ b/code/MessengerBroker.Configuration/Model/Servers/SlaveServer.cs
@@ -0,0 +1,11 @@
+using MessengerBroker.Configuration.Model.Servers.Base;
+
+namespace MessengerBroker.Configuration.Model.Servers
+{
+ ///
+ /// Server that is pulling data from us and has to provide alternate service for us.
+ ///
+ public class SlaveServer : Server
+ {
+ }
+}
\ No newline at end of file
diff --git a/code/MessengerBroker.Configuration/Parsers/ApiEnvironmentPersistenceConfigurationParser.cs b/code/MessengerBroker.Configuration/Parsers/ApiEnvironmentPersistenceConfigurationParser.cs
new file mode 100644
index 0000000..95dcff6
--- /dev/null
+++ b/code/MessengerBroker.Configuration/Parsers/ApiEnvironmentPersistenceConfigurationParser.cs
@@ -0,0 +1,27 @@
+using MessengerApi.Configuration.Model.Persistence;
+using MessengerApi.Configuration.Model.Persistence.Base;
+using MessengerApi.Configuration.Parsers;
+using MessengerApi.Configuration.Sources.Environment;
+using MessengerBroker.Configuration.Sources.Environment;
+
+namespace MessengerBroker.Configuration.Parsers
+{
+ public class ApiEnvironmentPersistenceConfigurationParser
+ {
+ public static PersistenceConfiguration Parse(IEnvironmentConfigurationSource config)
+ {
+ var type = PersistenceTypeParser.Parse(config.GetValue(Constants.EnvironmentVariables.API_PERSISTENCE_TYPE));
+
+ if (type == MessengerApi.Configuration.Enums.PersistenceTypes.Sql)
+ {
+ return new SqlPersistenceConfiguration(config);
+ }
+ else if (type == MessengerApi.Configuration.Enums.PersistenceTypes.PostgreSql)
+ {
+ return new NpgPersistenceConfiguration(config);
+ }
+
+ throw new InvalidOperationException("Unrecognized persistence type.");
+ }
+ }
+}
\ No newline at end of file
diff --git a/code/MessengerBroker.Configuration/Parsers/MasterServerParser.cs b/code/MessengerBroker.Configuration/Parsers/MasterServerParser.cs
new file mode 100644
index 0000000..d8044ca
--- /dev/null
+++ b/code/MessengerBroker.Configuration/Parsers/MasterServerParser.cs
@@ -0,0 +1,27 @@
+using MessengerBroker.Configuration.Model.Servers;
+
+namespace MessengerBroker.Configuration.Parsers
+{
+ public class MasterServerParser
+ {
+ public static MasterServer[] Parse(string value)
+ {
+ var servers = new List();
+ var values = value.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
+
+ foreach(var v in values)
+ {
+ var props = v.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
+
+ servers.Add(new MasterServer
+ {
+ BrokerId = Guid.Parse(props[0]),
+ BrokerUrl = props[1],
+ Name = props[2]
+ });
+ }
+
+ return servers.ToArray();
+ }
+ }
+}
diff --git a/code/MessengerBroker.Configuration/Parsers/SlaveServerParser.cs b/code/MessengerBroker.Configuration/Parsers/SlaveServerParser.cs
new file mode 100644
index 0000000..23761ba
--- /dev/null
+++ b/code/MessengerBroker.Configuration/Parsers/SlaveServerParser.cs
@@ -0,0 +1,26 @@
+using MessengerBroker.Configuration.Model.Servers;
+
+namespace MessengerBroker.Configuration.Parsers
+{
+ public static class SlaveServerParser
+ {
+ public static SlaveServer[] Parse(string value)
+ {
+ var servers = new List();
+ var values = value.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
+
+ foreach (var v in values)
+ {
+ var props = v.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
+
+ servers.Add(new SlaveServer
+ {
+ BrokerId = Guid.Parse(props[0]),
+ Name = props[1]
+ });
+ }
+
+ return servers.ToArray();
+ }
+ }
+}
diff --git a/code/MessengerBroker.Configuration/Sources/Environment/Constants.EnvironmentVariables.cs b/code/MessengerBroker.Configuration/Sources/Environment/Constants.EnvironmentVariables.cs
new file mode 100644
index 0000000..6d76f51
--- /dev/null
+++ b/code/MessengerBroker.Configuration/Sources/Environment/Constants.EnvironmentVariables.cs
@@ -0,0 +1,16 @@
+
+namespace MessengerBroker.Configuration.Sources.Environment
+{
+ public class Constants
+ {
+ public static class EnvironmentVariables
+ {
+ public const string API_PERSISTENCE_TYPE = nameof(API_PERSISTENCE_TYPE);
+ public const string API_SQL_CONNECTIONSTRING = nameof(API_SQL_CONNECTIONSTRING);
+ public const string API_NPG_CONNECTIONSTRING = nameof(API_NPG_CONNECTIONSTRING);
+ public const string BROKER_ID = nameof(BROKER_ID);
+ public const string MASTER_SERVERS = nameof(MASTER_SERVERS);
+ public const string SLAVE_SERVERS = nameof(SLAVE_SERVERS);
+ }
+ }
+}