diff --git a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/.env.example b/projeto-gerar-horario/Microsservicos/GerarHorario-Service/.env.example deleted file mode 100644 index 94bbd216..00000000 --- a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/.env.example +++ /dev/null @@ -1,4 +0,0 @@ -RABBITMQ_USERNAME=admin -RABBITMQ_PASSWORD=admin - -RABBITMQ_MANAGEMENT_ALLOW_WEB_ACCESS=true diff --git a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/Extensions/MiddlewareExtensions.cs b/projeto-gerar-horario/Microsservicos/GerarHorario-Service/Extensions/MiddlewareExtensions.cs deleted file mode 100644 index e669a85d..00000000 --- a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/Extensions/MiddlewareExtensions.cs +++ /dev/null @@ -1,11 +0,0 @@ -using GerarHorario_Service.Middlewares; - -namespace GerarHorario_Service.Extensions; - -public static class MiddlewareExtensions -{ - public static IApplicationBuilder UseQueueListener(this IApplicationBuilder app) - { - return app.UseMiddleware(); - } -} \ No newline at end of file diff --git a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/GerarHorario-Service.csproj b/projeto-gerar-horario/Microsservicos/GerarHorario-Service/GerarHorario-Service.csproj index 7360b5b4..e6de9b0a 100644 --- a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/GerarHorario-Service.csproj +++ b/projeto-gerar-horario/Microsservicos/GerarHorario-Service/GerarHorario-Service.csproj @@ -1,29 +1,21 @@ - - - net8.0 - enable - enable - GerarHorario_Service - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + Exe + net8.0 + GerarHorario_Service + enable + enable + + + + + + + + + ..\..\GerarHorario\bin\Debug\net8.0\GerarHorario.dll + + + + diff --git a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/Middlewares/QueueListenerMiddleware.cs b/projeto-gerar-horario/Microsservicos/GerarHorario-Service/Middlewares/QueueListenerMiddleware.cs deleted file mode 100644 index 396d3365..00000000 --- a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/Middlewares/QueueListenerMiddleware.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System.Globalization; -using System.Text; -using System.Text.Json; -using RabbitMQ.Client; -using RabbitMQ.Client.Events; -using Sisgea.GerarHorario.Core.Dtos.Configuracoes; -using Sisgea.GerarHorario.Core.Dtos.HorarioGerado; - -namespace GerarHorario_Service.Middlewares; - -public class QueueService -{ - - public static void ListenQueue() - { - var factory = new ConnectionFactory() { HostName = "localhost" }; - factory.UserName = "admin"; - factory.Password = "admin"; - using var connection = factory.CreateConnection(); - - using var channel = connection.CreateModel(); - channel.QueueDeclare( - queue: "gerar_horario", - durable: true, - exclusive: false, - autoDelete: false, - arguments: null - ); - - channel.QueueDeclare( - queue: "horario_gerado", - durable: true, - exclusive: false, - autoDelete: false, - arguments: null - ); - - void publicarRespostaGerarHorario(HorarioGerado? horarioGerado = null) - { - // TODO: message = JSON(horarioGerado) - const string message = "Hello World!"; - var body = Encoding.UTF8.GetBytes(message); - - channel.BasicPublish(exchange: string.Empty, - routingKey: "horario_gerado", - basicProperties: null, - body: body); - - Console.WriteLine($" [x] Sent {message}"); - } - - Console.WriteLine(" [*] Waiting for messages."); - - var consumer = new EventingBasicConsumer(channel); - consumer.Received += (model, ea) => - { - var body = ea.Body.ToArray(); - var message = Encoding.UTF8.GetString(body); - Console.WriteLine($" [x] Received {message}"); - - var options = new JsonSerializerOptions() - { - PropertyNameCaseInsensitive = true - }; - - GerarHorarioOptions? gerarHorarioOptions = JsonSerializer.Deserialize(message, options); - Console.WriteLine(gerarHorarioOptions); - - publicarRespostaGerarHorario(); - }; - - channel.BasicConsume(queue: "gerar_horario", - autoAck: true, - consumer: consumer); - - Console.ReadLine(); - } -} \ No newline at end of file diff --git a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/Program.cs b/projeto-gerar-horario/Microsservicos/GerarHorario-Service/Program.cs index 42a59963..406bc9f4 100644 --- a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/Program.cs +++ b/projeto-gerar-horario/Microsservicos/GerarHorario-Service/Program.cs @@ -1,23 +1,73 @@ -using GerarHorario_Service.Middlewares; - - -Thread server = new(() => -{ - - var builder = WebApplication.CreateBuilder(args); - var app = builder.Build(); - - app.MapGet("/up", () => "up"); - - - - app.Run(); -}); - -Thread queue = new(QueueService.ListenQueue); - - - -server.Start(); -queue.Start(); - +using System.Text; +using System.Text.Json; +using RabbitMQ.Client; +using RabbitMQ.Client.Events; +using Sisgea.GerarHorario; +using Sisgea.GerarHorario.Core.Dtos.Configuracoes; +using Sisgea.GerarHorario.Core.Dtos.HorarioGerado; + + +var factory = new ConnectionFactory() +{ + HostName = "localhost", + UserName = "admin", + Password = "admin" +}; + +using var connection = factory.CreateConnection(); + +using var channel = connection.CreateModel(); +channel.QueueDeclare( + queue: "gerar_horario", + durable: true, + exclusive: false, + autoDelete: false, + arguments: null +); + +channel.QueueDeclare( + queue: "horario_gerado", + durable: true, + exclusive: false, + autoDelete: false, + arguments: null +); + +void publicarRespostaGerarHorario(HorarioGerado? horarioGerado = null) +{ + // TODO: message = JSON(horarioGerado) + const string message = "Hello World!"; + var body = Encoding.UTF8.GetBytes(message); + + channel.BasicPublish(exchange: string.Empty, + routingKey: "horario_gerado", + basicProperties: null, + body: body); + + Console.WriteLine($" [x] Sent {message}"); +} + +Console.WriteLine(" [*] Waiting for messages."); + +var consumer = new EventingBasicConsumer(channel); +consumer.Received += (model, ea) => +{ + var body = ea.Body.ToArray(); + var message = Encoding.UTF8.GetString(body); + Console.WriteLine($" [x] Received {message}"); + + var options = new JsonSerializerOptions() + { + PropertyNameCaseInsensitive = true + }; + + GerarHorarioOptions? gerarHorarioOptions = JsonSerializer.Deserialize(message, options); + Console.WriteLine(gerarHorarioOptions); + + publicarRespostaGerarHorario(); +}; + +channel.BasicConsume(queue: "gerar_horario", + autoAck: true, + consumer: consumer); + \ No newline at end of file diff --git a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/Properties/launchSettings.json b/projeto-gerar-horario/Microsservicos/GerarHorario-Service/Properties/launchSettings.json deleted file mode 100644 index 1a9f97e4..00000000 --- a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/Properties/launchSettings.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/launchsettings.json", - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:60021", - "sslPort": 0 - } - }, - "profiles": { - "http": { - "commandName": "Project", - "dotnetRunMessages": true, - "launchBrowser": true, - "applicationUrl": "http://localhost:5017", - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - } - } -} diff --git a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/appsettings.Development.json b/projeto-gerar-horario/Microsservicos/GerarHorario-Service/appsettings.Development.json deleted file mode 100644 index 0c208ae9..00000000 --- a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/appsettings.Development.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -} diff --git a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/appsettings.json b/projeto-gerar-horario/Microsservicos/GerarHorario-Service/appsettings.json deleted file mode 100644 index 10f68b8c..00000000 --- a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/appsettings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - }, - "AllowedHosts": "*" -} diff --git a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/docker-compose.yml b/projeto-gerar-horario/Microsservicos/GerarHorario-Service/docker-compose.yml deleted file mode 100644 index 4adb6b36..00000000 --- a/projeto-gerar-horario/Microsservicos/GerarHorario-Service/docker-compose.yml +++ /dev/null @@ -1,14 +0,0 @@ -services: - message-broker: - image: docker.io/bitnami/rabbitmq:3.12 - container_name: sisgea-message-broker - env_file: - - .env - volumes: - - "sisgea-message-broker-data:/bitnami/rabbitmq/mnesia" - ports: - - 5672:5672 - - 15672:15672 - -volumes: - sisgea-message-broker-data: