Skip to content

Commit 47c9335

Browse files
committed
Initial commit
1 parent 9f32430 commit 47c9335

27 files changed

+842
-0
lines changed

.dockerignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
**/.classpath
2+
**/.dockerignore
3+
**/.env
4+
**/.git
5+
**/.gitignore
6+
**/.project
7+
**/.settings
8+
**/.toolstarget
9+
**/.vs
10+
**/.vscode
11+
**/*.*proj.user
12+
**/*.dbmdl
13+
**/*.jfm
14+
**/azds.yaml
15+
**/bin
16+
**/charts
17+
**/docker-compose*
18+
**/Dockerfile*
19+
**/node_modules
20+
**/npm-debug.log
21+
**/obj
22+
**/secrets.dev.yaml
23+
**/values.dev.yaml
24+
LICENSE
25+
README.md

Dockerfile.develop

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:5.0
2+
ARG BUILD_CONFIGURATION=Debug
3+
ENV ASPNETCORE_ENVIRONMENT=Development
4+
ENV ASPNETCORE_URLS=http://+:80
5+
ENV DOTNET_USE_POLLING_FILE_WATCHER=true
6+
EXPOSE 80
7+
8+
WORKDIR /src
9+
COPY ["SimpleK8sHosting.csproj", "./"]
10+
11+
RUN dotnet restore "./SimpleK8sHosting.csproj"
12+
COPY . .
13+
WORKDIR "/src/."
14+
RUN dotnet build --no-restore "SimpleK8sHosting.csproj" -c $BUILD_CONFIGURATION
15+
16+
RUN echo "exec dotnet run --no-build --no-launch-profile -c $BUILD_CONFIGURATION --" > /entrypoint.sh
17+
18+
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
# message-queue-k8s
22
Message based queue processing system hosted in Kubernetes
3+
4+
# Running using docker-compose
5+
6+
Run the below commands from the root of the repository
7+
- docker-compose build
8+
- docker-compose up --remove-orphans
9+
10+
# Running using Kubernetes
11+
12+
Pending

docker-compose.dcproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
3+
<PropertyGroup Label="Globals">
4+
<ProjectVersion>2.1</ProjectVersion>
5+
<DockerTargetOS>Linux</DockerTargetOS>
6+
<ProjectGuid>97ec0b88-9b17-49c2-9102-da8f826151d4</ProjectGuid>
7+
<DockerLaunchAction>LaunchBrowser</DockerLaunchAction>
8+
<DockerServiceUrl>{Scheme}://localhost:{ServicePort}/swagger</DockerServiceUrl>
9+
<DockerServiceName>host</DockerServiceName>
10+
</PropertyGroup>
11+
<ItemGroup>
12+
<None Include="docker-compose.override.yml">
13+
<DependentUpon>docker-compose.yml</DependentUpon>
14+
</None>
15+
<None Include="docker-compose.yml" />
16+
<None Include=".dockerignore" />
17+
</ItemGroup>
18+
</Project>

docker-compose.override.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3.4'
2+
3+
services:
4+
webapi:
5+
environment:
6+
- ASPNETCORE_ENVIRONMENT=Development
7+
- ASPNETCORE_URLS=https://+:443;http://+:80
8+
ports:
9+
- "80"
10+
- "443"
11+
volumes:
12+
- ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
13+
- ${APPDATA}/ASP.NET/Https:/root/.aspnet/https:ro

docker-compose.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: '3.4'
2+
3+
services:
4+
worker:
5+
build:
6+
context: .
7+
dockerfile: message-processor/Dockerfile
8+
restart: always
9+
depends_on:
10+
- "rabbitmq"
11+
rabbitmq: # login guest:guest
12+
image: rabbitmq:3-management
13+
hostname: "rabbitmq"
14+
labels:
15+
NAME: "rabbitmq"
16+
ports:
17+
- "4369:4369"
18+
- "5671:5671"
19+
- "5672:5672"
20+
- "25672:25672"
21+
- "15671:15671"
22+
- "15672:15672"
23+
webapi:
24+
image: ${DOCKER_REGISTRY-}host
25+
build:
26+
context: .
27+
dockerfile: webapi/Dockerfile
28+
ports:
29+
- "81:80"
30+

