(feature): init

This commit is contained in:
Maksym Sadovnychyy 2024-11-13 21:32:57 +01:00
commit 195342f0a3
33 changed files with 1139 additions and 0 deletions

63
.gitattributes vendored Normal file
View File

@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

265
.gitignore vendored Normal file
View File

@ -0,0 +1,265 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
project.fragment.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
#*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
.directory
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
**/docker-compose/rabbitmq

21
LICENSE.md Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2024 Maksym Sadovnychyy (MAKS-IT)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

45
README.md Normal file
View File

@ -0,0 +1,45 @@
# Dapr with ASP.NET Core in Docker Compose and Kubernetes deployment test
> Warning: This project is not yet complete to run in Kubernetes. It is still in development.
## Contribution
Contributions to this project are welcome! Please fork the repository and submit a pull request with your changes. If you encounter any issues or have feature requests, feel free to open an issue on GitHub.
## Contact
If you have any questions or need further assistance, feel free to reach out:
- **Email**: [maksym.sadovnychyy@gmail.com](mailto:maksym.sadovnychyy@gmail.com)
## License
This project is licensed under the MIT License. See the full license text below.
---
### MIT License
```
MIT License
Copyright (c) 2024 Maksym Sadovnychyy (MAKS-IT)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

30
src/.dockerignore Normal file
View File

@ -0,0 +1,30 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*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
!**/.gitignore
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Core.Commands;
public class TestCommand {
[Required]
public required string Message { get; set; }
}

9
src/Core/Core.csproj Normal file
View File

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

65
src/DaprNetTest.sln Normal file
View File

@ -0,0 +1,65 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35327.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Publisher", "Publisher\Publisher.csproj", "{74D466DA-71E2-4D59-B7DD-96DDE489D7E0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Subscriber", "Subscriber\Subscriber.csproj", "{0310090C-DB06-4437-ABA1-04B5487AC49F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "Core\Core.csproj", "{B565C0F4-2642-49A6-9A6F-9CAAC66F75EE}"
EndProject
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{939576C3-1BFC-4500-BDB3-0521234AC1B4}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dapr", "dapr", "{1501327C-BD39-4430-9E39-184B66816EEC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "components", "components", "{C7F60667-661D-4B86-9554-39F6AB571E55}"
ProjectSection(SolutionItems) = preProject
docker-compose\dapr\components\pubsub.yaml = docker-compose\dapr\components\pubsub.yaml
docker-compose\dapr\components\statestore.yaml = docker-compose\dapr\components\statestore.yaml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "configuration", "configuration", "{6A36CFD8-4BC5-45B5-9EA8-B57D6E2F88E5}"
ProjectSection(SolutionItems) = preProject
docker-compose\dapr\configuration\config.yaml = docker-compose\dapr\configuration\config.yaml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "deployment", "deployment", "{1874EE05-F553-41AB-A8A7-3E9AE70AE70F}"
ProjectSection(SolutionItems) = preProject
deployment.yaml = deployment.yaml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{74D466DA-71E2-4D59-B7DD-96DDE489D7E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74D466DA-71E2-4D59-B7DD-96DDE489D7E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74D466DA-71E2-4D59-B7DD-96DDE489D7E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74D466DA-71E2-4D59-B7DD-96DDE489D7E0}.Release|Any CPU.Build.0 = Release|Any CPU
{0310090C-DB06-4437-ABA1-04B5487AC49F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0310090C-DB06-4437-ABA1-04B5487AC49F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0310090C-DB06-4437-ABA1-04B5487AC49F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0310090C-DB06-4437-ABA1-04B5487AC49F}.Release|Any CPU.Build.0 = Release|Any CPU
{B565C0F4-2642-49A6-9A6F-9CAAC66F75EE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B565C0F4-2642-49A6-9A6F-9CAAC66F75EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B565C0F4-2642-49A6-9A6F-9CAAC66F75EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B565C0F4-2642-49A6-9A6F-9CAAC66F75EE}.Release|Any CPU.Build.0 = Release|Any CPU
{939576C3-1BFC-4500-BDB3-0521234AC1B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{939576C3-1BFC-4500-BDB3-0521234AC1B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{939576C3-1BFC-4500-BDB3-0521234AC1B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{939576C3-1BFC-4500-BDB3-0521234AC1B4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{C7F60667-661D-4B86-9554-39F6AB571E55} = {1501327C-BD39-4430-9E39-184B66816EEC}
{6A36CFD8-4BC5-45B5-9EA8-B57D6E2F88E5} = {1501327C-BD39-4430-9E39-184B66816EEC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6B523C08-C7BE-471D-9058-FD873C7131D5}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,34 @@
using Core.Commands;
using MaksIT.Core.Dapr;
using MaksIT.Core.Extensions;
using Microsoft.AspNetCore.Mvc;
using Publisher.Models;
using System.Text.Json;
namespace Publisher.Controllers;
[ApiController]
[Route("[controller]")]
public class DaprTestController : ControllerBase {
private readonly ILogger<DaprTestController> _logger;
private readonly IDaprService _daprService;
public DaprTestController(
ILogger<DaprTestController> logger,
IDaprService daprService
) {
_logger = logger;
_daprService = daprService;
}
[HttpPost(Name = "DaprTestPublisher")]
public async Task<IActionResult> Post([FromBody] PostDaprTestRequest requestData) {
var result = await _daprService.PublishEventAsync(
"pubsub",
"test",
new TestCommand {
Message = requestData.Message
}.ToJson());
return result.ToActionResult();
}
}

30
src/Publisher/Dockerfile Normal file
View File

@ -0,0 +1,30 @@
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Publisher/Publisher.csproj", "Publisher/"]
COPY ["Core/Core.csproj", "Core/"]
RUN dotnet restore "./Publisher/Publisher.csproj"
COPY . .
WORKDIR "/src/Publisher"
RUN dotnet build "./Publisher.csproj" -c $BUILD_CONFIGURATION -o /app/build
# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Publisher.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Publisher.dll"]

View File

@ -0,0 +1,9 @@
using MaksIT.Core.Abstractions.Webapi;
using System.ComponentModel.DataAnnotations;
namespace Publisher.Models;
public class PostDaprTestRequest : RequestModelBase {
[Required]
public required string Message { get; set; }
}

23
src/Publisher/Program.cs Normal file
View File

@ -0,0 +1,23 @@
using MaksIT.Core.Dapr.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.RegisterPublisher();
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.UseAuthorization();
app.MapControllers();
app.Run();

View File

@ -0,0 +1,41 @@
{
"profiles": {
"http": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5115"
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Container (Dockerfile)": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"environmentVariables": {
"ASPNETCORE_HTTP_PORTS": "8080"
},
"publishAllPorts": true,
"useSSL": false
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:23454",
"sslPort": 0
}
}
}

View File

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MaksIT.Core" Version="1.1.6" />
<PackageReference Include="MaksIT.Core.Dapr" Version="1.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
@Publisher_HostAddress = http://localhost:5115
GET {{Publisher_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@ -0,0 +1,30 @@
using Core.Commands;
using Dapr;
using MaksIT.Core.Extensions;
using Microsoft.AspNetCore.Mvc;
namespace Subscriber.Controllers;
[ApiController]
[Route("[controller]")]
public class DaprTestController : ControllerBase {
private readonly ILogger<DaprTestController> _logger;
public DaprTestController(
ILogger<DaprTestController> logger
) {
_logger = logger;
}
[Topic("pubsub", "test")]
[HttpPost(Name = "DaprTestSubscriber")]
public IActionResult Post([FromBody] string json) {
var requestData = json.ToObject<TestCommand>();
if (requestData == null)
return BadRequest();
_logger.LogInformation("Received message: {0}", requestData.Message);
return Ok();
}
}

30
src/Subscriber/Dockerfile Normal file
View File

@ -0,0 +1,30 @@
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Subscriber/Subscriber.csproj", "Subscriber/"]
COPY ["Core/Core.csproj", "Core/"]
RUN dotnet restore "./Subscriber/Subscriber.csproj"
COPY . .
WORKDIR "/src/Subscriber"
RUN dotnet build "./Subscriber.csproj" -c $BUILD_CONFIGURATION -o /app/build
# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Subscriber.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Subscriber.dll"]

24
src/Subscriber/Program.cs Normal file
View File

@ -0,0 +1,24 @@
using MaksIT.Core.Dapr.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment()) {
}
app.UseAuthorization();
app.RegisterSubscriber();
app.MapControllers();
app.Run();

View File

@ -0,0 +1,41 @@
{
"profiles": {
"http": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5016"
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Container (Dockerfile)": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
"environmentVariables": {
"ASPNETCORE_HTTP_PORTS": "8080"
},
"publishAllPorts": true,
"useSSL": false
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:25735",
"sslPort": 0
}
}
}

View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MaksIT.Core" Version="1.1.6" />
<PackageReference Include="MaksIT.Core.Dapr" Version="1.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
@Subscriber_HostAddress = http://localhost:5016
GET {{Subscriber_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

56
src/deployment.yaml Normal file
View File

@ -0,0 +1,56 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: publisher
namespace: dapr-test
spec:
replicas: 1
selector:
matchLabels:
app: publisher
template:
metadata:
labels:
app: publisher
annotations:
dapr.io/enabled: "true"
dapr.io/app-id: "publisher"
dapr.io/app-port: "3000"
spec:
containers:
- name: publisher
image: daprio/quickstart-pubsub-publisher
ports:
- containerPort: 3000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: subscriber
namespace: dapr-test
spec:
replicas: 1
selector:
matchLabels:
app: subscriber
template:
metadata:
labels:
app: subscriber
annotations:
dapr.io/enabled: "true"
dapr.io/app-id: "subscriber"
dapr.io/app-port: "3001"
spec:
containers:
- name: subscriber
image: daprio/quickstart-pubsub-subscriber
ports:
- containerPort: 3001
env:
- name: PUBSUB_TOPIC
value: "pubsub" # The topic used by pubsub component
- name: STATE_STORE
value: "statestore" # The name of your statestore component

19
src/docker-compose.dcproj Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
<PropertyGroup Label="Globals">
<ProjectVersion>2.1</ProjectVersion>
<DockerTargetOS>Linux</DockerTargetOS>
<DockerPublishLocally>False</DockerPublishLocally>
<ProjectGuid>939576c3-1bfc-4500-bdb3-0521234ac1b4</ProjectGuid>
<DockerLaunchAction>LaunchBrowser</DockerLaunchAction>
<DockerServiceUrl>{Scheme}://localhost:{ServicePort}/swagger</DockerServiceUrl>
<DockerServiceName>publisher</DockerServiceName>
</PropertyGroup>
<ItemGroup>
<None Include="docker-compose.override.yml">
<DependentUpon>docker-compose.yml</DependentUpon>
</None>
<None Include="docker-compose.yml" />
<None Include=".dockerignore" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,108 @@
networks:
hello-dapr:
driver: "bridge"
x-daprd-common: &daprd-common
image: "daprio/daprd:edge"
volumes:
- "./docker-compose/dapr/components/:/components" # Mount our components folder for the runtime to use. The mounted location must match the --resources-path argument.
- "./docker-compose/dapr/configuration/:/configuration" # Mount our configuration folder for the runtime to use. The mounted location must match the --config", "/configuration/config.yaml.
services:
publisher-dapr:
<<: *daprd-common
command: [
"./daprd",
"--app-id", "publisher",
"--app-port", "5000",
# "--enable-api-logging",
# "--log-level", "debug",
"--placement-host-address", "placement:50006", # Dapr's placement service can be reach via the docker DNS entry
"--config", "/configuration/config.yaml",
"--resources-path","./components",
"--components-path", "/components"
]
depends_on:
- placement
- publisher
network_mode: "service:publisher" # Attach the publisher-dapr service to the publisher network namespace
publisher:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_HTTP_PORTS=5000
ports:
- "5000:5000"
networks:
- hello-dapr
subscriber-dapr:
<<: *daprd-common
command: [
"./daprd",
"--app-id", "subscriber",
"--app-port", "5000",
# "--enable-api-logging",
# "--log-level", "debug",
"--placement-host-address", "placement:50006", # Dapr's placement service can be reach via the docker DNS entry
"--config", "/configuration/config.yaml",
"--resources-path","./components",
"--components-path", "/components"
]
depends_on:
- placement
- subscriber
network_mode: "service:subscriber" # Attach the subscriber-dapr service to the subscriber network namespace
subscriber:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_HTTP_PORTS=5000
ports:
- "5000"
networks:
- hello-dapr
placement:
command: [
"./placement",
"--port", "50006",
#"--log-level", "debug"
]
depends_on:
- rabbitmq
- redis
- zipkin
ports:
- "50006:50006"
networks:
- hello-dapr
zipkin:
ports:
- "9411:9411"
networks:
- hello-dapr
rabbitmq:
environment:
RABBITMQ_DEFAULT_USER: admin
RABBITMQ_DEFAULT_PASS: password
RABBITMQ_DEFAULT_VHOST: /
ports:
- "5672:5672"
- "15672:15672"
volumes:
- ./docker-compose/rabbitmq/lib:/var/lib/rabbitmq/
- ./docker-compose/rabbitmq/log:/var/log/rabbitmq/
networks:
- hello-dapr
redis:
ports:
- "6380:6379"
networks:
- hello-dapr

39
src/docker-compose.yml Normal file
View File

@ -0,0 +1,39 @@
services:
publisher-dapr:
container_name: publisher-dapr
image: "daprio/daprd:edge"
publisher:
container_name: publisher
image: ${DOCKER_REGISTRY-}publisher
build:
context: .
dockerfile: Publisher/Dockerfile
subscriber-dapr:
container_name: subscriber-dapr
image: "daprio/daprd:edge"
subscriber:
container_name: subscriber
image: ${DOCKER_REGISTRY-}subscriber
build:
context: .
dockerfile: Subscriber/Dockerfile
placement:
container_name: placement
image: "daprio/dapr"
zipkin:
container_name: zipkin
image: openzipkin/zipkin
rabbitmq:
container_name: rabbitmq
image: rabbitmq:3.12.1-management-alpine
redis:
container_name: redis
image: redis:alpine

View File

@ -0,0 +1,21 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: pubsub
namespace: dapr-test
spec:
type: pubsub.rabbitmq
version: v1
metadata:
- name: connectionString
value: "amqp://admin:password@rabbitmq:5672"
- name: durable
value: "false"
- name: deletedWhenUnused
value: "false"
- name: autoAck
value: "true"
- name: reconnectWait
value: "0"
- name: concurrency
value: parallel

View File

@ -0,0 +1,13 @@
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: statestore
namespace: dapr-test
spec:
type: state.redis
version: v1
metadata:
- name: redisHost
value: redis:6379
- name: actorStateStore
value: "true"

View File

@ -0,0 +1,10 @@
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: daprConfig
namespace: default
spec:
tracing:
samplingRate: "1"
zipkin:
endpointAddress: "http://zipkin:9411/api/v2/spans"

12
src/launchSettings.json Normal file
View File

@ -0,0 +1,12 @@
{
"profiles": {
"Docker Compose": {
"commandName": "DockerCompose",
"commandVersion": "1.0",
"serviceActions": {
"publisher": "StartDebugging",
"subscriber": "StartDebugging"
}
}
}
}