Skip to content
Open
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
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
21 changes: 21 additions & 0 deletions Message Processing and Anomaly Detection Service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM mcr.microsoft.com/dotnet/runtime:9.0 AS base
USER $APP_UID
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Message Processing and Anomaly Detection Service/Message Processing and Anomaly Detection Service.csproj", "Message Processing and Anomaly Detection Service/"]
RUN dotnet restore "Message Processing and Anomaly Detection Service/Message Processing and Anomaly Detection Service.csproj"
COPY . .
WORKDIR "/src/Message Processing and Anomaly Detection Service"
RUN dotnet build "./Message Processing and Anomaly Detection Service.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Message Processing and Anomaly Detection Service.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Message Processing and Anomaly Detection Service.dll"]
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
<RootNamespace>Message_Processing_and_Anomaly_Detection_Service</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

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

<ItemGroup>
<Content Include="..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Message_Processing_and_Anomaly_Detection_Service.RabbitMQReceivers;

public interface IRabbitMQReceiver
{
public Task<string> ReceivePayload();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Text;
using System.Text.Json;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;

namespace Message_Processing_and_Anomaly_Detection_Service.RabbitMQReceivers;

public class RabbitMQReceiver : IRabbitMQReceiver
{
public async Task<string> ReceivePayload()
{
var factory = new ConnectionFactory()
{
HostName = Environment.GetEnvironmentVariable("RABBITMQ__HOSTNAME") ?? "localhost",
Port = int.TryParse(Environment.GetEnvironmentVariable("RABBITMQ__PORT"), out var port) ? port : 5672,
UserName = Environment.GetEnvironmentVariable("RABBITMQ__USERNAME") ?? "guest",
Password = Environment.GetEnvironmentVariable("RABBITMQ__PASSWORD") ?? "guest"
};

using var connection = await factory.CreateConnectionAsync();
using var channel = await connection.CreateChannelAsync();


const string queueName = "server_statistics_queue";

await channel.QueueDeclareAsync(
queue: queueName,
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);

var tcs = new TaskCompletionSource<string>();
var consumer = new AsyncEventingBasicConsumer(channel);
consumer.ReceivedAsync += async (sender, eventArgs) =>
{
var message = Encoding.UTF8.GetString(eventArgs.Body.ToArray());;
tcs.TrySetResult(message);
await Task.CompletedTask;
await ((AsyncEventingBasicConsumer)sender).Channel.BasicAckAsync(eventArgs.DeliveryTag, multiple: false);
};
await channel.BasicConsumeAsync(queue: queueName,
autoAck: false,
consumer: consumer);

var result = await tcs.Task;


await channel.CloseAsync();
await connection.CloseAsync();
return result;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace Message_Processing_and_Anomaly_Detection_Service;

public record ServerStatistics(double MemoryUsage, double AvailableMemory, double CpuUsage,
DateTime Timestamp);