message-processor/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
2+
WORKDIR /app
3+
4+
# Copy csproj and restore as distinct layers
5+
COPY message-processor/*.csproj ./
6+
RUN dotnet restore
7+
8+
# Copy everything else and build
9+
COPY message-processor ./
10+
RUN dotnet publish "message-processor.csproj" -c Release -o out
11+
12+
# Build runtime image
13+
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
14+
15+
WORKDIR /app
16+
17+
COPY --from=build /app/out .
18+
19+
ENTRYPOINT ["dotnet", "message-processor.dll"]

message-processor/Program.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using Newtonsoft.Json;
2+
using RabbitMQ.Client;
3+
using RabbitMQ.Client.Events;
4+
using System;
5+
using System.Net.Http;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace message_processor
10+
{
11+
class Program
12+
{
13+
static void Main(string[] args)
14+
{
15+
Console.WriteLine($"Started {nameof(message_processor)}");
16+
ConnectionFactory factory = new ConnectionFactory() { HostName = "rabbitmq", Port = 5672 };
17+
factory.UserName = "guest";
18+
factory.Password = "guest";
19+
IConnection conn = factory.CreateConnection();
20+
IModel channel = conn.CreateModel();
21+
channel.QueueDeclare(queue: "myqueue",
22+
durable: false,
23+
exclusive: false,
24+
autoDelete: false,
25+
arguments: null);
26+
var consumer = new EventingBasicConsumer(channel);
27+
consumer.Received += (model, ea) =>
28+
{
29+
var body = ea.Body.Span;
30+
var message = Encoding.UTF8.GetString(body);
31+
Console.WriteLine($"🠗 Received from RabbitMQ: {message}");
32+
};
33+
Console.WriteLine("Subscribed to the queue");
34+
channel.BasicConsume(queue: "myqueue",
35+
autoAck: true,
36+
consumer: consumer);
37+
Task.Delay(1000).Wait();
38+
Console.WriteLine($"Completed {nameof(message_processor)}");
39+
}
40+
}
41+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
<RootNamespace>message_processor</RootNamespace>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
11+
<PackageReference Include="RabbitMQ.Client" Version="6.2.2" />
12+
</ItemGroup>
13+
14+
</Project>

message-queue-k8s.sln

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31321.278
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "host", "webapi\host.csproj", "{FEE7C895-DA8F-4E96-9933-C2162C43D25E}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "message-processor", "message-processor\message-processor.csproj", "{825B4F75-60EE-44A1-AC18-529AD96E32FC}"
9+
EndProject
10+
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{97EC0B88-9B17-49C2-9102-DA8F826151D4}"
11+
EndProject
12+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "shared", "shared\shared.csproj", "{EBCC529E-9788-44B6-B368-039102A825CB}"
13+
EndProject
14+
Global
15+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
16+
Debug|Any CPU = Debug|Any CPU
17+
NoVariablesDefault|Any CPU = NoVariablesDefault|Any CPU
18+
Release|Any CPU = Release|Any CPU
19+
EndGlobalSection
20+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21+
{FEE7C895-DA8F-4E96-9933-C2162C43D25E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{FEE7C895-DA8F-4E96-9933-C2162C43D25E}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{FEE7C895-DA8F-4E96-9933-C2162C43D25E}.NoVariablesDefault|Any CPU.ActiveCfg = Debug|Any CPU
24+
{FEE7C895-DA8F-4E96-9933-C2162C43D25E}.NoVariablesDefault|Any CPU.Build.0 = Debug|Any CPU
25+
{FEE7C895-DA8F-4E96-9933-C2162C43D25E}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{FEE7C895-DA8F-4E96-9933-C2162C43D25E}.Release|Any CPU.Build.0 = Release|Any CPU
27+
{825B4F75-60EE-44A1-AC18-529AD96E32FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28+
{825B4F75-60EE-44A1-AC18-529AD96E32FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{825B4F75-60EE-44A1-AC18-529AD96E32FC}.NoVariablesDefault|Any CPU.ActiveCfg = Debug|Any CPU
30+
{825B4F75-60EE-44A1-AC18-529AD96E32FC}.NoVariablesDefault|Any CPU.Build.0 = Debug|Any CPU
31+
{825B4F75-60EE-44A1-AC18-529AD96E32FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
32+
{825B4F75-60EE-44A1-AC18-529AD96E32FC}.Release|Any CPU.Build.0 = Release|Any CPU
33+
{97EC0B88-9B17-49C2-9102-DA8F826151D4}.Debug|Any CPU.ActiveCfg = NoVariablesDefault
34+
{97EC0B88-9B17-49C2-9102-DA8F826151D4}.Debug|Any CPU.Build.0 = NoVariablesDefault
35+
{97EC0B88-9B17-49C2-9102-DA8F826151D4}.NoVariablesDefault|Any CPU.ActiveCfg = NoVariablesDefault
36+
{97EC0B88-9B17-49C2-9102-DA8F826151D4}.NoVariablesDefault|Any CPU.Build.0 = NoVariablesDefault
37+
{97EC0B88-9B17-49C2-9102-DA8F826151D4}.Release|Any CPU.ActiveCfg = NoVariablesDefault
38+
{97EC0B88-9B17-49C2-9102-DA8F826151D4}.Release|Any CPU.Build.0 = NoVariablesDefault
39+
{EBCC529E-9788-44B6-B368-039102A825CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40+
{EBCC529E-9788-44B6-B368-039102A825CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
41+
{EBCC529E-9788-44B6-B368-039102A825CB}.NoVariablesDefault|Any CPU.ActiveCfg = Debug|Any CPU
42+
{EBCC529E-9788-44B6-B368-039102A825CB}.NoVariablesDefault|Any CPU.Build.0 = Debug|Any CPU
43+
{EBCC529E-9788-44B6-B368-039102A825CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{EBCC529E-9788-44B6-B368-039102A825CB}.Release|Any CPU.Build.0 = Release|Any CPU
45+
EndGlobalSection
46+
GlobalSection(SolutionProperties) = preSolution
47+
HideSolutionNode = FALSE
48+
EndGlobalSection
49+
GlobalSection(ExtensibilityGlobals) = postSolution
50+
SolutionGuid = {8B6993A5-74F7-4BA0-A99C-61A32747F3D6}
51+
EndGlobalSection
52+
EndGlobal

0 commit comments

Comments
 (0)