diff --git a/.NET Microservices.postman_collection.json b/.NET Microservices.postman_collection.json new file mode 100644 index 0000000..148c168 --- /dev/null +++ b/.NET Microservices.postman_collection.json @@ -0,0 +1,296 @@ +{ + "info": { + "_postman_id": "ee354e59-5eaa-4b1d-a8b9-2a1365f39fff", + "name": ".NET Microservices", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "11229835" + }, + "item": [ + { + "name": "Platform Service", + "item": [ + { + "name": "Ingress Nginx", + "item": [ + { + "name": "Get Platforms", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://acme.com/api/platforms", + "protocol": "http", + "host": [ + "acme", + "com" + ], + "path": [ + "api", + "platforms" + ] + } + }, + "response": [] + }, + { + "name": "Get Platform By Id", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://acme.com/api/platforms/:id", + "protocol": "http", + "host": [ + "acme", + "com" + ], + "path": [ + "api", + "platforms", + ":id" + ], + "variable": [ + { + "key": "id", + "value": "5" + } + ] + } + }, + "response": [] + }, + { + "name": "Create Platform", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"name\": \"Consul\",\r\n \"publisher\": \"Hashicrop\",\r\n \"cost\": \"Free\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://acme.com/api/platforms", + "protocol": "http", + "host": [ + "acme", + "com" + ], + "path": [ + "api", + "platforms" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Node Port", + "item": [ + { + "name": "Get Platforms", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:30232/api/platforms", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "30232", + "path": [ + "api", + "platforms" + ] + } + }, + "response": [] + }, + { + "name": "Get Platform By Id", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:30232/api/platforms/:id", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "30232", + "path": [ + "api", + "platforms", + ":id" + ], + "variable": [ + { + "key": "id", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Create Platform", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"name\": \"Vagrant\",\r\n \"publisher\": \"Hashicrop\",\r\n \"cost\": \"Free\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://localhost:30232/api/platforms", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "30232", + "path": [ + "api", + "platforms" + ] + } + }, + "response": [] + } + ] + } + ] + }, + { + "name": "Command Service", + "item": [ + { + "name": "Ingress Nginx", + "item": [ + { + "name": "Get Platforms", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://acme.com/api/c/platforms", + "protocol": "http", + "host": [ + "acme", + "com" + ], + "path": [ + "api", + "c", + "platforms" + ] + } + }, + "response": [] + }, + { + "name": "Get Commands for Platform", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://acme.com/api/c/platforms/:platformId/commands", + "protocol": "http", + "host": [ + "acme", + "com" + ], + "path": [ + "api", + "c", + "platforms", + ":platformId", + "commands" + ], + "variable": [ + { + "key": "platformId", + "value": "" + } + ] + } + }, + "response": [] + }, + { + "name": "Create Command for Platform", + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\r\n \"HowTo\": \"This is the how-to\",\r\n \"CommandLine\": \"This is the command line\"\r\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "http://acme.com/api/c/platforms/:platformId/commands", + "protocol": "http", + "host": [ + "acme", + "com" + ], + "path": [ + "api", + "c", + "platforms", + ":platformId", + "commands" + ], + "variable": [ + { + "key": "platformId", + "value": "5" + } + ] + } + }, + "response": [] + }, + { + "name": "Create Platform", + "request": { + "method": "POST", + "header": [], + "url": { + "raw": "http://acme.com/api/c/platforms", + "protocol": "http", + "host": [ + "acme", + "com" + ], + "path": [ + "api", + "c", + "platforms" + ] + } + }, + "response": [] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/CommandsService/.dockerignore b/CommandsService/.dockerignore new file mode 100644 index 0000000..51717a8 --- /dev/null +++ b/CommandsService/.dockerignore @@ -0,0 +1,3 @@ +Dockerfile +[b|B]in +[O|o]bj \ No newline at end of file diff --git a/CommandsService/AsyncDataServices/MessageBusSubscriber.cs b/CommandsService/AsyncDataServices/MessageBusSubscriber.cs index 9cde0b2..e6c51eb 100644 --- a/CommandsService/AsyncDataServices/MessageBusSubscriber.cs +++ b/CommandsService/AsyncDataServices/MessageBusSubscriber.cs @@ -1,12 +1,8 @@ -using System; -using System.Text; -using System.Threading; -using System.Threading.Tasks; + using CommandsService.EventProcessing; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; using RabbitMQ.Client; using RabbitMQ.Client.Events; +using System.Text; namespace CommandsService.AsyncDataServices { @@ -14,44 +10,70 @@ public class MessageBusSubscriber : BackgroundService { private readonly IConfiguration _configuration; private readonly IEventProcessor _eventProcessor; - private IConnection _connection; - private IModel _channel; - private string _queueName; - public MessageBusSubscriber( - IConfiguration configuration, - IEventProcessor eventProcessor) + public MessageBusSubscriber(IConfiguration configuration, IEventProcessor eventProcessor) { _configuration = configuration; _eventProcessor = eventProcessor; - - InitializeRabbitMQ(); } - private void InitializeRabbitMQ() + private IConnection? _connection; + private IChannel? _channel; + private string _queueName; + + private async Task InitializeRabbitMQ() { - var factory = new ConnectionFactory() { HostName = _configuration["RabbitMQHost"], Port = int.Parse(_configuration["RabbitMQPort"])}; + if (_connection != null) + { + return; + } + + var factory = new ConnectionFactory() + { + HostName = _configuration["RabbitMQHost"], + Port = int.Parse(_configuration["RabbitMQPort"]) + }; + + try + { + _connection = await factory.CreateConnectionAsync(); + _channel = await _connection.CreateChannelAsync(); + + await _channel.ExchangeDeclareAsync("trigger", ExchangeType.Fanout); + + var _queue = await _channel.QueueDeclareAsync(); + _queueName = _queue.QueueName; - _connection = factory.CreateConnection(); - _channel = _connection.CreateModel(); - _channel.ExchangeDeclare(exchange: "trigger", type: ExchangeType.Fanout); - _queueName = _channel.QueueDeclare().QueueName; - _channel.QueueBind(queue: _queueName, - exchange: "trigger", - routingKey: ""); + await _channel.QueueBindAsync( + queue: _queueName, + exchange: "trigger", + routingKey: string.Empty + ); - Console.WriteLine("--> Listenting on the Message Bus..."); + _connection.ConnectionShutdownAsync += RabbitMQ_ConnectionShutdownAsync; - _connection.ConnectionShutdown += RabbitMQ_ConnectionShitdown; + Console.WriteLine("--> Listening on the Message Bus"); + } + catch (Exception ex) + { + Console.WriteLine($"--> Could not connect to the Message Bus: {ex.Message}"); + } + } + + private async Task RabbitMQ_ConnectionShutdownAsync(object sender, ShutdownEventArgs e) + { + Console.WriteLine("--> RabbitMQ Connection Shutdown"); } - protected override Task ExecuteAsync(CancellationToken stoppingToken) + protected override async Task ExecuteAsync(CancellationToken stoppingToken) { + await InitializeRabbitMQ(); + stoppingToken.ThrowIfCancellationRequested(); - var consumer = new EventingBasicConsumer(_channel); + var consumer = new AsyncEventingBasicConsumer(_channel); - consumer.Received += (ModuleHandle, ea) => + consumer.ReceivedAsync += async (ModuleHandle, ea) => { Console.WriteLine("--> Event Received!"); @@ -61,25 +83,29 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) _eventProcessor.ProcessEvent(notificationMessage); }; - _channel.BasicConsume(queue: _queueName, autoAck: true, consumer: consumer); - - return Task.CompletedTask; - } - - private void RabbitMQ_ConnectionShitdown(object sender, ShutdownEventArgs e) - { - Console.WriteLine("--> Connection Shutdown"); + await _channel.BasicConsumeAsync( + queue: _queueName, + autoAck: true, + consumer: consumer + ); } public override void Dispose() { - if(_channel.IsOpen) + if (_channel != null && _channel.IsOpen) { - _channel.Close(); - _connection.Close(); + _channel.CloseAsync(); } - base.Dispose(); + if (_connection != null && _connection.IsOpen) + { + _connection.CloseAsync(); + } + + _connection = null; + _channel = null; + + GC.SuppressFinalize(this); } } -} \ No newline at end of file +} diff --git a/CommandsService/CommandsService.csproj b/CommandsService/CommandsService.csproj index 0b816e3..864ee19 100644 --- a/CommandsService/CommandsService.csproj +++ b/CommandsService/CommandsService.csproj @@ -1,25 +1,28 @@ - net5.0 + net8.0 + enable + enable - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + diff --git a/CommandsService/Controllers/CommandsController.cs b/CommandsService/Controllers/CommandsController.cs index 0d3c8ec..b483dd7 100644 --- a/CommandsService/Controllers/CommandsController.cs +++ b/CommandsService/Controllers/CommandsController.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using AutoMapper; +using AutoMapper; using CommandsService.Data; using CommandsService.Dtos; using CommandsService.Models; @@ -26,7 +24,7 @@ public ActionResult> GetCommandsForPlatform(int plat { Console.WriteLine($"--> Hit GetCommandsForPlatform: {platformId}"); - if (!_repository.PlaformExits(platformId)) + if (_repository.PlatformExist(platformId) == false) { return NotFound(); } @@ -41,14 +39,14 @@ public ActionResult GetCommandForPlatform(int platformId, int co { Console.WriteLine($"--> Hit GetCommandForPlatform: {platformId} / {commandId}"); - if (!_repository.PlaformExits(platformId)) + if (_repository.PlatformExist(platformId) == false) { return NotFound(); } var command = _repository.GetCommand(platformId, commandId); - if(command == null) + if (command == null) { return NotFound(); } @@ -59,9 +57,9 @@ public ActionResult GetCommandForPlatform(int platformId, int co [HttpPost] public ActionResult CreateCommandForPlatform(int platformId, CommandCreateDto commandDto) { - Console.WriteLine($"--> Hit CreateCommandForPlatform: {platformId}"); + Console.WriteLine($"--> Hit CreateCommandForPlatform: {platformId}"); - if (!_repository.PlaformExits(platformId)) + if (_repository.PlatformExist(platformId) == false) { return NotFound(); } @@ -73,9 +71,14 @@ public ActionResult CreateCommandForPlatform(int platformId, Com var commandReadDto = _mapper.Map(command); - return CreatedAtRoute(nameof(GetCommandForPlatform), - new {platformId = platformId, commandId = commandReadDto.Id}, commandReadDto); + return CreatedAtRoute( + nameof(GetCommandForPlatform), + new + { + platformId = platformId, + commandId = commandReadDto.Id + }, + commandReadDto); } - } -} \ No newline at end of file +} diff --git a/CommandsService/Controllers/PlatformsController.cs b/CommandsService/Controllers/PlatformsController.cs index 844e772..73b742b 100644 --- a/CommandsService/Controllers/PlatformsController.cs +++ b/CommandsService/Controllers/PlatformsController.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using AutoMapper; +using AutoMapper; using CommandsService.Data; using CommandsService.Dtos; using Microsoft.AspNetCore.Mvc; @@ -21,13 +19,13 @@ public PlatformsController(ICommandRepo repository, IMapper mapper) } [HttpGet] - public ActionResult> GetPlatforms() + public ActionResult> GetPlatforms() { Console.WriteLine("--> Getting Platforms from CommandsService"); var platformItems = _repository.GetAllPlatforms(); - return Ok(_mapper.Map>(platformItems)); + return Ok(_mapper.Map>(platformItems)); } [HttpPost] @@ -35,7 +33,7 @@ public ActionResult TestInboundConnection() { Console.WriteLine("--> Inbound POST # Command Service"); - return Ok("Inbound test of from Platforms Controler"); + return Ok("Inbound test of from Platforms Controller"); } } -} \ No newline at end of file +} diff --git a/CommandsService/Data/AppDbContext.cs b/CommandsService/Data/AppDbContext.cs index f64381d..47b7d1b 100644 --- a/CommandsService/Data/AppDbContext.cs +++ b/CommandsService/Data/AppDbContext.cs @@ -1,14 +1,11 @@ -using CommandsService.Models; +using CommandsService.Models; using Microsoft.EntityFrameworkCore; namespace CommandsService.Data { public class AppDbContext : DbContext { - public AppDbContext(DbContextOptions opt ) : base(opt) - { - - } + public AppDbContext(DbContextOptions opt) : base(opt) { } public DbSet Platforms { get; set; } public DbSet Commands { get; set; } @@ -18,14 +15,14 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder .Entity() .HasMany(p => p.Commands) - .WithOne(p=> p.Platform!) + .WithOne(p => p.Platform!) .HasForeignKey(p => p.PlatformId); modelBuilder .Entity() .HasOne(p => p.Platform) .WithMany(p => p.Commands) - .HasForeignKey(p =>p.PlatformId); + .HasForeignKey(p => p.PlatformId); } } -} \ No newline at end of file +} diff --git a/CommandsService/Data/CommandRepo.cs b/CommandsService/Data/CommandRepo.cs index fab729c..c0dd2dc 100644 --- a/CommandsService/Data/CommandRepo.cs +++ b/CommandsService/Data/CommandRepo.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using CommandsService.Models; +using CommandsService.Models; namespace CommandsService.Data { @@ -27,10 +24,11 @@ public void CreateCommand(int platformId, Command command) public void CreatePlatform(Platform plat) { - if(plat == null) + if (plat == null) { throw new ArgumentNullException(nameof(plat)); } + _context.Platforms.Add(plat); } @@ -41,13 +39,14 @@ public bool ExternalPlatformExists(int externalPlatformId) public IEnumerable GetAllPlatforms() { - return _context.Platforms.ToList(); + return _context.Platforms; } public Command GetCommand(int platformId, int commandId) { return _context.Commands - .Where(c => c.PlatformId == platformId && c.Id == commandId).FirstOrDefault(); + .Where(c => c.PlatformId == platformId && c.Id == commandId) + .FirstOrDefault(); } public IEnumerable GetCommandsForPlatform(int platformId) @@ -57,7 +56,7 @@ public IEnumerable GetCommandsForPlatform(int platformId) .OrderBy(c => c.Platform.Name); } - public bool PlaformExits(int platformId) + public bool PlatformExist(int platformId) { return _context.Platforms.Any(p => p.Id == platformId); } @@ -67,4 +66,4 @@ public bool SaveChanges() return (_context.SaveChanges() >= 0); } } -} \ No newline at end of file +} diff --git a/CommandsService/Data/ICommandRepo.cs b/CommandsService/Data/ICommandRepo.cs index 7f4006f..aac2463 100644 --- a/CommandsService/Data/ICommandRepo.cs +++ b/CommandsService/Data/ICommandRepo.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using CommandsService.Models; +using CommandsService.Models; namespace CommandsService.Data { @@ -10,7 +9,7 @@ public interface ICommandRepo // Platforms IEnumerable GetAllPlatforms(); void CreatePlatform(Platform plat); - bool PlaformExits(int platformId); + bool PlatformExist(int platformId); bool ExternalPlatformExists(int externalPlatformId); // Commands @@ -18,4 +17,4 @@ public interface ICommandRepo Command GetCommand(int platformId, int commandId); void CreateCommand(int platformId, Command command); } -} \ No newline at end of file +} diff --git a/CommandsService/Data/PrepDb.cs b/CommandsService/Data/PrepDb.cs index 8cc0483..43b2068 100644 --- a/CommandsService/Data/PrepDb.cs +++ b/CommandsService/Data/PrepDb.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using CommandsService.Models; +using CommandsService.Models; using CommandsService.SyncDataServices.Grpc; -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; namespace CommandsService.Data { @@ -11,28 +7,28 @@ public static class PrepDb { public static void PrepPopulation(IApplicationBuilder applicationBuilder) { - using (var serviceScope = applicationBuilder.ApplicationServices.CreateScope()) - { - var grpcClient = serviceScope.ServiceProvider.GetService(); + using var serviceScope = applicationBuilder.ApplicationServices.CreateScope(); - var platforms = grpcClient.ReturnAllPlatforms(); + var grpcClient = serviceScope.ServiceProvider.GetService(); - SeedData(serviceScope.ServiceProvider.GetService(), platforms); - } + var platforms = grpcClient.ReturnAllPlatforms(); + + SeedData(serviceScope.ServiceProvider.GetService(), platforms); } - + private static void SeedData(ICommandRepo repo, IEnumerable platforms) { Console.WriteLine("Seeding new platforms..."); - foreach (var plat in platforms) + foreach (Platform plat in platforms) { - if(!repo.ExternalPlatformExists(plat.ExternalID)) + if (repo.ExternalPlatformExists(plat.ExternalID) == false) { repo.CreatePlatform(plat); } + repo.SaveChanges(); } } } -} \ No newline at end of file +} diff --git a/CommandsService/Dockerfile b/CommandsService/Dockerfile index cf20f7e..3088d66 100644 --- a/CommandsService/Dockerfile +++ b/CommandsService/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env WORKDIR /app COPY *.csproj ./ @@ -7,7 +7,7 @@ RUN dotnet restore COPY . ./ RUN dotnet publish -c Release -o out -FROM mcr.microsoft.com/dotnet/aspnet:5.0 +FROM mcr.microsoft.com/dotnet/aspnet:8.0 WORKDIR /app COPY --from=build-env /app/out . ENTRYPOINT [ "dotnet", "CommandsService.dll" ] \ No newline at end of file diff --git a/CommandsService/Dtos/CommandCreateDto.cs b/CommandsService/Dtos/CommandCreateDto.cs index 0b9fc7f..a9d0042 100644 --- a/CommandsService/Dtos/CommandCreateDto.cs +++ b/CommandsService/Dtos/CommandCreateDto.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace CommandsService.Dtos { @@ -10,4 +10,4 @@ public class CommandCreateDto [Required] public string CommandLine { get; set; } } -} \ No newline at end of file +} diff --git a/CommandsService/Dtos/CommandReadDto.cs b/CommandsService/Dtos/CommandReadDto.cs index d1f6a09..14485f6 100644 --- a/CommandsService/Dtos/CommandReadDto.cs +++ b/CommandsService/Dtos/CommandReadDto.cs @@ -1,4 +1,4 @@ -namespace CommandsService.Dtos +namespace CommandsService.Dtos { public class CommandReadDto { @@ -7,4 +7,4 @@ public class CommandReadDto public string CommandLine { get; set; } public int PlatformId { get; set; } } -} \ No newline at end of file +} diff --git a/CommandsService/Dtos/GenericEventDto.cs b/CommandsService/Dtos/GenericEventDto.cs index 886d8b0..6d43d06 100644 --- a/CommandsService/Dtos/GenericEventDto.cs +++ b/CommandsService/Dtos/GenericEventDto.cs @@ -1,7 +1,7 @@ -namespace CommandsService.Dtos +namespace CommandsService.Dtos { public class GenericEventDto { public string Event { get; set; } } -} \ No newline at end of file +} diff --git a/CommandsService/Dtos/PlatformPublishedDto.cs b/CommandsService/Dtos/PlatformPublishedDto.cs index 85ef3d6..a5a044a 100644 --- a/CommandsService/Dtos/PlatformPublishedDto.cs +++ b/CommandsService/Dtos/PlatformPublishedDto.cs @@ -1,4 +1,4 @@ -namespace CommandsService.Dtos +namespace CommandsService.Dtos { public class PlatformPublishedDto { @@ -6,4 +6,4 @@ public class PlatformPublishedDto public string Name { get; set; } public string Event { get; set; } } -} \ No newline at end of file +} diff --git a/CommandsService/Dtos/PlatformReadDto.cs b/CommandsService/Dtos/PlatformReadDto.cs index 0f93455..12215cc 100644 --- a/CommandsService/Dtos/PlatformReadDto.cs +++ b/CommandsService/Dtos/PlatformReadDto.cs @@ -1,8 +1,8 @@ -namespace CommandsService.Dtos +namespace CommandsService.Dtos { - public class PlatformreadDto + public class PlatformReadDto { public int Id { get; set; } public string Name { get; set; } } -} \ No newline at end of file +} diff --git a/CommandsService/EventProcessing/EventProcessor.cs b/CommandsService/EventProcessing/EventProcessor.cs index e0dcb5a..b0c864f 100644 --- a/CommandsService/EventProcessing/EventProcessor.cs +++ b/CommandsService/EventProcessing/EventProcessor.cs @@ -1,10 +1,8 @@ -using System; -using System.Text.Json; -using AutoMapper; +using AutoMapper; using CommandsService.Data; using CommandsService.Dtos; using CommandsService.Models; -using Microsoft.Extensions.DependencyInjection; +using System.Text.Json; namespace CommandsService.EventProcessing { @@ -13,7 +11,7 @@ public class EventProcessor : IEventProcessor private readonly IServiceScopeFactory _scopeFactory; private readonly IMapper _mapper; - public EventProcessor(IServiceScopeFactory scopeFactory, AutoMapper.IMapper mapper) + public EventProcessor(IServiceScopeFactory scopeFactory, IMapper mapper) { _scopeFactory = scopeFactory; _mapper = mapper; @@ -26,20 +24,20 @@ public void ProcessEvent(string message) switch (eventType) { case EventType.PlatformPublished: - addPlatform(message); + AddPlatform(message); break; default: break; } } - private EventType DetermineEvent(string notifcationMessage) + private EventType DetermineEvent(string notificationMessage) { Console.WriteLine("--> Determining Event"); - var eventType = JsonSerializer.Deserialize(notifcationMessage); + var eventType = JsonSerializer.Deserialize(notificationMessage); - switch(eventType.Event) + switch (eventType.Event) { case "Platform_Published": Console.WriteLine("--> Platform Published Event Detected"); @@ -50,40 +48,39 @@ private EventType DetermineEvent(string notifcationMessage) } } - private void addPlatform(string platformPublishedMessage) + private void AddPlatform(string platformPublishedMessage) { - using (var scope = _scopeFactory.CreateScope()) + using var scope = _scopeFactory.CreateScope(); + + var repo = scope.ServiceProvider.GetRequiredService(); + + var platformPublishedDto = JsonSerializer.Deserialize(platformPublishedMessage); + + try { - var repo = scope.ServiceProvider.GetRequiredService(); - - var platformPublishedDto = JsonSerializer.Deserialize(platformPublishedMessage); + var plat = _mapper.Map(platformPublishedDto); - try + if (repo.ExternalPlatformExists(plat.ExternalID) == false) { - var plat = _mapper.Map(platformPublishedDto); - if(!repo.ExternalPlatformExists(plat.ExternalID)) - { - repo.CreatePlatform(plat); - repo.SaveChanges(); - Console.WriteLine("--> Platform added!"); - } - else - { - Console.WriteLine("--> Platform already exisits..."); - } - + repo.CreatePlatform(plat); + repo.SaveChanges(); + Console.WriteLine("--> Platform added!"); } - catch (Exception ex) + else { - Console.WriteLine($"--> Could not add Platform to DB {ex.Message}"); + Console.WriteLine("--> Platform already exists..."); } } + catch (Exception ex) + { + Console.WriteLine($"--> Could not add Platform to DB: {ex.Message}"); + } } - } - enum EventType - { - PlatformPublished, - Undetermined + enum EventType + { + PlatformPublished, + Undetermined + } } } \ No newline at end of file diff --git a/CommandsService/EventProcessing/IEventProcessor.cs b/CommandsService/EventProcessing/IEventProcessor.cs index 4462067..d3a8b4c 100644 --- a/CommandsService/EventProcessing/IEventProcessor.cs +++ b/CommandsService/EventProcessing/IEventProcessor.cs @@ -1,7 +1,7 @@ -namespace CommandsService.EventProcessing +namespace CommandsService.EventProcessing { public interface IEventProcessor { void ProcessEvent(string message); } -} \ No newline at end of file +} diff --git a/CommandsService/Models/Command.cs b/CommandsService/Models/Command.cs index bd053f8..1d11c85 100644 --- a/CommandsService/Models/Command.cs +++ b/CommandsService/Models/Command.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace CommandsService.Models { @@ -17,6 +17,6 @@ public class Command [Required] public int PlatformId { get; set; } - public Platform Platform {get; set;} + public Platform Platform { get; set; } } -} \ No newline at end of file +} diff --git a/CommandsService/Models/Platform.cs b/CommandsService/Models/Platform.cs index f128503..723f179 100644 --- a/CommandsService/Models/Platform.cs +++ b/CommandsService/Models/Platform.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace CommandsService.Models { @@ -16,5 +15,5 @@ public class Platform public string Name { get; set; } public ICollection Commands { get; set; } = new List(); - } -} \ No newline at end of file + } +} diff --git a/CommandsService/Profiles/CommandsProfile.cs b/CommandsService/Profiles/CommandsProfile.cs index f529d41..9b933bb 100644 --- a/CommandsService/Profiles/CommandsProfile.cs +++ b/CommandsService/Profiles/CommandsProfile.cs @@ -1,7 +1,6 @@ -using AutoMapper; +using AutoMapper; using CommandsService.Dtos; using CommandsService.Models; -using PlatformService; namespace CommandsService.Profiles { @@ -10,7 +9,7 @@ public class CommandsProfile : Profile public CommandsProfile() { // Source -> Target - CreateMap(); + CreateMap(); CreateMap(); CreateMap(); CreateMap() @@ -21,4 +20,4 @@ public CommandsProfile() .ForMember(dest => dest.Commands, opt => opt.Ignore()); } } -} \ No newline at end of file +} diff --git a/CommandsService/Program.cs b/CommandsService/Program.cs index 9d554a2..743eb72 100644 --- a/CommandsService/Program.cs +++ b/CommandsService/Program.cs @@ -1,26 +1,40 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; - -namespace CommandsService +using CommandsService.AsyncDataServices; +using CommandsService.Data; +using CommandsService.EventProcessing; +using CommandsService.SyncDataServices.Grpc; +using Microsoft.EntityFrameworkCore; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddDbContext(opt => opt.UseInMemoryDatabase("InMem")); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddSingleton(); +builder.Services.AddControllers(); +builder.Services.AddHostedService(); +builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) { - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + app.UseSwagger(); + app.UseSwaggerUI(); } + +//We're not using HTTPS for this learning. Comment out so the warning is not triggered. +//app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +PrepDb.PrepPopulation(app); + +app.Run(); diff --git a/CommandsService/Properties/launchSettings.json b/CommandsService/Properties/launchSettings.json index d9f242f..f165333 100644 --- a/CommandsService/Properties/launchSettings.json +++ b/CommandsService/Properties/launchSettings.json @@ -4,25 +4,35 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:53729", - "sslPort": 44345 + "applicationUrl": "http://localhost:39073", + "sslPort": 44398 } }, "profiles": { - "IIS Express": { - "commandName": "IISExpress", + "http": { + "commandName": "Project", + "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", + "applicationUrl": "http://localhost:5082", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, - "CommandsService": { + "https": { "commandName": "Project", - "dotnetRunMessages": "true", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7180;http://localhost:5082", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "https://localhost:6001;http://localhost:6000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/CommandsService/Protos/platforms.proto b/CommandsService/Protos/platforms.proto index bf4a64c..c195530 100644 --- a/CommandsService/Protos/platforms.proto +++ b/CommandsService/Protos/platforms.proto @@ -1,19 +1,19 @@ syntax = "proto3"; -option csharp_namespace = "PlatformService"; +option csharp_namespace = "CommandsService"; service GrpcPlatform { - rpc GetAllPlatforms (GetAllRequest) returns (PlatformResponse); + rpc GetAllPlatforms (GetAllRequest) returns (PlatformResponse); } message GetAllRequest {} -message GrpcPlatformModel{ - int32 platformId = 1; - string name = 2; - string publisher = 3; +message GrpcPlatformModel { + int32 platformId = 1; + string name = 2; + string publisher = 3; } message PlatformResponse { - repeated GrpcPlatformModel platform = 1; -} \ No newline at end of file + repeated GrpcPlatformModel platform = 1; +} diff --git a/CommandsService/Startup.cs b/CommandsService/Startup.cs deleted file mode 100644 index 80dffcf..0000000 --- a/CommandsService/Startup.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using CommandsService.AsyncDataServices; -using CommandsService.Data; -using CommandsService.EventProcessing; -using CommandsService.SyncDataServices.Grpc; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.HttpsPolicy; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using Microsoft.OpenApi.Models; - -namespace CommandsService -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - - public void ConfigureServices(IServiceCollection services) - { - services.AddDbContext(opt => opt.UseInMemoryDatabase("InMen")); - services.AddScoped(); - services.AddControllers(); - - services.AddHostedService(); - - services.AddSingleton(); - services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); - services.AddScoped(); - services.AddSwaggerGen(c => - { - c.SwaggerDoc("v1", new OpenApiInfo { Title = "CommandsService", Version = "v1" }); - }); - } - - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "CommandsService v1")); - } - - //app.UseHttpsRedirection(); - - app.UseRouting(); - - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - }); - - PrepDb.PrepPopulation(app); - } - } -} diff --git a/CommandsService/SyncDataServices/Grpc/IPlatformDataClient.cs b/CommandsService/SyncDataServices/Grpc/IPlatformDataClient.cs index 74ca038..8967254 100644 --- a/CommandsService/SyncDataServices/Grpc/IPlatformDataClient.cs +++ b/CommandsService/SyncDataServices/Grpc/IPlatformDataClient.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using CommandsService.Models; +using CommandsService.Models; namespace CommandsService.SyncDataServices.Grpc { @@ -7,4 +6,4 @@ public interface IPlatformDataClient { IEnumerable ReturnAllPlatforms(); } -} \ No newline at end of file +} diff --git a/CommandsService/SyncDataServices/Grpc/PlatformDataClient.cs b/CommandsService/SyncDataServices/Grpc/PlatformDataClient.cs index bcf1b80..cc26eca 100644 --- a/CommandsService/SyncDataServices/Grpc/PlatformDataClient.cs +++ b/CommandsService/SyncDataServices/Grpc/PlatformDataClient.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using AutoMapper; +using AutoMapper; using CommandsService.Models; using Grpc.Net.Client; -using Microsoft.Extensions.Configuration; -using PlatformService; namespace CommandsService.SyncDataServices.Grpc { @@ -21,7 +17,8 @@ public PlatformDataClient(IConfiguration configuration, IMapper mapper) public IEnumerable ReturnAllPlatforms() { - Console.WriteLine($"--> Calling GRPC Service {_configuration["GrpcPlatform"]}"); + Console.WriteLine($"--> Calling gRPC Service {_configuration["GrpcPlatform"]}"); + var channel = GrpcChannel.ForAddress(_configuration["GrpcPlatform"]); var client = new GrpcPlatform.GrpcPlatformClient(channel); var request = new GetAllRequest(); @@ -33,7 +30,7 @@ public IEnumerable ReturnAllPlatforms() } catch (Exception ex) { - Console.WriteLine($"--> Couldnot call GRPC Server {ex.Message}"); + Console.WriteLine($"--> Could not call gRPC Server {ex.Message}"); return null; } } diff --git a/CommandsService/appsettings.Development.json b/CommandsService/appsettings.Development.json index c3b2693..cf4567b 100644 --- a/CommandsService/appsettings.Development.json +++ b/CommandsService/appsettings.Development.json @@ -2,11 +2,10 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Microsoft.AspNetCore": "Warning" } }, "RabbitMQHost": "localhost", "RabbitMQPort": "5672", - "GrpcPlatform" : "https://localhost:5001" -} \ No newline at end of file + "GrpcPlatform": "http://localhost:888" +} diff --git a/CommandsService/appsettings.Production.json b/CommandsService/appsettings.Production.json deleted file mode 100644 index fea160d..0000000 --- a/CommandsService/appsettings.Production.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "RabbitMQHost": "rabbitmq-clusterip-srv", - "RabbitMQPort": "5672", - "GrpcPlatform" : "http://platforms-clusterip-srv:666" -} \ No newline at end of file diff --git a/CommandsService/appsettings.json b/CommandsService/appsettings.json index d9d9a9b..7f31e53 100644 --- a/CommandsService/appsettings.json +++ b/CommandsService/appsettings.json @@ -2,9 +2,11 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "RabbitMQHost": "rabbitmq-clusterip-srv", + "RabbitMQPort": "5672", + "GrpcPlatform": "http://platforms-clusterip-srv:666" } diff --git a/K8S/commands-depl.yaml b/K8S/commands-depl.yaml index 5b499da..808662c 100644 --- a/K8S/commands-depl.yaml +++ b/K8S/commands-depl.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: commandservice - image: binarythistle/commandservice:latest + image: azizanhaniff/commandservice:latest --- apiVersion: v1 kind: Service @@ -27,5 +27,5 @@ spec: ports: - name: commandservice protocol: TCP - port: 80 - targetPort: 80 \ No newline at end of file + port: 8080 + targetPort: 8080 \ No newline at end of file diff --git a/K8S/ingress-srv.yaml b/K8S/ingress-srv.yaml index 6160857..9c4c557 100644 --- a/K8S/ingress-srv.yaml +++ b/K8S/ingress-srv.yaml @@ -16,13 +16,11 @@ spec: service: name: platforms-clusterip-srv port: - number: 80 + number: 8080 - path: /api/c/platforms pathType: Prefix backend: service: name: commands-clusterip-srv port: - number: 80 - - \ No newline at end of file + number: 8080 \ No newline at end of file diff --git a/K8S/local-pvc.yaml b/K8S/local-pvc.yaml index 29bd301..8252785 100644 --- a/K8S/local-pvc.yaml +++ b/K8S/local-pvc.yaml @@ -7,5 +7,4 @@ spec: - ReadWriteMany resources: requests: - storage: 200Mi - + storage: 200Mi \ No newline at end of file diff --git a/K8S/mssql-plat-depl.yaml b/K8S/mssql-plat-depl.yaml index e281d57..c813668 100644 --- a/K8S/mssql-plat-depl.yaml +++ b/K8S/mssql-plat-depl.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: mssql - image: mcr.microsoft.com/mssql/server:2017-latest + image: mcr.microsoft.com/mssql/server:2022-latest ports: - containerPort: 1433 env: @@ -22,11 +22,11 @@ spec: value: "Express" - name: ACCEPT_EULA value: "Y" - - name: SA_PASSWORD + - name: MSSQL_SA_PASSWORD valueFrom: secretKeyRef: name: mssql - key: SA_PASSWORD + key: MSSQL_SA_PASSWORD volumeMounts: - mountPath: /var/opt/mssql/data name: mssqldb @@ -52,7 +52,7 @@ spec: apiVersion: v1 kind: Service metadata: - name: mssql-loadbalancer + name: mssql-loadbalancer-srv spec: type: LoadBalancer selector: @@ -60,4 +60,4 @@ spec: ports: - protocol: TCP port: 1433 - targetPort: 1433 \ No newline at end of file + targetPort: 1433 diff --git a/K8S/platforms-depl.yaml b/K8S/platforms-depl.yaml index bc3a213..76fb4bc 100644 --- a/K8S/platforms-depl.yaml +++ b/K8S/platforms-depl.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: platformservice - image: binarythistle/platformservice:latest + image: azizanhaniff/platformservice:latest --- apiVersion: v1 kind: Service @@ -27,9 +27,9 @@ spec: ports: - name: platformservice protocol: TCP - port: 80 - targetPort: 80 - - name: plafromgrpc + port: 8080 + targetPort: 8080 + - name: platformgrpc protocol: TCP port: 666 targetPort: 666 \ No newline at end of file diff --git a/K8S/platforms-np-srv.yaml b/K8S/platforms-np-srv.yaml index 33a19ea..ae77e0f 100644 --- a/K8S/platforms-np-srv.yaml +++ b/K8S/platforms-np-srv.yaml @@ -9,5 +9,5 @@ spec: ports: - name: platformservice protocol: TCP - port: 80 - targetPort: 80 \ No newline at end of file + port: 8080 + targetPort: 8080 \ No newline at end of file diff --git a/K8S/rabbitmq-depl.yaml b/K8S/rabbitmq-depl.yaml index 7418ed6..eee0fb4 100644 --- a/K8S/rabbitmq-depl.yaml +++ b/K8S/rabbitmq-depl.yaml @@ -14,7 +14,7 @@ spec: spec: containers: - name: rabbitmq - image: rabbitmq:3-management + image: rabbitmq:4-management ports: - containerPort: 15672 name: rbmq-mgmt-port @@ -42,17 +42,17 @@ spec: apiVersion: v1 kind: Service metadata: - name: rabbitmq-loadbalancer + name: rabbitmq-loadbalancer-srv spec: type: LoadBalancer selector: app: rabbitmq ports: - - name: rbmq-mgmt-port + - name: rabbit-mgmt-port protocol: TCP port: 15672 targetPort: 15672 - - name: rbmq-msg-port + - name: rabbit-msg-port protocol: TCP port: 5672 - targetPort: 5672 \ No newline at end of file + targetPort: 5672 diff --git a/PlatformService/.dockerignore b/PlatformService/.dockerignore new file mode 100644 index 0000000..51717a8 --- /dev/null +++ b/PlatformService/.dockerignore @@ -0,0 +1,3 @@ +Dockerfile +[b|B]in +[O|o]bj \ No newline at end of file diff --git a/PlatformService/AsyncDataServices/IMessageBusClient.cs b/PlatformService/AsyncDataServices/IMessageBusClient.cs index af787cf..5ca0c43 100644 --- a/PlatformService/AsyncDataServices/IMessageBusClient.cs +++ b/PlatformService/AsyncDataServices/IMessageBusClient.cs @@ -1,9 +1,9 @@ -using PlatformService.Dtos; +using PlatformService.Dtos; namespace PlatformService.AsyncDataServices { public interface IMessageBusClient { - void PublishNewPlatform(PlatformPublishedDto platformPublishedDto); + Task PublishNewPlatformAsync(PlatformPublishedDto platformPublishedDto); } -} \ No newline at end of file +} diff --git a/PlatformService/AsyncDataServices/MessageBusClient.cs b/PlatformService/AsyncDataServices/MessageBusClient.cs index 1464e41..293194b 100644 --- a/PlatformService/AsyncDataServices/MessageBusClient.cs +++ b/PlatformService/AsyncDataServices/MessageBusClient.cs @@ -1,37 +1,46 @@ -using System; +using PlatformService.Dtos; +using RabbitMQ.Client; +using RabbitMQ.Client.Events; using System.Text; using System.Text.Json; -using Microsoft.Extensions.Configuration; -using PlatformService.Dtos; -using RabbitMQ.Client; namespace PlatformService.AsyncDataServices { - public class MessageBusClient : IMessageBusClient + public class MessageBusClient : IMessageBusClient, IDisposable { private readonly IConfiguration _configuration; - private readonly IConnection _connection; - private readonly IModel _channel; public MessageBusClient(IConfiguration configuration) { _configuration = configuration; + } + + private IConnection? _connection; + private IChannel? _channel; + + private async Task StartChannelAsync() + { + if (_connection != null) + { + return; + } + var factory = new ConnectionFactory() { HostName = _configuration["RabbitMQHost"], Port = int.Parse(_configuration["RabbitMQPort"]) }; + try { - _connection = factory.CreateConnection(); - _channel = _connection.CreateModel(); + _connection = await factory.CreateConnectionAsync(); + _channel = await _connection.CreateChannelAsync(); - _channel.ExchangeDeclare(exchange: "trigger", type: ExchangeType.Fanout); + await _channel.ExchangeDeclareAsync("trigger", ExchangeType.Fanout); - _connection.ConnectionShutdown += RabbitMQ_ConnectionShutdown; + _connection.ConnectionShutdownAsync += RabbitMQ_ConnectionShutdownAsync; Console.WriteLine("--> Connected to MessageBus"); - } catch (Exception ex) { @@ -39,45 +48,61 @@ public MessageBusClient(IConfiguration configuration) } } - public void PublishNewPlatform(PlatformPublishedDto platformPublishedDto) + private async Task RabbitMQ_ConnectionShutdownAsync(object sender, ShutdownEventArgs e) { + Console.WriteLine("--> RabbitMQ Connection Shutdown"); + } + + public async Task PublishNewPlatformAsync(PlatformPublishedDto platformPublishedDto) + { + await StartChannelAsync(); + var message = JsonSerializer.Serialize(platformPublishedDto); - if (_connection.IsOpen) + if (_connection != null && _connection.IsOpen) { - Console.WriteLine("--> RabbitMQ Connection Open, sending message..."); - SendMessage(message); + Console.WriteLine("--> RabbitMQ Connection open, sending message..."); + + // To do send the message + await SendMessageAsync(message); } else { - Console.WriteLine("--> RabbitMQ connectionis closed, not sending"); - } + Console.WriteLine("--> RabbitMQ Connection is closed, not sending"); + } } - private void SendMessage(string message) + private async Task SendMessageAsync(string message) { var body = Encoding.UTF8.GetBytes(message); - _channel.BasicPublish(exchange: "trigger", - routingKey: "", - basicProperties: null, - body: body); + await _channel.BasicPublishAsync( + exchange: "trigger", + routingKey: string.Empty, + body: body + ); + Console.WriteLine($"--> We have sent {message}"); } public void Dispose() { Console.WriteLine("MessageBus Disposed"); - if (_channel.IsOpen) + + if (_channel != null && _channel.IsOpen) { - _channel.Close(); - _connection.Close(); + _channel.CloseAsync(); } - } - private void RabbitMQ_ConnectionShutdown(object sender, ShutdownEventArgs e) - { - Console.WriteLine("--> RabbitMQ Connection Shutdown"); + if (_connection != null && _connection.IsOpen) + { + _connection.CloseAsync(); + } + + _connection = null; + _channel = null; + + GC.SuppressFinalize(this); } } -} \ No newline at end of file +} diff --git a/PlatformService/Controllers/PlatformsController.cs b/PlatformService/Controllers/PlatformsController.cs index 0697aa5..c98c647 100644 --- a/PlatformService/Controllers/PlatformsController.cs +++ b/PlatformService/Controllers/PlatformsController.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using AutoMapper; +using AutoMapper; using Microsoft.AspNetCore.Mvc; using PlatformService.AsyncDataServices; using PlatformService.Data; @@ -21,7 +18,7 @@ public class PlatformsController : ControllerBase private readonly IMessageBusClient _messageBusClient; public PlatformsController( - IPlatformRepo repository, + IPlatformRepo repository, IMapper mapper, ICommandDataClient commandDataClient, IMessageBusClient messageBusClient) @@ -68,24 +65,24 @@ public async Task> CreatePlatform(PlatformCreateDt { await _commandDataClient.SendPlatformToCommand(platformReadDto); } - catch(Exception ex) + catch (Exception ex) { Console.WriteLine($"--> Could not send synchronously: {ex.Message}"); } - //Send Async Message + // Send Async Message try { var platformPublishedDto = _mapper.Map(platformReadDto); platformPublishedDto.Event = "Platform_Published"; - _messageBusClient.PublishNewPlatform(platformPublishedDto); + await _messageBusClient.PublishNewPlatformAsync(platformPublishedDto); } catch (Exception ex) { Console.WriteLine($"--> Could not send asynchronously: {ex.Message}"); } - return CreatedAtRoute(nameof(GetPlatformById), new { Id = platformReadDto.Id}, platformReadDto); + return CreatedAtRoute(nameof(GetPlatformById), new { Id = platformReadDto.Id }, platformReadDto); } } -} \ No newline at end of file +} diff --git a/PlatformService/Data/AppDbContext.cs b/PlatformService/Data/AppDbContext.cs index df7231f..ceeb7f7 100644 --- a/PlatformService/Data/AppDbContext.cs +++ b/PlatformService/Data/AppDbContext.cs @@ -1,15 +1,12 @@ -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using PlatformService.Models; namespace PlatformService.Data { public class AppDbContext : DbContext { - public AppDbContext(DbContextOptions opt) : base(opt) - { - - } + public AppDbContext(DbContextOptions opt) : base(opt) { } public DbSet Platforms { get; set; } } -} \ No newline at end of file +} diff --git a/PlatformService/Data/IPlatformRepo.cs b/PlatformService/Data/IPlatformRepo.cs index d63485d..cc666e9 100644 --- a/PlatformService/Data/IPlatformRepo.cs +++ b/PlatformService/Data/IPlatformRepo.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using PlatformService.Models; +using PlatformService.Models; namespace PlatformService.Data { @@ -11,4 +10,4 @@ public interface IPlatformRepo Platform GetPlatformById(int id); void CreatePlatform(Platform plat); } -} \ No newline at end of file +} diff --git a/PlatformService/Data/PlatformRepo.cs b/PlatformService/Data/PlatformRepo.cs index 4156c91..beb3565 100644 --- a/PlatformService/Data/PlatformRepo.cs +++ b/PlatformService/Data/PlatformRepo.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using PlatformService.Models; +using PlatformService.Models; namespace PlatformService.Data { @@ -16,7 +13,7 @@ public PlatformRepo(AppDbContext context) public void CreatePlatform(Platform plat) { - if(plat == null) + if (plat == null) { throw new ArgumentNullException(nameof(plat)); } @@ -31,7 +28,7 @@ public IEnumerable GetAllPlatforms() public Platform GetPlatformById(int id) { - return _context.Platforms.FirstOrDefault(p => p.Id == id); + return _context.Platforms.FirstOrDefault(e => e.Id == id); } public bool SaveChanges() @@ -39,4 +36,4 @@ public bool SaveChanges() return (_context.SaveChanges() >= 0); } } -} \ No newline at end of file +} diff --git a/PlatformService/Data/PrepDb.cs b/PlatformService/Data/PrepDb.cs index ad6df2b..824b29a 100644 --- a/PlatformService/Data/PrepDb.cs +++ b/PlatformService/Data/PrepDb.cs @@ -1,45 +1,42 @@ -using System; -using System.Linq; -using Microsoft.AspNetCore.Builder; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; +using Microsoft.EntityFrameworkCore; using PlatformService.Models; namespace PlatformService.Data { + /// + /// Not for pushing into production. Just for local test purposes. + /// public static class PrepDb { public static void PrepPopulation(IApplicationBuilder app, bool isProd) { - using( var serviceScope = app.ApplicationServices.CreateScope()) - { - SeedData(serviceScope.ServiceProvider.GetService(), isProd); - } + using var serviceScope = app.ApplicationServices.CreateScope(); + SeedData(serviceScope.ServiceProvider.GetService(), isProd); } private static void SeedData(AppDbContext context, bool isProd) { - if(isProd) + if (isProd) { Console.WriteLine("--> Attempting to apply migrations..."); try { context.Database.Migrate(); } - catch(Exception ex) + catch (Exception ex) { Console.WriteLine($"--> Could not run migrations: {ex.Message}"); } } - - if(!context.Platforms.Any()) + + if (context.Platforms.Any() == false) { Console.WriteLine("--> Seeding Data..."); context.Platforms.AddRange( - new Platform() {Name="Dot Net", Publisher="Microsoft", Cost="Free"}, - new Platform() {Name="SQL Server Express", Publisher="Microsoft", Cost="Free"}, - new Platform() {Name="Kubernetes", Publisher="Cloud Native Computing Foundation", Cost="Free"} + new Platform() { Name = "Dot Net", Publisher = "Microsoft", Cost = "Free" }, + new Platform() { Name = "SQL Server Express", Publisher = "Microsoft", Cost = "Free" }, + new Platform() { Name = "Kubernetes", Publisher = "Cloud Native Computing Foundation", Cost = "Free" } ); context.SaveChanges(); @@ -50,4 +47,4 @@ private static void SeedData(AppDbContext context, bool isProd) } } } -} \ No newline at end of file +} diff --git a/PlatformService/Dockerfile b/PlatformService/Dockerfile index 78ee4e1..de4a699 100644 --- a/PlatformService/Dockerfile +++ b/PlatformService/Dockerfile @@ -1,4 +1,4 @@ -FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build-env +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env WORKDIR /app COPY *.csproj ./ @@ -7,7 +7,7 @@ RUN dotnet restore COPY . ./ RUN dotnet publish -c Release -o out -FROM mcr.microsoft.com/dotnet/aspnet:5.0 +FROM mcr.microsoft.com/dotnet/aspnet:8.0 WORKDIR /app COPY --from=build-env /app/out . ENTRYPOINT [ "dotnet", "PlatformService.dll" ] \ No newline at end of file diff --git a/PlatformService/Dtos/PlatformCreateDto.cs b/PlatformService/Dtos/PlatformCreateDto.cs index e2ec733..cb0b544 100644 --- a/PlatformService/Dtos/PlatformCreateDto.cs +++ b/PlatformService/Dtos/PlatformCreateDto.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace PlatformService.Dtos { @@ -13,4 +13,4 @@ public class PlatformCreateDto [Required] public string Cost { get; set; } } -} \ No newline at end of file +} diff --git a/PlatformService/Dtos/PlatformPublishedDto.cs b/PlatformService/Dtos/PlatformPublishedDto.cs index ad8f517..e5f9873 100644 --- a/PlatformService/Dtos/PlatformPublishedDto.cs +++ b/PlatformService/Dtos/PlatformPublishedDto.cs @@ -1,9 +1,11 @@ -namespace PlatformService.Dtos +namespace PlatformService.Dtos { public class PlatformPublishedDto { public int Id { get; set; } + public string Name { get; set; } + public string Event { get; set; } } -} \ No newline at end of file +} diff --git a/PlatformService/Dtos/PlatformReadDto.cs b/PlatformService/Dtos/PlatformReadDto.cs index 5b1e2dd..a4662e5 100644 --- a/PlatformService/Dtos/PlatformReadDto.cs +++ b/PlatformService/Dtos/PlatformReadDto.cs @@ -1,13 +1,13 @@ -namespace PlatformService.Dtos +namespace PlatformService.Dtos { public class PlatformReadDto - { + { public int Id { get; set; } public string Name { get; set; } - + public string Publisher { get; set; } - + public string Cost { get; set; } } -} \ No newline at end of file +} diff --git a/PlatformService/Migrations/20210811091426_initialmigration.Designer.cs b/PlatformService/Migrations/20250218160355_InitialMigration.Designer.cs similarity index 75% rename from PlatformService/Migrations/20210811091426_initialmigration.Designer.cs rename to PlatformService/Migrations/20250218160355_InitialMigration.Designer.cs index c341edf..bae2bf1 100644 --- a/PlatformService/Migrations/20210811091426_initialmigration.Designer.cs +++ b/PlatformService/Migrations/20250218160355_InitialMigration.Designer.cs @@ -6,26 +6,31 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using PlatformService.Data; +#nullable disable + namespace PlatformService.Migrations { [DbContext(typeof(AppDbContext))] - [Migration("20210811091426_initialmigration")] - partial class initialmigration + [Migration("20250218160355_InitialMigration")] + partial class InitialMigration { + /// protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("ProductVersion", "5.0.8") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasAnnotation("ProductVersion", "8.0.13") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); modelBuilder.Entity("PlatformService.Models.Platform", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Cost") .IsRequired() diff --git a/PlatformService/Migrations/20210811091426_initialmigration.cs b/PlatformService/Migrations/20250218160355_InitialMigration.cs similarity index 87% rename from PlatformService/Migrations/20210811091426_initialmigration.cs rename to PlatformService/Migrations/20250218160355_InitialMigration.cs index 75d95a3..3da7ad7 100644 --- a/PlatformService/Migrations/20210811091426_initialmigration.cs +++ b/PlatformService/Migrations/20250218160355_InitialMigration.cs @@ -1,9 +1,13 @@ using Microsoft.EntityFrameworkCore.Migrations; +#nullable disable + namespace PlatformService.Migrations { - public partial class initialmigration : Migration + /// + public partial class InitialMigration : Migration { + /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( @@ -22,6 +26,7 @@ protected override void Up(MigrationBuilder migrationBuilder) }); } + /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( diff --git a/PlatformService/Migrations/AppDbContextModelSnapshot.cs b/PlatformService/Migrations/AppDbContextModelSnapshot.cs index 345028c..42724bb 100644 --- a/PlatformService/Migrations/AppDbContextModelSnapshot.cs +++ b/PlatformService/Migrations/AppDbContextModelSnapshot.cs @@ -5,6 +5,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using PlatformService.Data; +#nullable disable + namespace PlatformService.Migrations { [DbContext(typeof(AppDbContext))] @@ -14,16 +16,18 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("ProductVersion", "5.0.8") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasAnnotation("ProductVersion", "8.0.13") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); modelBuilder.Entity("PlatformService.Models.Platform", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int") - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); b.Property("Cost") .IsRequired() diff --git a/PlatformService/Models/Platform.cs b/PlatformService/Models/Platform.cs index 1fbddb1..2e3241f 100644 --- a/PlatformService/Models/Platform.cs +++ b/PlatformService/Models/Platform.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace PlatformService.Models { @@ -17,4 +17,4 @@ public class Platform [Required] public string Cost { get; set; } } -} \ No newline at end of file +} diff --git a/PlatformService/PlatformService.csproj b/PlatformService/PlatformService.csproj index e95e073..16b8c47 100644 --- a/PlatformService/PlatformService.csproj +++ b/PlatformService/PlatformService.csproj @@ -1,21 +1,28 @@ - + - net5.0 + net8.0 + enable + enable + false - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + diff --git a/PlatformService/Profiles/PlatformsProfile.cs b/PlatformService/Profiles/PlatformsProfile.cs index 1c13c39..b0f7ca4 100644 --- a/PlatformService/Profiles/PlatformsProfile.cs +++ b/PlatformService/Profiles/PlatformsProfile.cs @@ -1,4 +1,4 @@ -using AutoMapper; +using AutoMapper; using PlatformService.Dtos; using PlatformService.Models; @@ -13,9 +13,9 @@ public PlatformsProfile() CreateMap(); CreateMap(); CreateMap() - .ForMember(dest => dest.PlatformId, opt => opt.MapFrom(src =>src.Id)) - .ForMember(dest => dest.Name, opt => opt.MapFrom(src =>src.Name)) - .ForMember(dest => dest.Publisher, opt => opt.MapFrom(src =>src.Publisher)); + .ForMember(dest => dest.PlatformId, opt => opt.MapFrom(src => src.Id)) + .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name)) + .ForMember(dest => dest.Publisher, opt => opt.MapFrom(src => src.Publisher)); } } -} \ No newline at end of file +} diff --git a/PlatformService/Program.cs b/PlatformService/Program.cs index 10b9f5a..0f0b837 100644 --- a/PlatformService/Program.cs +++ b/PlatformService/Program.cs @@ -1,26 +1,67 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; - -namespace PlatformService +using Microsoft.EntityFrameworkCore; +using PlatformService.AsyncDataServices; +using PlatformService.Data; +using PlatformService.SyncDataServices.Grpc; +using PlatformService.SyncDataServices.Http; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +if (builder.Environment.IsProduction()) +{ + Console.WriteLine("--> Using SqlServer Db"); + builder.Services.AddDbContext(opt => + { + opt.UseSqlServer(builder.Configuration.GetConnectionString("PlatformsConn")); + }); +} +else { - public class Program + Console.WriteLine("--> Using InMem Db"); + builder.Services.AddDbContext(opt => { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); - } + opt.UseInMemoryDatabase("InMem"); + }); +} + +builder.Services.AddScoped(); +builder.Services.AddSingleton(); + +builder.Services.AddHttpClient(); + +builder.Services.AddGrpc(); + +builder.Services.AddControllers(); +builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +Console.WriteLine($"--> CommandService Endpoint {builder.Configuration["CommandService"]}"); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); } + +//We're not using HTTPS for this learning. Comment out so the warning is not triggered. +//app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); +app.MapGrpcService(); + +app.MapGet("/protos/platforms.proto", async context => +{ + await context.Response.WriteAsync(File.ReadAllText("Protos/platforms.proto")); +}); + +PrepDb.PrepPopulation(app, app.Environment.IsProduction()); + +app.Run(); diff --git a/PlatformService/Properties/launchSettings.json b/PlatformService/Properties/launchSettings.json index 5789417..34f3d7b 100644 --- a/PlatformService/Properties/launchSettings.json +++ b/PlatformService/Properties/launchSettings.json @@ -4,25 +4,35 @@ "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:42320", - "sslPort": 44316 + "applicationUrl": "http://localhost:46506", + "sslPort": 44358 } }, "profiles": { - "IIS Express": { - "commandName": "IISExpress", + "http": { + "commandName": "Project", + "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", + "applicationUrl": "http://localhost:5080", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, - "PlatformService": { + "https": { "commandName": "Project", - "dotnetRunMessages": "true", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7151;http://localhost:5080", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "swagger", - "applicationUrl": "https://localhost:5001;http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/PlatformService/Protos/platforms.proto b/PlatformService/Protos/platforms.proto index 8f7fc9b..9859733 100644 --- a/PlatformService/Protos/platforms.proto +++ b/PlatformService/Protos/platforms.proto @@ -3,18 +3,17 @@ syntax = "proto3"; option csharp_namespace = "PlatformService"; service GrpcPlatform { - rpc GetAllPlatforms (GetAllRequest) returns (PlatformResponse); + rpc GetAllPlatforms (GetAllRequest) returns (PlatformResponse); } message GetAllRequest {} -message GrpcPlatformModel{ - int32 platformId = 1; - string name = 2; - string publisher = 3; +message GrpcPlatformModel { + int32 platformId = 1; + string name = 2; + string publisher = 3; } message PlatformResponse { - repeated GrpcPlatformModel platform = 1; + repeated GrpcPlatformModel platform = 1; } - diff --git a/PlatformService/Startup.cs b/PlatformService/Startup.cs deleted file mode 100644 index 3a44f6e..0000000 --- a/PlatformService/Startup.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.HttpsPolicy; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using Microsoft.OpenApi.Models; -using PlatformService.AsyncDataServices; -using PlatformService.Data; -using PlatformService.SyncDataServices.Grpc; -using PlatformService.SyncDataServices.Http; - -namespace PlatformService -{ - public class Startup - { - public IConfiguration Configuration { get; } - private readonly IWebHostEnvironment _env; - - public Startup(IConfiguration configuration, IWebHostEnvironment env) - { - Configuration = configuration; - _env = env; - } - - - public void ConfigureServices(IServiceCollection services) - { - if (_env.IsProduction()) - { - Console.WriteLine("--> Using SqlServer Db"); - services.AddDbContext(opt => - opt.UseSqlServer(Configuration.GetConnectionString("PlatformsConn"))); - } - else - { - Console.WriteLine("--> Using InMem Db"); - services.AddDbContext(opt => - opt.UseInMemoryDatabase("InMem")); - } - - services.AddScoped(); - - services.AddHttpClient(); - services.AddSingleton(); - services.AddGrpc(); - services.AddControllers(); - services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); - services.AddSwaggerGen(c => - { - c.SwaggerDoc("v1", new OpenApiInfo { Title = "PlatformService", Version = "v1" }); - }); - - Console.WriteLine($"--> CommandService Endpoint {Configuration["CommandService"]}"); - - } - - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "PlatformService v1")); - } - - //app.UseHttpsRedirection(); - - app.UseRouting(); - - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - endpoints.MapGrpcService(); - - endpoints.MapGet("/protos/platforms.proto", async context => - { - await context.Response.WriteAsync(File.ReadAllText("Protos/platforms.proto")); - }); - }); - - - PrepDb.PrepPopulation(app, env.IsProduction()); - - } - } -} diff --git a/PlatformService/SyncDataServices/Grpc/GrpcPlatformService.cs b/PlatformService/SyncDataServices/Grpc/GrpcPlatformService.cs index 1cc0764..4a896cd 100644 --- a/PlatformService/SyncDataServices/Grpc/GrpcPlatformService.cs +++ b/PlatformService/SyncDataServices/Grpc/GrpcPlatformService.cs @@ -1,5 +1,4 @@ -using System.Threading.Tasks; -using AutoMapper; +using AutoMapper; using Grpc.Core; using PlatformService.Data; @@ -21,7 +20,7 @@ public override Task GetAllPlatforms(GetAllRequest request, Se var response = new PlatformResponse(); var platforms = _repository.GetAllPlatforms(); - foreach(var plat in platforms) + foreach (var plat in platforms) { response.Platform.Add(_mapper.Map(plat)); } diff --git a/PlatformService/SyncDataServices/Http/HttpCommandDataClient.cs b/PlatformService/SyncDataServices/Http/HttpCommandDataClient.cs index 31b95eb..73c15fd 100644 --- a/PlatformService/SyncDataServices/Http/HttpCommandDataClient.cs +++ b/PlatformService/SyncDataServices/Http/HttpCommandDataClient.cs @@ -1,10 +1,6 @@ -using System; -using System.Net.Http; +using PlatformService.Dtos; using System.Text; using System.Text.Json; -using System.Threading.Tasks; -using Microsoft.Extensions.Configuration; -using PlatformService.Dtos; namespace PlatformService.SyncDataServices.Http { @@ -19,7 +15,6 @@ public HttpCommandDataClient(HttpClient httpClient, IConfiguration configuration _configuration = configuration; } - public async Task SendPlatformToCommand(PlatformReadDto plat) { var httpContent = new StringContent( @@ -29,7 +24,7 @@ public async Task SendPlatformToCommand(PlatformReadDto plat) var response = await _httpClient.PostAsync($"{_configuration["CommandService"]}", httpContent); - if(response.IsSuccessStatusCode) + if (response.IsSuccessStatusCode) { Console.WriteLine("--> Sync POST to CommandService was OK!"); } @@ -39,4 +34,4 @@ public async Task SendPlatformToCommand(PlatformReadDto plat) } } } -} \ No newline at end of file +} diff --git a/PlatformService/SyncDataServices/Http/ICommandDataClient.cs b/PlatformService/SyncDataServices/Http/ICommandDataClient.cs index ac332c2..297ead2 100644 --- a/PlatformService/SyncDataServices/Http/ICommandDataClient.cs +++ b/PlatformService/SyncDataServices/Http/ICommandDataClient.cs @@ -1,10 +1,9 @@ -using System.Threading.Tasks; -using PlatformService.Dtos; +using PlatformService.Dtos; namespace PlatformService.SyncDataServices.Http { public interface ICommandDataClient { - Task SendPlatformToCommand(PlatformReadDto plat); + Task SendPlatformToCommand(PlatformReadDto plat); } -} \ No newline at end of file +} diff --git a/PlatformService/appsettings.Development.json b/PlatformService/appsettings.Development.json index f50cc17..2835930 100644 --- a/PlatformService/appsettings.Development.json +++ b/PlatformService/appsettings.Development.json @@ -2,14 +2,25 @@ "Logging": { "LogLevel": { "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Microsoft.AspNetCore": "Warning" } }, - "CommandService": "http://localhost:6000/api/c/platforms/", + "CommandService": "https://localhost:7180/api/c/platforms", "ConnectionStrings": { - "PlatformsConn": "Server=localhost,1433;Initial Catalog=platformsdb;User ID=sa;Password=pa55w0rd;" + "PlatformsConn": "Server=localhost,1433;Database=platformsdb;User ID=sa;Password=pa55w0rd!;Encrypt=False;Trust Server Certificate=False;" }, "RabbitMQHost": "localhost", - "RabbitMQPort": "5672" -} \ No newline at end of file + "RabbitMQPort": "5672", + "Kestrel": { + "Endpoints": { + "Grpc": { + "Protocols": "Http2", + "Url": "http://localhost:888" + }, + "WebApi": { + "Protocols": "Http1", + "Url": "https://localhost:7151" + } + } + } +} diff --git a/PlatformService/appsettings.Production.json b/PlatformService/appsettings.Production.json deleted file mode 100644 index 37a2646..0000000 --- a/PlatformService/appsettings.Production.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "CommandService": "http://commands-clusterip-srv:80/api/c/platforms/", - "ConnectionStrings": { - "PlatformsConn": "Server=mssql-clusterip-srv,1433;Initial Catalog=platformsdb;User ID=sa;Password=pa55w0rd!;" - }, - "RabbitMQHost": "rabbitmq-clusterip-srv", - "RabbitMQPort": "5672", - "Kestrel": { - "Endpoints": { - "Grpc": { - "Protocols": "Http2", - "Url": "http://platforms-clusterip-srv:666" - }, - "webApi": { - "Protocols": "Http1", - "Url": "http://platforms-clusterip-srv:80" - } - } - } -} \ No newline at end of file diff --git a/PlatformService/appsettings.json b/PlatformService/appsettings.json new file mode 100644 index 0000000..d035563 --- /dev/null +++ b/PlatformService/appsettings.json @@ -0,0 +1,27 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*", + "CommandService": "http://commands-clusterip-srv:8080/api/c/platforms", + "ConnectionStrings": { + "PlatformsConn": "Server=host.docker.internal,1433;Database=platformsdb;User ID=sa;Password=pa55w0rd!;Encrypt=False;Trust Server Certificate=False;" + }, + "RabbitMQHost": "rabbitmq-clusterip-srv", + "RabbitMQPort": "5672", + "Kestrel": { + "Endpoints": { + "Grpc": { + "Protocols": "Http2", + "Url": "http://platforms-clusterip-srv:666" + }, + "WebApi": { + "Protocols": "Http1", + "Url": "http://platforms-clusterip-srv:8080" + } + } + } +}