Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore simplifying project #25

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>GerarHorario_Service</RootNamespace>
</PropertyGroup>


<ItemGroup>
<ProjectReference Include="..\..\GerarHorario\GerarHorario.csproj" />
</ItemGroup>


<ItemGroup>
<PackageReference Include="RabbitMQ.Client" Version="6.8.1" />
<PackageReference Include="RabbitMQ.Stream.Client" Version="1.8.2" />
</ItemGroup>


<ItemGroup>
<Folder Include="Extensions\" />
</ItemGroup>


<ItemGroup>
<Compile Remove="Extensions\MiddlewareExtensions.cs" />
</ItemGroup>
</Project>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>GerarHorario_Service</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="RabbitMQ.Client" Version="6.8.1" />
</ItemGroup>

<ItemGroup>
<Reference Include="GerarHorario">
<HintPath>..\..\GerarHorario\bin\Debug\net8.0\GerarHorario.dll</HintPath>
guesant marked this conversation as resolved.
Show resolved Hide resolved
</Reference>
</ItemGroup>

</Project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<GerarHorarioOptions>(message, options);
Console.WriteLine(gerarHorarioOptions);

publicarRespostaGerarHorario();
};

channel.BasicConsume(queue: "gerar_horario",
autoAck: true,
consumer: consumer);

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading