Commit dfd16aa5 authored by mohammad.salama's avatar mohammad.salama

Added Some Appsetting Parsing

parent a6fe4b3e
...@@ -22,7 +22,7 @@ public class Program ...@@ -22,7 +22,7 @@ public class Program
builder.Services.AddDiscoveryClient(builder.Configuration); builder.Services.AddDiscoveryClient(builder.Configuration);
const string serviceName = "http_2-protocol-node"; const string serviceName = "http_2-protocol-node";
builder.Logging.AddOpenTelemetry(options => /*builder.Logging.AddOpenTelemetry(options =>
{ {
options options
.SetResourceBuilder( .SetResourceBuilder(
...@@ -30,7 +30,7 @@ public class Program ...@@ -30,7 +30,7 @@ public class Program
.AddService(serviceName)) .AddService(serviceName))
.AddConsoleExporter(); .AddConsoleExporter();
}); });*/
builder.Services.AddOpenTelemetry() builder.Services.AddOpenTelemetry()
......
...@@ -57,3 +57,4 @@ ...@@ -57,3 +57,4 @@
2.0 2.0
2.0 2.0
2.0 2.0
2.0
...@@ -18,7 +18,7 @@ namespace HTTPMessageNode.Controllers ...@@ -18,7 +18,7 @@ namespace HTTPMessageNode.Controllers
private static readonly string ErrorValidation = "Error When Validating Request"; private static readonly string ErrorValidation = "Error When Validating Request";
private static readonly string ErrorGRPCConnection = "Error Connecting to GRPC Servers"; private static readonly string ErrorGRPCConnection = "Error Connecting to GRPC Servers";
public QueueMessageController(ILogger<QueueMessageController> logger , IDiscoveryClient discovery, IConfiguration configuration) public QueueMessageController(ILogger<QueueMessageController> logger , IDiscoveryClient discovery)
{ {
_logger = logger; _logger = logger;
discoveryClient = discovery; discoveryClient = discovery;
......
...@@ -29,3 +29,4 @@ ...@@ -29,3 +29,4 @@
2.0 2.0
2.0 2.0
2.0 2.0
2.0
...@@ -35,6 +35,8 @@ namespace GGRPCMessageGenerator ...@@ -35,6 +35,8 @@ namespace GGRPCMessageGenerator
message.MsgId = "msg-id=1"; message.MsgId = "msg-id=1";
message.PhoneNumber = "043 33 00 83"; message.PhoneNumber = "043 33 00 83";
message.Tag = "SYR"; message.Tag = "SYR";
message.Minute = message.Hour = message.Day = message.Month = message.Year = 0;
Console.WriteLine("Sending to " + address); Console.WriteLine("Sending to " + address);
......
...@@ -10,6 +10,7 @@ D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\PriorityStr ...@@ -10,6 +10,7 @@ D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\PriorityStr
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\PriorityStream\bin\Debug\net6.0\Pipelines.Sockets.Unofficial.dll D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\PriorityStream\bin\Debug\net6.0\Pipelines.Sockets.Unofficial.dll
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\PriorityStream\bin\Debug\net6.0\StackExchange.Redis.dll D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\PriorityStream\bin\Debug\net6.0\StackExchange.Redis.dll
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\PriorityStream\bin\Debug\net6.0\System.IO.Pipelines.dll D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\PriorityStream\bin\Debug\net6.0\System.IO.Pipelines.dll
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\PriorityStream\obj\Debug\net6.0\PriorityStream.csproj.AssemblyReference.cache
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\PriorityStream\obj\Debug\net6.0\PriorityStream.GeneratedMSBuildEditorConfig.editorconfig D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\PriorityStream\obj\Debug\net6.0\PriorityStream.GeneratedMSBuildEditorConfig.editorconfig
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\PriorityStream\obj\Debug\net6.0\PriorityStream.AssemblyInfoInputs.cache D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\PriorityStream\obj\Debug\net6.0\PriorityStream.AssemblyInfoInputs.cache
D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\PriorityStream\obj\Debug\net6.0\PriorityStream.AssemblyInfo.cs D:\HIAST\FIY\Project-MSGPriorityQ\GrpcMessage\message-priority-queue\PriorityStream\obj\Debug\net6.0\PriorityStream.AssemblyInfo.cs
......
namespace Scheduler.Initializer
{
public class Initializer
{
public static void init(ref IConfiguration conf)
{
MessagesMongoDBParser.setAccountsDB(ref conf);
ServiceNameParser.setServiceName(ref conf);
RedisInfoParser.setInfo(ref conf);
}
}
}
namespace Scheduler.Initializer
{
public class MessagesMongoDBParser
{
public static string connection = "";
public static string database = "";
public static string collection = "";
public static void setAccountsDB(ref IConfiguration config)
{
string? conn = config.GetSection("MessageStorage").GetSection("Mongo").Value;
string? namedb = config.GetSection("MessageStorage").GetSection("DBName").Value;
string? colldb = config.GetSection("MessageStorage").GetSection("collection").Value;
if (conn == null || namedb == null || colldb == null)
{
throw new ArgumentException("Messages MongoDB DataBase Full Information (DBName + Collection + Not Defined in appsettings.json");
}
connection = conn;
database = namedb;
collection = colldb;
}
}
}
namespace Scheduler.Initializer
{
public class RedisInfoParser
{
public static string connection = "";
public static string MTN = "";
public static string Syriatel = "";
public static int LEVELS = 0;
public static void setInfo(ref IConfiguration config)
{
string? conn = config.GetSection("RedisInfo").GetSection("Connection").Value;
string? provs = config.GetSection("RedisInfo").GetSection("Providors").Value;
string? lvls = config.GetSection("RedisInfo").GetSection("Levels").Value;
if (conn == null || provs == null || lvls == null )
{
throw new ArgumentException("Redis Full Info (connection + providers + levels) Not Defined in appsettings.json");
}
connection = conn;
LEVELS = int.Parse(lvls);
string[] temp = provs.Split(',');
Syriatel = temp[0];
MTN = temp[1];
}
}
}
using Microsoft.Extensions.Options;
namespace Scheduler.Initializer
{
public class ServiceNameParser
{
public static string serviceName = "";
public static void setServiceName(ref IConfiguration config)
{
string? name = config.GetSection("OpenTelemetry").GetSection("ServiceName").Value;
if (name == null)
{
throw new ArgumentException("Service Name Not Defined in appsettings.json");
}
serviceName = name;
}
}
}
...@@ -6,6 +6,8 @@ using OpenTelemetry.Logs; ...@@ -6,6 +6,8 @@ using OpenTelemetry.Logs;
using OpenTelemetry.Metrics; using OpenTelemetry.Metrics;
using OpenTelemetry.Resources; using OpenTelemetry.Resources;
using OpenTelemetry.Trace; using OpenTelemetry.Trace;
using Scheduler.Initializer;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Additional configuration is required to successfully run gRPC on macOS. // Additional configuration is required to successfully run gRPC on macOS.
...@@ -14,7 +16,8 @@ var builder = WebApplication.CreateBuilder(args); ...@@ -14,7 +16,8 @@ var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddGrpc(); builder.Services.AddGrpc();
builder.Services.AddDiscoveryClient(); builder.Services.AddDiscoveryClient();
IConfiguration config = builder.Configuration;
Initializer.init(ref config);
MessageQueues.init(); MessageQueues.init();
MongoMessagesShceduler.init(); MongoMessagesShceduler.init();
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
}, },
"OpenTelemetry": { "OpenTelemetry": {
"ServiceName": "Scheduler-1",
"Tracing": { "Tracing": {
"Exporter": { "Exporter": {
"Jaeger": { "Jaeger": {
...@@ -35,5 +36,16 @@ ...@@ -35,5 +36,16 @@
} }
} }
} }
},
"RedisInfo": {
"Connection": "localhost:63790",
"Providors": "SYR,MTN",
"Levels": "6"
},
"MessageStorage": {
"Mongo": "mongodb://127.0.0.1:27017",
"DBName": "scheduled-messages",
"collection": "messages"
} }
} }
\ No newline at end of file
...@@ -53,3 +53,4 @@ ...@@ -53,3 +53,4 @@
2.0 2.0
2.0 2.0
2.0 2.0
2.0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ScheduledMessagesHandler
{
public static class RedisInitializeExtentions
{
//Extention methods
public static IHost InitRedis(this IHost host)
{
return host;
}
}
}
namespace ScheduledMessagesHandler.Initializer
{
public class Initializer
{
public static void init(ref IConfiguration conf)
{
RedisInfoParser.setInfo(ref conf);
}
}
}
namespace ScheduledMessagesHandler.Initializer
{
public class RedisInfoParser
{
public static string connection = "";
public static string MTN = "";
public static string Syriatel = "";
public static int LEVELS = 0;
public static void setInfo(ref IConfiguration config)
{
string? conn = config.GetSection("RedisInfo").GetSection("Connection").Value;
string? provs = config.GetSection("RedisInfo").GetSection("Providors").Value;
string? lvls = config.GetSection("RedisInfo").GetSection("Levels").Value;
if (conn == null || provs == null || lvls == null )
{
throw new ArgumentException("Redis Full Info (connection + providers + levels) Not Defined in appsettings.json");
}
connection = conn;
LEVELS = int.Parse(lvls);
string[] temp = provs.Split(',');
Syriatel = temp[0];
MTN = temp[1];
}
}
}
using ScheduledMessagesHandler; using ScheduledMessagesHandler;
using ScheduledMessagesHandler.Initializer;
using ScheduledMessagesHandler.MongoMessages; using ScheduledMessagesHandler.MongoMessages;
using ScheduledMessagesHandler.RedisQueuer; using ScheduledMessagesHandler.RedisQueuer;
using Steeltoe.Discovery.Client; using Steeltoe.Discovery.Client;
...@@ -15,9 +16,9 @@ IHost host = Host.CreateDefaultBuilder(args) ...@@ -15,9 +16,9 @@ IHost host = Host.CreateDefaultBuilder(args)
.Build(); .Build();
config = host.Services.GetRequiredService<IConfiguration>(); config = host.Services.GetRequiredService<IConfiguration>();
Initializer.init(ref config);
//host.InitRedis();
host.InitRedis();
MessageQueues.init(); MessageQueues.init();
MongoMessagesShceduler.init(); MongoMessagesShceduler.init();
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ScheduledMessagesHandler
{
public class RedisInitializationService : BackgroundService
{
protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
throw new NotImplementedException();
}
}
}
...@@ -4,5 +4,10 @@ ...@@ -4,5 +4,10 @@
"Default": "Information", "Default": "Information",
"Microsoft.Hosting.Lifetime": "Information" "Microsoft.Hosting.Lifetime": "Information"
} }
},
"RedisInfo": {
"Connection": "localhost:63790",
"Providors": "SYR,MTN",
"Levels": "6"
} }
} }
namespace Validator.Initializer
{
public class AccountsDBParser
{
public static string connection = "";
public static void setAccountsDB(ref IConfiguration config)
{
string? conn = config.GetSection("AccountsDB").GetSection("Mongo").Value;
if (conn == null)
{
throw new ArgumentException("Accounts MongoDB DataBase Not Defined in appsettings.json");
}
connection = conn;
}
}
}
namespace Validator.Initializer
{
public class Initializer
{
public static void init(ref IConfiguration conf)
{
AccountsDBParser.setAccountsDB(ref conf);
ServiceNameParser.setServiceName(ref conf);
}
}
}
using Microsoft.Extensions.Options;
namespace Validator.Initializer
{
public class ServiceNameParser
{
public static string serviceName = "";
public static void setServiceName(ref IConfiguration config)
{
string? name = config.GetSection("OpenTelemetry").GetSection("ServiceName").Value;
if (name == null)
{
throw new ArgumentException("Service Name Not Defined in appsettings.json");
}
serviceName = name;
}
}
}
...@@ -4,6 +4,8 @@ using OpenTelemetry.Logs; ...@@ -4,6 +4,8 @@ using OpenTelemetry.Logs;
using OpenTelemetry.Metrics; using OpenTelemetry.Metrics;
using OpenTelemetry.Resources; using OpenTelemetry.Resources;
using OpenTelemetry.Trace; using OpenTelemetry.Trace;
using Validator.Initializer;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Additional configuration is required to successfully run gRPC on macOS. // Additional configuration is required to successfully run gRPC on macOS.
...@@ -12,19 +14,11 @@ var builder = WebApplication.CreateBuilder(args); ...@@ -12,19 +14,11 @@ var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddGrpc(); builder.Services.AddGrpc();
builder.Services.AddDiscoveryClient(); builder.Services.AddDiscoveryClient();
const string serviceName = "Vaidator-1"; IConfiguration config = builder.Configuration;
/* Initializer.init(ref config);
builder.Logging.AddOpenTelemetry(options =>
{ string serviceName = ServiceNameParser.serviceName;
options
.SetResourceBuilder(
ResourceBuilder.CreateDefault()
.AddService(serviceName))
.AddConsoleExporter();
});
*/
builder.Services.AddOpenTelemetry() builder.Services.AddOpenTelemetry()
.ConfigureResource(resource => resource.AddService(serviceName)) .ConfigureResource(resource => resource.AddService(serviceName))
.WithTracing(tracing => tracing .WithTracing(tracing => tracing
...@@ -36,10 +30,13 @@ builder.Services.AddOpenTelemetry() ...@@ -36,10 +30,13 @@ builder.Services.AddOpenTelemetry()
.AddAspNetCoreInstrumentation() .AddAspNetCoreInstrumentation()
); );
var app = builder.Build(); var app = builder.Build();
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
app.MapGrpcService<ValidatorService>(); app.MapGrpcService<ValidatorService>();
app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909"); app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
app.Run(); app.Run();
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
} }
}, },
"OpenTelemetry": { "OpenTelemetry": {
"ServiceName": "Validator-1",
"Tracing": { "Tracing": {
"Exporter": { "Exporter": {
"Jaeger": { "Jaeger": {
...@@ -33,5 +34,8 @@ ...@@ -33,5 +34,8 @@
} }
} }
} }
},
"AccountsDB": {
"Mongo" : "localhost:6565"
} }
} }
...@@ -33,5 +33,9 @@ ...@@ -33,5 +33,9 @@
} }
} }
} }
},
"ServiceName": "Validator-1",
"AccountsDB": {
"Mongo" : "localhost:6565"
} }
} }
17e9ce3c0a03f6bd4933c1b6269ec3b7fb11fb47 04eda466c4608d02cd054cc7f851d695ec425e99
...@@ -12,3 +12,7 @@ ...@@ -12,3 +12,7 @@
2.0 2.0
2.0 2.0
2.0 2.0
2.0
2.0
2.0
2.0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment