diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..6528a51 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "csharpier": { + "version": "0.27.2", + "commands": [ + "dotnet-csharpier" + ] + } + } +} \ No newline at end of file diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100644 index 0000000..987d26a --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +LC_ALL=C + +local_branch="$(git rev-parse --abbrev-ref HEAD)" + +valid_branch_regex="^(dependabot|feature|fix|docs|style|refactor|perf|hotfix|test|chore|create)(\/[a-zA-Z0-9._-]+)+$" + +message="There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_regex. Your commit will be rejected. You should rename your branch to a valid name and try again." + +if [[ ! $local_branch =~ $valid_branch_regex ]] +then + echo "$message" + exit 1 +fi + +dotnet tool restore && dotnet csharpier . --check diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..dd84ea7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0735e0d..2b17f91 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,25 +1,31 @@ version: 2 + updates: -- package-ecosystem: "docker" - directory: "/" - schedule: - interval: weekly - open-pull-requests-limit: 10 - + - package-ecosystem: "nuget" directory: "/" schedule: interval: weekly - open-pull-requests-limit: 10 - -- package-ecosystem: "npm" - directory: "/" - schedule: - interval: weekly - open-pull-requests-limit: 10 - + open-pull-requests-limit: 50 + assignees: + - "guibranco" + reviewers: + - "guibranco" + labels: + - "nuget" + - "packages" + - ".NET" + - "dependencies" + - package-ecosystem: "github-actions" directory: "/" schedule: interval: weekly - open-pull-requests-limit: 10 + open-pull-requests-limit: 50 + assignees: + - "guibranco" + reviewers: + - "guibranco" + labels: + - "github-actions" + - "dependencies" diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..c111ab0 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,24 @@ +name: Linter check + +on: + workflow_dispatch: + pull_request: + +jobs: + linter-check: + runs-on: ubuntu-latest + steps: + + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + + - name: Dotnet restore + run: dotnet tool restore + + - name: Csharpier format check + run: | + dotnet csharpier . --check + echo "run 'dotnet build' to fix the formatting of the code automatically" diff --git a/.github/workflows/size-label.yml b/.github/workflows/size-label.yml new file mode 100644 index 0000000..90bd95b --- /dev/null +++ b/.github/workflows/size-label.yml @@ -0,0 +1,28 @@ +name: Label based on PR size + +on: + pull_request: + pull_request_target: + workflow_dispatch: + +jobs: + size-label: + permissions: write-all + runs-on: ubuntu-latest + + steps: + + - name: size-label + if: >- + ( + github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name == github.repository + ) || ( + github.event_name == 'pull_request_target' && + github.event.pull_request.head.repo.full_name != github.repository + ) || ( + github.event_name == 'workflow_dispatch' + ) + uses: "pascalgn/size-label-action@v0.5.0" + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index a2f79d2..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - // Use IntelliSense to find out which attributes exist for C# debugging - // Use hover for the description of the existing attributes - // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md - "name": ".NET Core Launch (console)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/Src/ReceiveLogs/bin/Debug/netcoreapp3.0/ReceiveLogs.dll", - "args": [], - "cwd": "${workspaceFolder}/Src/ReceiveLogs", - // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console - "console": "internalConsole", - "stopAtEntry": false - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach", - "processId": "${command:pickProcess}" - } - ] -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 1fdb0f0..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "command": "dotnet", - "type": "process", - "args": [ - "build", - "${workspaceFolder}/Src/ReceiveLogs/ReceiveLogs.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "publish", - "command": "dotnet", - "type": "process", - "args": [ - "publish", - "${workspaceFolder}/Src/ReceiveLogs/ReceiveLogs.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "watch", - "command": "dotnet", - "type": "process", - "args": [ - "watch", - "run", - "${workspaceFolder}/Src/ReceiveLogs/ReceiveLogs.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 0000000..8153833 --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,9 @@ + + + true + false + + + + + diff --git a/HelloWorldRabbitMQ.sln b/HelloWorldRabbitMQ.sln new file mode 100644 index 0000000..323a415 --- /dev/null +++ b/HelloWorldRabbitMQ.sln @@ -0,0 +1,93 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34525.116 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Src", "Src", "{E961E0F4-9F78-44C0-B141-994178170F58}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmitLog", "Src\EmitLog\EmitLog.csproj", "{6E823770-6DC1-4355-9155-AF856FF9FF10}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewTask", "Src\NewTask\NewTask.csproj", "{36830E15-927F-4136-84CA-1CD7F320C46E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NewTaskAck", "Src\NewTaskAck\NewTaskAck.csproj", "{2B067444-CB24-41C5-9605-D2FA53D09E8B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Receive", "Src\Receive\Receive.csproj", "{AA07E19F-C028-43CC-95ED-5C05AE5CEDF1}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReceiveLogs", "Src\ReceiveLogs\ReceiveLogs.csproj", "{99DEE5CA-3616-4811-97D7-FA23391B3AC4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcClient", "Src\RpcClient\RpcClient.csproj", "{60D3BF6C-AA16-4F48-B6E0-99572D3C332F}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcWorker", "Src\RpcWorker\RpcWorker.csproj", "{5E662B83-9E50-4647-B48E-C4635727AA48}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Send", "Src\Send\Send.csproj", "{30DE4BFE-D057-4EB9-B225-337B02969C11}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Worker", "Src\Worker\Worker.csproj", "{F9EF05D1-F808-43BA-8EE3-965E7C356336}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkerAck", "Src\WorkerAck\WorkerAck.csproj", "{CBC5FD37-2E9A-4720-830F-95AE16A0EACD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6E823770-6DC1-4355-9155-AF856FF9FF10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6E823770-6DC1-4355-9155-AF856FF9FF10}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6E823770-6DC1-4355-9155-AF856FF9FF10}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6E823770-6DC1-4355-9155-AF856FF9FF10}.Release|Any CPU.Build.0 = Release|Any CPU + {36830E15-927F-4136-84CA-1CD7F320C46E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {36830E15-927F-4136-84CA-1CD7F320C46E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {36830E15-927F-4136-84CA-1CD7F320C46E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {36830E15-927F-4136-84CA-1CD7F320C46E}.Release|Any CPU.Build.0 = Release|Any CPU + {2B067444-CB24-41C5-9605-D2FA53D09E8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2B067444-CB24-41C5-9605-D2FA53D09E8B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2B067444-CB24-41C5-9605-D2FA53D09E8B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2B067444-CB24-41C5-9605-D2FA53D09E8B}.Release|Any CPU.Build.0 = Release|Any CPU + {AA07E19F-C028-43CC-95ED-5C05AE5CEDF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AA07E19F-C028-43CC-95ED-5C05AE5CEDF1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AA07E19F-C028-43CC-95ED-5C05AE5CEDF1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AA07E19F-C028-43CC-95ED-5C05AE5CEDF1}.Release|Any CPU.Build.0 = Release|Any CPU + {99DEE5CA-3616-4811-97D7-FA23391B3AC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {99DEE5CA-3616-4811-97D7-FA23391B3AC4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {99DEE5CA-3616-4811-97D7-FA23391B3AC4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {99DEE5CA-3616-4811-97D7-FA23391B3AC4}.Release|Any CPU.Build.0 = Release|Any CPU + {60D3BF6C-AA16-4F48-B6E0-99572D3C332F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {60D3BF6C-AA16-4F48-B6E0-99572D3C332F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {60D3BF6C-AA16-4F48-B6E0-99572D3C332F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {60D3BF6C-AA16-4F48-B6E0-99572D3C332F}.Release|Any CPU.Build.0 = Release|Any CPU + {5E662B83-9E50-4647-B48E-C4635727AA48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5E662B83-9E50-4647-B48E-C4635727AA48}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5E662B83-9E50-4647-B48E-C4635727AA48}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5E662B83-9E50-4647-B48E-C4635727AA48}.Release|Any CPU.Build.0 = Release|Any CPU + {30DE4BFE-D057-4EB9-B225-337B02969C11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {30DE4BFE-D057-4EB9-B225-337B02969C11}.Debug|Any CPU.Build.0 = Debug|Any CPU + {30DE4BFE-D057-4EB9-B225-337B02969C11}.Release|Any CPU.ActiveCfg = Release|Any CPU + {30DE4BFE-D057-4EB9-B225-337B02969C11}.Release|Any CPU.Build.0 = Release|Any CPU + {F9EF05D1-F808-43BA-8EE3-965E7C356336}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F9EF05D1-F808-43BA-8EE3-965E7C356336}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F9EF05D1-F808-43BA-8EE3-965E7C356336}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F9EF05D1-F808-43BA-8EE3-965E7C356336}.Release|Any CPU.Build.0 = Release|Any CPU + {CBC5FD37-2E9A-4720-830F-95AE16A0EACD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CBC5FD37-2E9A-4720-830F-95AE16A0EACD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CBC5FD37-2E9A-4720-830F-95AE16A0EACD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CBC5FD37-2E9A-4720-830F-95AE16A0EACD}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {6E823770-6DC1-4355-9155-AF856FF9FF10} = {E961E0F4-9F78-44C0-B141-994178170F58} + {36830E15-927F-4136-84CA-1CD7F320C46E} = {E961E0F4-9F78-44C0-B141-994178170F58} + {2B067444-CB24-41C5-9605-D2FA53D09E8B} = {E961E0F4-9F78-44C0-B141-994178170F58} + {AA07E19F-C028-43CC-95ED-5C05AE5CEDF1} = {E961E0F4-9F78-44C0-B141-994178170F58} + {99DEE5CA-3616-4811-97D7-FA23391B3AC4} = {E961E0F4-9F78-44C0-B141-994178170F58} + {60D3BF6C-AA16-4F48-B6E0-99572D3C332F} = {E961E0F4-9F78-44C0-B141-994178170F58} + {5E662B83-9E50-4647-B48E-C4635727AA48} = {E961E0F4-9F78-44C0-B141-994178170F58} + {30DE4BFE-D057-4EB9-B225-337B02969C11} = {E961E0F4-9F78-44C0-B141-994178170F58} + {F9EF05D1-F808-43BA-8EE3-965E7C356336} = {E961E0F4-9F78-44C0-B141-994178170F58} + {CBC5FD37-2E9A-4720-830F-95AE16A0EACD} = {E961E0F4-9F78-44C0-B141-994178170F58} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D23A7951-8498-4403-8293-0828B60021C0} + EndGlobalSection +EndGlobal diff --git a/Src/.vscode/launch.json b/Src/.vscode/launch.json deleted file mode 100644 index 3981c86..0000000 --- a/Src/.vscode/launch.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - // Use IntelliSense to find out which attributes exist for C# debugging - // Use hover for the description of the existing attributes - // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md - "version": "0.2.0", - "configurations": [ - { - "name": ".NET Core Launch (console)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/ReceiveLogs/bin/Debug/netcoreapp3.0/ReceiveLogs.dll", - "args": [], - "cwd": "${workspaceFolder}/ReceiveLogs", - // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console - "console": "internalConsole", - "stopAtEntry": false - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach", - "processId": "${command:pickProcess}" - } - ] -} \ No newline at end of file diff --git a/Src/.vscode/tasks.json b/Src/.vscode/tasks.json deleted file mode 100644 index c755b46..0000000 --- a/Src/.vscode/tasks.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "command": "dotnet", - "type": "process", - "args": [ - "build", - "${workspaceFolder}/ReceiveLogs/ReceiveLogs.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "publish", - "command": "dotnet", - "type": "process", - "args": [ - "publish", - "${workspaceFolder}/ReceiveLogs/ReceiveLogs.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - }, - { - "label": "watch", - "command": "dotnet", - "type": "process", - "args": [ - "watch", - "run", - "${workspaceFolder}/ReceiveLogs/ReceiveLogs.csproj", - "/property:GenerateFullPaths=true", - "/consoleloggerparameters:NoSummary" - ], - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file diff --git a/Src/EmitLog/EmitLog.cs b/Src/EmitLog/EmitLog.cs index 0eadbab..d91216b 100644 --- a/Src/EmitLog/EmitLog.cs +++ b/Src/EmitLog/EmitLog.cs @@ -1,23 +1,27 @@ using System; -using RabbitMQ.Client; using System.Text; +using RabbitMQ.Client; + +namespace EmitLog; class EmitLog { public static void Main(string[] args) { var factory = new ConnectionFactory() { HostName = "localhost" }; - using(var connection = factory.CreateConnection()) - using(var channel = connection.CreateModel()) + using (var connection = factory.CreateConnection()) + using (var channel = connection.CreateModel()) { channel.ExchangeDeclare(exchange: "logs", type: ExchangeType.Fanout); var message = GetMessage(args); var body = Encoding.UTF8.GetBytes(message); - channel.BasicPublish(exchange: "logs", - routingKey: "", - basicProperties: null, - body: body); + channel.BasicPublish( + exchange: "logs", + routingKey: "", + basicProperties: null, + body: body + ); Console.WriteLine(" [x] Sent {0}", message); } @@ -27,8 +31,6 @@ public static void Main(string[] args) private static string GetMessage(string[] args) { - return ((args.Length > 0) - ? string.Join(" ", args) - : "info: Hello World!"); + return ((args.Length > 0) ? string.Join(" ", args) : "info: Hello World!"); } -} \ No newline at end of file +} diff --git a/Src/EmitLog/EmitLog.csproj b/Src/EmitLog/EmitLog.csproj index 9c78c0a..201fd49 100644 --- a/Src/EmitLog/EmitLog.csproj +++ b/Src/EmitLog/EmitLog.csproj @@ -2,11 +2,11 @@ Exe - netcoreapp3.0 + net8 - + diff --git a/Src/NewTask/NewTask.cs b/Src/NewTask/NewTask.cs index 930f3c9..fca78ee 100644 --- a/Src/NewTask/NewTask.cs +++ b/Src/NewTask/NewTask.cs @@ -1,37 +1,43 @@ using System; -using RabbitMQ.Client; using System.Text; +using RabbitMQ.Client; +namespace NewTask; -namespace NewTask +class NewTask { - class NewTask + static void Main(string[] args) { - static void Main(string[] args) + var factory = new ConnectionFactory() { HostName = "localhost" }; + using (var connection = factory.CreateConnection()) + using (var channel = connection.CreateModel()) { - var factory = new ConnectionFactory() { HostName = "localhost" }; - using(var connection = factory.CreateConnection()) - using(var channel = connection.CreateModel()) - { - channel.QueueDeclare(queue: "task_queue", durable: false, exclusive: false, autoDelete: false, arguments: null); + channel.QueueDeclare( + queue: "task_queue", + durable: false, + exclusive: false, + autoDelete: false, + arguments: null + ); - var message = GetMessage(args); - var body = Encoding.UTF8.GetBytes(message); + var message = GetMessage(args); + var body = Encoding.UTF8.GetBytes(message); - var properties = channel.CreateBasicProperties(); - channel.BasicPublish(exchange: "", - routingKey: "task_queue", - basicProperties: properties, - body: body); - } - - Console.WriteLine(" Press [enter] to exit."); - Console.ReadLine(); + var properties = channel.CreateBasicProperties(); + channel.BasicPublish( + exchange: "", + routingKey: "task_queue", + basicProperties: properties, + body: body + ); } - private static string GetMessage(string[] args) - { - return ((args.Length > 0) ? string.Join(" ", args) : "Hello World!"); - } + Console.WriteLine(" Press [enter] to exit."); + Console.ReadLine(); + } + + private static string GetMessage(string[] args) + { + return ((args.Length > 0) ? string.Join(" ", args) : "Hello World!"); } } diff --git a/Src/NewTask/NewTask.csproj b/Src/NewTask/NewTask.csproj index 9c78c0a..201fd49 100644 --- a/Src/NewTask/NewTask.csproj +++ b/Src/NewTask/NewTask.csproj @@ -2,11 +2,11 @@ Exe - netcoreapp3.0 + net8 - + diff --git a/Src/NewTaskAck/NewTaskAck.cs b/Src/NewTaskAck/NewTaskAck.cs index f94b5ab..5995e8f 100644 --- a/Src/NewTaskAck/NewTaskAck.cs +++ b/Src/NewTaskAck/NewTaskAck.cs @@ -1,39 +1,45 @@ using System; -using RabbitMQ.Client; using System.Text; +using RabbitMQ.Client; +namespace NewTaskAck; -namespace NewTaskAck +class NewTaskAck { - class NewTaskAck + static void Main(string[] args) { - static void Main(string[] args) + var factory = new ConnectionFactory() { HostName = "localhost" }; + using (var connection = factory.CreateConnection()) + using (var channel = connection.CreateModel()) { - var factory = new ConnectionFactory() { HostName = "localhost" }; - using(var connection = factory.CreateConnection()) - using(var channel = connection.CreateModel()) - { - channel.QueueDeclare(queue: "task_queue_ack", durable: true, exclusive: false, autoDelete: false, arguments: null); + channel.QueueDeclare( + queue: "task_queue_ack", + durable: true, + exclusive: false, + autoDelete: false, + arguments: null + ); - var message = GetMessage(args); - var body = Encoding.UTF8.GetBytes(message); + var message = GetMessage(args); + var body = Encoding.UTF8.GetBytes(message); - var properties = channel.CreateBasicProperties(); - properties.Persistent = true; + var properties = channel.CreateBasicProperties(); + properties.Persistent = true; - channel.BasicPublish(exchange: "", - routingKey: "task_queue_ack", - basicProperties: properties, - body: body); - } - - Console.WriteLine(" Press [enter] to exit."); - Console.ReadLine(); + channel.BasicPublish( + exchange: "", + routingKey: "task_queue_ack", + basicProperties: properties, + body: body + ); } - private static string GetMessage(string[] args) - { - return ((args.Length > 0) ? string.Join(" ", args) : "Hello World!"); - } + Console.WriteLine(" Press [enter] to exit."); + Console.ReadLine(); + } + + private static string GetMessage(string[] args) + { + return ((args.Length > 0) ? string.Join(" ", args) : "Hello World!"); } } diff --git a/Src/NewTaskAck/NewTaskAck.csproj b/Src/NewTaskAck/NewTaskAck.csproj index 9c78c0a..201fd49 100644 --- a/Src/NewTaskAck/NewTaskAck.csproj +++ b/Src/NewTaskAck/NewTaskAck.csproj @@ -2,11 +2,11 @@ Exe - netcoreapp3.0 + net8 - + diff --git a/Src/Receive/Receive.cs b/Src/Receive/Receive.cs index 0619aff..9ecf7ce 100644 --- a/Src/Receive/Receive.cs +++ b/Src/Receive/Receive.cs @@ -1,32 +1,37 @@ -using RabbitMQ.Client; -using RabbitMQ.Client.Events; -using System; +using System; using System.Text; +using RabbitMQ.Client; +using RabbitMQ.Client.Events; + +namespace Receive; -namespace Receive +class Receive { - class Receive + static void Main() { - static void Main(string[] args) + var factory = new ConnectionFactory() { HostName = "localhost" }; + using (var connection = factory.CreateConnection()) + using (var channel = connection.CreateModel()) { - var factory = new ConnectionFactory() { HostName = "localhost" }; - using(var connection = factory.CreateConnection()) - using(var channel = connection.CreateModel()) - { - channel.QueueDeclare(queue: "hello", durable: false, exclusive: false, autoDelete: false, arguments: null); + channel.QueueDeclare( + queue: "hello", + durable: false, + exclusive: false, + autoDelete: false, + arguments: null + ); - var consumer = new EventingBasicConsumer(channel); - consumer.Received += (model, ea) => - { - var body = ea.Body; - var message = Encoding.UTF8.GetString(body); - Console.WriteLine(" [x] Received {0}", message); - }; - channel.BasicConsume(queue: "hello", autoAck: true, consumer: consumer); + var consumer = new EventingBasicConsumer(channel); + consumer.Received += (_, ea) => + { + var body = ea.Body; + var message = Encoding.UTF8.GetString(body.ToArray()); + Console.WriteLine(" [x] Received {0}", message); + }; + channel.BasicConsume(queue: "hello", autoAck: true, consumer: consumer); - Console.WriteLine(" Press [enter] to exit."); - Console.ReadLine(); - } + Console.WriteLine(" Press [enter] to exit."); + Console.ReadLine(); } } } diff --git a/Src/Receive/Receive.csproj b/Src/Receive/Receive.csproj index 9c78c0a..201fd49 100644 --- a/Src/Receive/Receive.csproj +++ b/Src/Receive/Receive.csproj @@ -2,11 +2,11 @@ Exe - netcoreapp3.0 + net8 - + diff --git a/Src/ReceiveLogs/ReceiveLogs.cs b/Src/ReceiveLogs/ReceiveLogs.cs index ec09fff..f110af3 100644 --- a/Src/ReceiveLogs/ReceiveLogs.cs +++ b/Src/ReceiveLogs/ReceiveLogs.cs @@ -1,38 +1,36 @@ using System; +using System.Text; using RabbitMQ.Client; using RabbitMQ.Client.Events; -using System.Text; + +namespace ReceiveLogs; class ReceiveLogs { public static void Main() { var factory = new ConnectionFactory() { HostName = "localhost" }; - using(var connection = factory.CreateConnection()) - using(var channel = connection.CreateModel()) + using (var connection = factory.CreateConnection()) + using (var channel = connection.CreateModel()) { channel.ExchangeDeclare(exchange: "logs", type: ExchangeType.Fanout); var queueName = channel.QueueDeclare().QueueName; - channel.QueueBind(queue: queueName, - exchange: "logs", - routingKey: ""); + channel.QueueBind(queue: queueName, exchange: "logs", routingKey: ""); Console.WriteLine(" [*] Waiting for logs."); var consumer = new EventingBasicConsumer(channel); - consumer.Received += (model, ea) => + consumer.Received += (_, ea) => { var body = ea.Body; - var message = Encoding.UTF8.GetString(body); + var message = Encoding.UTF8.GetString(body.ToArray()); Console.WriteLine(" [x] {0}", message); }; - channel.BasicConsume(queue: queueName, - autoAck: true, - consumer: consumer); + channel.BasicConsume(queue: queueName, autoAck: true, consumer: consumer); Console.WriteLine(" Press [enter] to exit."); Console.ReadLine(); } } -} \ No newline at end of file +} diff --git a/Src/ReceiveLogs/ReceiveLogs.csproj b/Src/ReceiveLogs/ReceiveLogs.csproj index 9c78c0a..201fd49 100644 --- a/Src/ReceiveLogs/ReceiveLogs.csproj +++ b/Src/ReceiveLogs/ReceiveLogs.csproj @@ -2,11 +2,11 @@ Exe - netcoreapp3.0 + net8 - + diff --git a/Src/ReceiveLogs/ReceiveLogs.sln b/Src/ReceiveLogs/ReceiveLogs.sln deleted file mode 100644 index 0cfa098..0000000 --- a/Src/ReceiveLogs/ReceiveLogs.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30204.135 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReceiveLogs", "ReceiveLogs.csproj", "{1BEB3D20-D9FB-4FBC-8512-6887B690CCAD}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1BEB3D20-D9FB-4FBC-8512-6887B690CCAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1BEB3D20-D9FB-4FBC-8512-6887B690CCAD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1BEB3D20-D9FB-4FBC-8512-6887B690CCAD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1BEB3D20-D9FB-4FBC-8512-6887B690CCAD}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {4AA95007-A26C-4484-9736-A1EE957A34D2} - EndGlobalSection -EndGlobal diff --git a/Src/RpcClient/Domain/Order.cs b/Src/RpcClient/Domain/Order.cs index f88ac14..01144ed 100644 --- a/Src/RpcClient/Domain/Order.cs +++ b/Src/RpcClient/Domain/Order.cs @@ -1,58 +1,44 @@ -// *********************************************************************** -// Assembly : RpcClient -// Author : Guilherme Branco Stracini -// Created : 07-23-2020 -// -// Last Modified By : Guilherme Branco Stracini -// Last Modified On : 07-23-2020 -// *********************************************************************** -// -// Copyright (c) Guilherme Branco Stracini ME. All rights reserved. -// -// -// *********************************************************************** -using System; +using System; -namespace RpcClient.Domain +namespace RpcClient.Domain; + +/// +/// Class Order. +/// +public class Order { /// - /// Class Order. + /// Gets or sets the identifier. /// - public class Order - { - /// - /// Gets or sets the identifier. - /// - /// The identifier. - public long Id { get; set; } + /// The identifier. + public long Id { get; set; } - /// - /// Gets or sets the amount. - /// - /// The amount. - public decimal Amount { get; set; } + /// + /// Gets or sets the amount. + /// + /// The amount. + public decimal Amount { get; set; } - /// - /// Gets the status. - /// - /// The status. - public string Status => OrderStatus.ToString(); + /// + /// Gets the status. + /// + /// The status. + public string Status => OrderStatus.ToString(); - /// - /// Gets or sets the order status. - /// - /// The order status. - private OrderStatus OrderStatus { get; set; } + /// + /// Gets or sets the order status. + /// + /// The order status. + private OrderStatus OrderStatus { get; set; } - /// - /// Initializes a new instance of the class. - /// - /// The amount. - public Order(decimal amount) - { - Id = DateTime.Now.Ticks; - OrderStatus = OrderStatus.Processing; - Amount = amount; - } + /// + /// Initializes a new instance of the class. + /// + /// The amount. + public Order(decimal amount) + { + Id = DateTime.Now.Ticks; + OrderStatus = OrderStatus.Processing; + Amount = amount; } } diff --git a/Src/RpcClient/Domain/OrderStatus.cs b/Src/RpcClient/Domain/OrderStatus.cs index 5c9de0f..01ba0c4 100644 --- a/Src/RpcClient/Domain/OrderStatus.cs +++ b/Src/RpcClient/Domain/OrderStatus.cs @@ -1,36 +1,22 @@ -// *********************************************************************** -// Assembly : RpcClient -// Author : Guilherme Branco Stracini -// Created : 07-23-2020 -// -// Last Modified By : Guilherme Branco Stracini -// Last Modified On : 07-23-2020 -// *********************************************************************** -// -// Copyright (c) Guilherme Branco Stracini ME. All rights reserved. -// -// -// *********************************************************************** -namespace RpcClient.Domain +namespace RpcClient.Domain; + +/// +/// Enum OrderStatus +/// +public enum OrderStatus { /// - /// Enum OrderStatus + /// The processing /// - public enum OrderStatus - { - /// - /// The processing - /// - Processing = 0, + Processing = 0, - /// - /// The approved - /// - Approved, + /// + /// The approved + /// + Approved, - /// - /// The declined - /// - Declined - } + /// + /// The declined + /// + Declined } diff --git a/Src/RpcClient/Program.cs b/Src/RpcClient/Program.cs index f8f63ef..12f8827 100644 --- a/Src/RpcClient/Program.cs +++ b/Src/RpcClient/Program.cs @@ -1,131 +1,133 @@ -// *********************************************************************** -// Assembly : RpcClient -// Author : Guilherme Branco Stracini -// Created : 07-23-2020 -// -// Last Modified By : Guilherme Branco Stracini -// Last Modified On : 07-23-2020 -// *********************************************************************** -// -// Copyright (c) Guilherme Branco Stracini ME. All rights reserved. -// -// -// *********************************************************************** +using System; +using System.Text; +using System.Text.Json; using RabbitMQ.Client; using RabbitMQ.Client.Events; using RpcClient.Domain; -using System; -using System.Text; -using System.Text.Json; -namespace RpcClient +namespace RpcClient; + +/// +/// Class Program. +/// +static class Program { /// - /// Class Program. + /// Defines the entry point of the application. /// - class Program + private static void Main() { - /// - /// Defines the entry point of the application. - /// - private static void Main() - { - var factory = new ConnectionFactory { HostName = "localhost" }; - - using var connection = factory.CreateConnection(); - using var channel = connection.CreateModel(); - - var replyQueue = $"{nameof(Order)}_return"; - var correlationId = Guid.NewGuid().ToString(); - - channel.QueueDeclare(queue: replyQueue, durable: false, exclusive: false, autoDelete: false, arguments: null); - channel.QueueDeclare(queue: nameof(Order), durable: false, exclusive: false, autoDelete: false, arguments: null); - - Consumer(channel, correlationId, replyQueue); - - Publisher(channel, correlationId, replyQueue); - } + var factory = new ConnectionFactory { HostName = "localhost" }; + + using var connection = factory.CreateConnection(); + using var channel = connection.CreateModel(); + + var replyQueue = $"{nameof(Order)}_return"; + var correlationId = Guid.NewGuid().ToString(); + + channel.QueueDeclare( + queue: replyQueue, + durable: false, + exclusive: false, + autoDelete: false, + arguments: null + ); + channel.QueueDeclare( + queue: nameof(Order), + durable: false, + exclusive: false, + autoDelete: false, + arguments: null + ); + + Consumer(channel, correlationId, replyQueue); + + Publisher(channel, correlationId, replyQueue); + } - /// - /// Consumers the specified channel. - /// - /// The channel. - /// The correlation identifier. - /// The reply queue. - private static void Consumer(IModel channel, string correlationId, string replyQueue) + /// + /// Consumers the specified channel. + /// + /// The channel. + /// The correlation identifier. + /// The reply queue. + private static void Consumer(IModel channel, string correlationId, string replyQueue) + { + var consumer = new EventingBasicConsumer(channel); + consumer.Received += (_, ea) => { - var consumer = new EventingBasicConsumer(channel); - consumer.Received += (model, ea) => + if (correlationId == ea.BasicProperties.CorrelationId) { - if (correlationId == ea.BasicProperties.CorrelationId) - { - var body = ea.Body.ToArray(); - var message = Encoding.UTF8.GetString(body); - Console.WriteLine($"Received: {message}"); + var body = ea.Body.ToArray(); + var message = Encoding.UTF8.GetString(body); + Console.WriteLine($"Received: {message}"); - return; - } + return; + } - Console.WriteLine( - $"Discarded message, invalid correlation identifiers. Original: {correlationId} | Received: {ea.BasicProperties.CorrelationId}"); - }; + Console.WriteLine( + $"Discarded message, invalid correlation identifiers. Original: {correlationId} | Received: {ea.BasicProperties.CorrelationId}" + ); + }; - channel.BasicConsume(queue: replyQueue, autoAck: true, consumer: consumer); - } + channel.BasicConsume(queue: replyQueue, autoAck: true, consumer: consumer); + } - /// - /// Publishers the specified channel. - /// - /// The channel. - /// The correlation identifier. - /// The reply queue. - private static void Publisher(IModel channel, string correlationId, string replyQueue) - { - var props = channel.CreateBasicProperties(); + /// + /// Publishers the specified channel. + /// + /// The channel. + /// The correlation identifier. + /// The reply queue. + private static void Publisher(IModel channel, string correlationId, string replyQueue) + { + var props = channel.CreateBasicProperties(); - props.CorrelationId = correlationId; - props.ReplyTo = replyQueue; + props.CorrelationId = correlationId; + props.ReplyTo = replyQueue; - while (true) - { - var body = GetOrder(); + while (true) + { + var body = GetOrder(); - if (body == null) - continue; + if (body == null) + continue; - channel.BasicPublish(exchange: "", routingKey: nameof(Order), basicProperties: props, body: body); + channel.BasicPublish( + exchange: "", + routingKey: nameof(Order), + basicProperties: props, + body: body + ); - Console.WriteLine($"Published\r\n"); + Console.WriteLine($"Published\r\n"); - var key = Console.ReadKey(); + var key = Console.ReadKey(); - if (key.Key == ConsoleKey.C) - break; + if (key.Key == ConsoleKey.C) + break; - Console.Clear(); - } + Console.Clear(); } + } - /// - /// Gets the order. - /// - /// System.Byte[]. - private static byte[] GetOrder() - { - - Console.Write("Informe o valor do pedido:"); - - var line = Console.ReadLine(); + /// + /// Gets the order. + /// + /// System.Byte[]. + private static byte[] GetOrder() + { + Console.Write("Informe o valor do pedido:"); - if (string.IsNullOrWhiteSpace(line)) - return null; + var line = Console.ReadLine(); - var amount = decimal.Parse(line); + if (string.IsNullOrWhiteSpace(line)) + return null; - var order = new Order(amount); - var message = JsonSerializer.Serialize(order); - return Encoding.UTF8.GetBytes(message); + var amount = decimal.Parse(line); - } + var order = new Order(amount); + var message = JsonSerializer.Serialize(order); + return Encoding.UTF8.GetBytes(message); } } diff --git a/Src/RpcClient/RpcClient.csproj b/Src/RpcClient/RpcClient.csproj index 4dd2904..182cf9a 100644 --- a/Src/RpcClient/RpcClient.csproj +++ b/Src/RpcClient/RpcClient.csproj @@ -2,11 +2,11 @@ Exe - netcoreapp3.1 + net8 - + diff --git a/Src/RpcClient/RpcClient.sln b/Src/RpcClient/RpcClient.sln deleted file mode 100644 index 2d6ae15..0000000 --- a/Src/RpcClient/RpcClient.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30309.148 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcClient", "RpcClient.csproj", "{382DE2DD-27E1-4BE1-81A7-79C060C8C5D7}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {382DE2DD-27E1-4BE1-81A7-79C060C8C5D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {382DE2DD-27E1-4BE1-81A7-79C060C8C5D7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {382DE2DD-27E1-4BE1-81A7-79C060C8C5D7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {382DE2DD-27E1-4BE1-81A7-79C060C8C5D7}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {A27FD27E-C80B-4F5C-A629-44D680300A59} - EndGlobalSection -EndGlobal diff --git a/Src/RpcWorker/Domain/Order.cs b/Src/RpcWorker/Domain/Order.cs index cf2b558..ca9bd6f 100644 --- a/Src/RpcWorker/Domain/Order.cs +++ b/Src/RpcWorker/Domain/Order.cs @@ -12,41 +12,40 @@ // // *********************************************************************** -namespace RpcWorker.Domain +namespace RpcWorker.Domain; + +/// +/// Class Order. +/// +public class Order { /// - /// Class Order. + /// Gets or sets the identifier. /// - public class Order - { - /// - /// Gets or sets the identifier. - /// - /// The identifier. - public long Id { get; set; } + /// The identifier. + public long Id { get; set; } - /// - /// Gets or sets the amount. - /// - /// The amount. - public decimal Amount { get; set; } + /// + /// Gets or sets the amount. + /// + /// The amount. + public decimal Amount { get; set; } - /// - /// Gets the status. - /// - /// The status. - public string Status => OrderStatus.ToString(); + /// + /// Gets the status. + /// + /// The status. + public string Status => OrderStatus.ToString(); - /// - /// Gets or sets the order status. - /// - /// The order status. - private OrderStatus OrderStatus { get; set; } + /// + /// Gets or sets the order status. + /// + /// The order status. + private OrderStatus OrderStatus { get; set; } - /// - /// Sets the status. - /// - /// The order status. - public void SetStatus(OrderStatus orderStatus) => OrderStatus = orderStatus; - } + /// + /// Sets the status. + /// + /// The order status. + public void SetStatus(OrderStatus orderStatus) => OrderStatus = orderStatus; } diff --git a/Src/RpcWorker/Domain/OrderStatus.cs b/Src/RpcWorker/Domain/OrderStatus.cs index 6e56879..ca27c5a 100644 --- a/Src/RpcWorker/Domain/OrderStatus.cs +++ b/Src/RpcWorker/Domain/OrderStatus.cs @@ -1,36 +1,22 @@ -// *********************************************************************** -// Assembly : RpcWorker -// Author : Guilherme Branco Stracini -// Created : 07-23-2020 -// -// Last Modified By : Guilherme Branco Stracini -// Last Modified On : 07-23-2020 -// *********************************************************************** -// -// Copyright (c) Guilherme Branco Stracini ME. All rights reserved. -// -// -// *********************************************************************** -namespace RpcWorker.Domain +namespace RpcWorker.Domain; + +/// +/// Enum OrderStatus +/// +public enum OrderStatus { /// - /// Enum OrderStatus + /// The processing /// - public enum OrderStatus - { - /// - /// The processing - /// - Processing = 0, + Processing = 0, - /// - /// The approved - /// - Approved, + /// + /// The approved + /// + Approved, - /// - /// The declined - /// - Declined - } + /// + /// The declined + /// + Declined } diff --git a/Src/RpcWorker/Program.cs b/Src/RpcWorker/Program.cs index 1ac5a88..1217b0b 100644 --- a/Src/RpcWorker/Program.cs +++ b/Src/RpcWorker/Program.cs @@ -1,122 +1,122 @@ -// *********************************************************************** -// Assembly : RpcWorker -// Author : Guilherme Branco Stracini -// Created : 07-23-2020 -// -// Last Modified By : Guilherme Branco Stracini -// Last Modified On : 07-23-2020 -// *********************************************************************** -// -// Copyright (c) Guilherme Branco Stracini ME. All rights reserved. -// -// -// *********************************************************************** +using System; +using System.Text; +using System.Text.Json; using RabbitMQ.Client; using RabbitMQ.Client.Events; using RpcWorker.Domain; using RpcWorker.Services; -using System; -using System.Text; -using System.Text.Json; -namespace RpcWorker +namespace RpcWorker; + +/// +/// Class Program. +/// +class Program { /// - /// Class Program. + /// Defines the entry point of the application. /// - class Program + static void Main() { - /// - /// Defines the entry point of the application. - /// - static void Main() - { - var factory = new ConnectionFactory { HostName = "localhost" }; + var factory = new ConnectionFactory { HostName = "localhost" }; - using var connection = factory.CreateConnection(); - using var channel = connection.CreateModel(); + using var connection = factory.CreateConnection(); + using var channel = connection.CreateModel(); - Consumer(channel); + Consumer(channel); + Console.ReadLine(); + } - Console.ReadLine(); - } + /// + /// Consumers the specified channel. + /// + /// The channel. + private static void Consumer(IModel channel) + { + var consumer = InitializerConsumer(channel, nameof(Order)); - /// - /// Consumers the specified channel. - /// - /// The channel. - private static void Consumer(IModel channel) + consumer.Received += (_, ea) => { - var consumer = InitializerConsumer(channel, nameof(Order)); + try + { + var incomingMessage = Encoding.UTF8.GetString(ea.Body.ToArray()); + Console.WriteLine($"{DateTime.Now:o} Incoming => {incomingMessage}"); + + var order = JsonSerializer.Deserialize(incomingMessage); + order.SetStatus(ProcessOrderStatus(order.Amount)); - consumer.Received += (model, ea) => + var replyMessage = JsonSerializer.Serialize(order); + Console.WriteLine($"{DateTime.Now:o} Reply => {replyMessage}"); + + SendReplyMessage(replyMessage, channel, ea); + } + catch { - try - { - var incomingMessage = Encoding.UTF8.GetString(ea.Body.ToArray()); - Console.WriteLine($"{DateTime.Now:o} Incoming => {incomingMessage}"); - - var order = JsonSerializer.Deserialize(incomingMessage); - order.SetStatus(ProcessOrderStatus(order.Amount)); - - var replyMessage = JsonSerializer.Serialize(order); - Console.WriteLine($"{DateTime.Now:o} Reply => {replyMessage}"); - - SendReplyMessage(replyMessage, channel, ea); - } - catch - { - Console.WriteLine($"Error {ea.DeliveryTag}"); - } - }; - } - - /// - /// Processes the order status. - /// - /// The amount. - /// OrderStatus. - private static OrderStatus ProcessOrderStatus(decimal amount) - { - return OrderServices.OnStore(amount); - } - - /// - /// Sends the reply message. - /// - /// The reply message. - /// The channel. - /// The instance containing the event data. - private static void SendReplyMessage(string replyMessage, IModel channel, BasicDeliverEventArgs ea) - { - var props = ea.BasicProperties; - var replyProps = channel.CreateBasicProperties(); - replyProps.CorrelationId = props.CorrelationId; + Console.WriteLine($"Error {ea.DeliveryTag}"); + } + }; + } - var responseBytes = Encoding.UTF8.GetBytes(replyMessage); + /// + /// Processes the order status. + /// + /// The amount. + /// OrderStatus. + private static OrderStatus ProcessOrderStatus(decimal amount) + { + return OrderServices.OnStore(amount); + } - channel.BasicPublish(exchange: "", routingKey: props.ReplyTo, basicProperties: replyProps, body: responseBytes); + /// + /// Sends the reply message. + /// + /// The reply message. + /// The channel. + /// The instance containing the event data. + private static void SendReplyMessage( + string replyMessage, + IModel channel, + BasicDeliverEventArgs ea + ) + { + var props = ea.BasicProperties; + var replyProps = channel.CreateBasicProperties(); + replyProps.CorrelationId = props.CorrelationId; - channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false); - } + var responseBytes = Encoding.UTF8.GetBytes(replyMessage); - /// - /// Initializers the consumer. - /// - /// The channel. - /// Name of the queue. - /// EventingBasicConsumer. - private static EventingBasicConsumer InitializerConsumer(IModel channel, string queueName) - { - channel.QueueDeclare(queue: queueName, durable: false, exclusive: false, autoDelete: false, arguments: null); + channel.BasicPublish( + exchange: "", + routingKey: props.ReplyTo, + basicProperties: replyProps, + body: responseBytes + ); + + channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false); + } + + /// + /// Initializers the consumer. + /// + /// The channel. + /// Name of the queue. + /// EventingBasicConsumer. + private static EventingBasicConsumer InitializerConsumer(IModel channel, string queueName) + { + channel.QueueDeclare( + queue: queueName, + durable: false, + exclusive: false, + autoDelete: false, + arguments: null + ); - channel.BasicQos(0, 1, false); + channel.BasicQos(0, 1, false); - var consumer = new EventingBasicConsumer(channel); - channel.BasicConsume(queue: queueName, autoAck: false, consumer: consumer); + var consumer = new EventingBasicConsumer(channel); + channel.BasicConsume(queue: queueName, autoAck: false, consumer: consumer); - return consumer; - } + return consumer; } } diff --git a/Src/RpcWorker/RpcWorker.csproj b/Src/RpcWorker/RpcWorker.csproj index 4dd2904..182cf9a 100644 --- a/Src/RpcWorker/RpcWorker.csproj +++ b/Src/RpcWorker/RpcWorker.csproj @@ -2,11 +2,11 @@ Exe - netcoreapp3.1 + net8 - + diff --git a/Src/RpcWorker/RpcWorker.sln b/Src/RpcWorker/RpcWorker.sln deleted file mode 100644 index deeafb1..0000000 --- a/Src/RpcWorker/RpcWorker.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30309.148 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RpcWorker", "RpcWorker.csproj", "{2D42A83F-B38F-4413-A33B-D2432F9164EC}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {2D42A83F-B38F-4413-A33B-D2432F9164EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2D42A83F-B38F-4413-A33B-D2432F9164EC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2D42A83F-B38F-4413-A33B-D2432F9164EC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2D42A83F-B38F-4413-A33B-D2432F9164EC}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {D4DFCD27-803E-4668-974A-C8FF0A2AEB07} - EndGlobalSection -EndGlobal diff --git a/Src/RpcWorker/Services/OrderServices.cs b/Src/RpcWorker/Services/OrderServices.cs index f370bc4..6735316 100644 --- a/Src/RpcWorker/Services/OrderServices.cs +++ b/Src/RpcWorker/Services/OrderServices.cs @@ -1,33 +1,19 @@ -// *********************************************************************** -// Assembly : -// Author : Guilherme Branco Stracini -// Created : 07-23-2020 -// -// Last Modified By : Guilherme Branco Stracini -// Last Modified On : 07-23-2020 -// *********************************************************************** -// -// Copyright (c) Guilherme Branco Stracini ME. All rights reserved. -// -// -// *********************************************************************** -using RpcWorker.Domain; +using RpcWorker.Domain; -namespace RpcWorker.Services +namespace RpcWorker.Services; + +/// +/// Class OrderServices. This class cannot be inherited. +/// +public sealed class OrderServices { /// - /// Class OrderServices. This class cannot be inherited. + /// Called when [store]. /// - public sealed class OrderServices + /// The amount. + /// OrderStatus. + public static OrderStatus OnStore(decimal amount) { - /// - /// Called when [store]. - /// - /// The amount. - /// OrderStatus. - public static OrderStatus OnStore(decimal amount) - { - return (amount < 0 || amount > 10000) ? OrderStatus.Declined : OrderStatus.Approved; - } + return (amount < 0 || amount > 10000) ? OrderStatus.Declined : OrderStatus.Approved; } } diff --git a/Src/Send/Send.cs b/Src/Send/Send.cs index d9b6f94..32f695b 100644 --- a/Src/Send/Send.cs +++ b/Src/Send/Send.cs @@ -1,28 +1,38 @@ using System; -using RabbitMQ.Client; using System.Text; +using RabbitMQ.Client; + +namespace Send; -namespace Send +class Send { - class Send + static void Main() { - static void Main(string[] args) + var factory = new ConnectionFactory() { HostName = "localhost" }; + using (var connection = factory.CreateConnection()) + using (var channel = connection.CreateModel()) { - var factory = new ConnectionFactory() { HostName = "localhost" }; - using(var connection = factory.CreateConnection()) - using(var channel = connection.CreateModel()) - { - channel.QueueDeclare(queue: "hello", durable: false, exclusive: false, autoDelete: false, arguments: null); + channel.QueueDeclare( + queue: "hello", + durable: false, + exclusive: false, + autoDelete: false, + arguments: null + ); - string message = "Hello World!"; - var body = Encoding.UTF8.GetBytes(message); + string message = "Hello World!"; + var body = Encoding.UTF8.GetBytes(message); - channel.BasicPublish(exchange: "", routingKey: "hello", basicProperties: null, body: body); - Console.WriteLine(" [x] Sent {0}", message); - } - - Console.WriteLine(" Press [enter] to exit."); - Console.ReadLine(); + channel.BasicPublish( + exchange: "", + routingKey: "hello", + basicProperties: null, + body: body + ); + Console.WriteLine(" [x] Sent {0}", message); } + + Console.WriteLine(" Press [enter] to exit."); + Console.ReadLine(); } } diff --git a/Src/Send/Send.csproj b/Src/Send/Send.csproj index 9c78c0a..201fd49 100644 --- a/Src/Send/Send.csproj +++ b/Src/Send/Send.csproj @@ -2,11 +2,11 @@ Exe - netcoreapp3.0 + net8 - + diff --git a/Src/Worker/Worker.cs b/Src/Worker/Worker.cs index 7959468..b6f23cc 100644 --- a/Src/Worker/Worker.cs +++ b/Src/Worker/Worker.cs @@ -1,38 +1,43 @@ -using RabbitMQ.Client; -using RabbitMQ.Client.Events; -using System; +using System; using System.Text; using System.Threading; +using RabbitMQ.Client; +using RabbitMQ.Client.Events; + +namespace Worker; -namespace Worker +class Worker { - class Worker + static void Main() { - static void Main(string[] args) + var factory = new ConnectionFactory() { HostName = "localhost" }; + using (var connection = factory.CreateConnection()) + using (var channel = connection.CreateModel()) { - var factory = new ConnectionFactory() { HostName = "localhost" }; - using(var connection = factory.CreateConnection()) - using(var channel = connection.CreateModel()) - { - channel.QueueDeclare(queue: "task_queue", durable: false, exclusive: false, autoDelete: false, arguments: null); + channel.QueueDeclare( + queue: "task_queue", + durable: false, + exclusive: false, + autoDelete: false, + arguments: null + ); - var consumer = new EventingBasicConsumer(channel); - consumer.Received += (model, ea) => - { - var body = ea.Body; - var message = Encoding.UTF8.GetString(body); - Console.WriteLine(" [x] Received {0}", message); + var consumer = new EventingBasicConsumer(channel); + consumer.Received += (_, ea) => + { + var body = ea.Body; + var message = Encoding.UTF8.GetString(body.ToArray()); + Console.WriteLine(" [x] Received {0}", message); - int dots = message.Split('.').Length - 1; - Thread.Sleep(dots * 1000); + int dots = message.Split('.').Length - 1; + Thread.Sleep(dots * 1000); - Console.WriteLine(" [x] Done"); - }; - channel.BasicConsume(queue: "task_queue", autoAck: true, consumer: consumer); + Console.WriteLine(" [x] Done"); + }; + channel.BasicConsume(queue: "task_queue", autoAck: true, consumer: consumer); - Console.WriteLine(" Press [enter] to exit."); - Console.ReadLine(); - } + Console.WriteLine(" Press [enter] to exit."); + Console.ReadLine(); } } } diff --git a/Src/Worker/Worker.csproj b/Src/Worker/Worker.csproj index 9c78c0a..201fd49 100644 --- a/Src/Worker/Worker.csproj +++ b/Src/Worker/Worker.csproj @@ -2,11 +2,11 @@ Exe - netcoreapp3.0 + net8 - + diff --git a/Src/WorkerAck/WorkerAck.cs b/Src/WorkerAck/WorkerAck.cs index aca0d96..51f3973 100644 --- a/Src/WorkerAck/WorkerAck.cs +++ b/Src/WorkerAck/WorkerAck.cs @@ -1,42 +1,47 @@ -using RabbitMQ.Client; -using RabbitMQ.Client.Events; -using System; +using System; using System.Text; using System.Threading; +using RabbitMQ.Client; +using RabbitMQ.Client.Events; + +namespace WorkerAck; -namespace Worker +static class WorkerAck { - class WorkerAck + static void Main() { - static void Main(string[] args) + var factory = new ConnectionFactory() { HostName = "localhost" }; + using (var connection = factory.CreateConnection()) + using (var channel = connection.CreateModel()) { - var factory = new ConnectionFactory() { HostName = "localhost" }; - using(var connection = factory.CreateConnection()) - using(var channel = connection.CreateModel()) - { - channel.QueueDeclare(queue: "task_queue_ack", durable: true, exclusive: false, autoDelete: false, arguments: null); + channel.QueueDeclare( + queue: "task_queue_ack", + durable: true, + exclusive: false, + autoDelete: false, + arguments: null + ); - channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false); + channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false); - var consumer = new EventingBasicConsumer(channel); - consumer.Received += (model, ea) => - { - var body = ea.Body; - var message = Encoding.UTF8.GetString(body); - Console.WriteLine(" [x] Received {0}", message); + var consumer = new EventingBasicConsumer(channel); + consumer.Received += (_, ea) => + { + var body = ea.Body; + var message = Encoding.UTF8.GetString(body.ToArray()); + Console.WriteLine(" [x] Received {0}", message); - int dots = message.Split('.').Length - 1; - Thread.Sleep(dots * 1000); + int dots = message.Split('.').Length - 1; + Thread.Sleep(dots * 1000); - Console.WriteLine(" [x] Done"); + Console.WriteLine(" [x] Done"); - channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false); - }; - channel.BasicConsume(queue: "task_queue_ack", autoAck: false, consumer: consumer); + channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false); + }; + channel.BasicConsume(queue: "task_queue_ack", autoAck: false, consumer: consumer); - Console.WriteLine(" Press [enter] to exit."); - Console.ReadLine(); - } + Console.WriteLine(" Press [enter] to exit."); + Console.ReadLine(); } } } diff --git a/Src/WorkerAck/WorkerAck.csproj b/Src/WorkerAck/WorkerAck.csproj index 3fd0635..b4ffffd 100644 --- a/Src/WorkerAck/WorkerAck.csproj +++ b/Src/WorkerAck/WorkerAck.csproj @@ -2,11 +2,11 @@ Exe - netcoreapp3.0 + net8 - +