├── .DS_Store ├── .editorconfig ├── .gitignore ├── Orders.sln ├── readme.md └── src ├── .DS_Store ├── Orders.Api ├── .DS_Store ├── Controllers │ └── OrdersController.cs ├── Handlers │ └── ProcessOrderHandler.cs ├── Orders.Api.csproj ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json └── appsettings.json ├── Orders.Application ├── Boundaries │ └── PlaceOrder │ │ ├── IPlaceOrderUseCase.cs │ │ ├── IProcessOrderUseCase.cs │ │ └── PlaceOrderInput.cs ├── Orders.Application.csproj ├── Services │ └── IPublisher.cs └── UseCases │ ├── PlaceOrder.cs │ └── ProcessOrder.cs ├── Orders.Domain ├── .DS_Store └── Orders.Domain.csproj ├── Orders.Infrastructure ├── .DS_Store ├── Orders.Infrastructure.csproj └── RabbitMQ │ └── RabbitMQBus.cs ├── Orders.Worker ├── Orders.Worker.csproj ├── Program.cs ├── Worker.cs ├── appsettings.Development.json └── appsettings.json └── scripts └── setup-rabbitmq.sh /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivanpaulovich/webapi-backgroundworker-rabbitmq/b431b2e5c4ccfaf2aa1f74f2763678f7268f027b/.DS_Store -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Default settings: 7 | # A newline ending every file 8 | # Use 4 spaces as indentation 9 | [*] 10 | insert_final_newline = true 11 | indent_style = space 12 | indent_size = 4 13 | trim_trailing_whitespace = true 14 | 15 | [project.json] 16 | indent_size = 2 17 | 18 | # C# files 19 | [*.cs] 20 | # New line preferences 21 | csharp_new_line_before_open_brace = all 22 | csharp_new_line_before_else = true 23 | csharp_new_line_before_catch = true 24 | csharp_new_line_before_finally = true 25 | csharp_new_line_before_members_in_object_initializers = true 26 | csharp_new_line_before_members_in_anonymous_types = true 27 | csharp_new_line_between_query_expression_clauses = true 28 | 29 | # Indentation preferences 30 | csharp_indent_block_contents = true 31 | csharp_indent_braces = false 32 | csharp_indent_case_contents = true 33 | csharp_indent_case_contents_when_block = true 34 | csharp_indent_switch_labels = true 35 | csharp_indent_labels = one_less_than_current 36 | 37 | # Modifier preferences 38 | csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion 39 | 40 | # avoid this. unless absolutely necessary 41 | dotnet_style_qualification_for_field = false:suggestion 42 | dotnet_style_qualification_for_property = false:suggestion 43 | dotnet_style_qualification_for_method = false:suggestion 44 | dotnet_style_qualification_for_event = false:suggestion 45 | 46 | # Types: use keywords instead of BCL types, and permit var only when the type is clear 47 | csharp_style_var_for_built_in_types = false:suggestion 48 | csharp_style_var_when_type_is_apparent = false:none 49 | csharp_style_var_elsewhere = false:suggestion 50 | dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion 51 | dotnet_style_predefined_type_for_member_access = true:suggestion 52 | 53 | # name all constant fields using PascalCase 54 | dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion 55 | dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields 56 | dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style 57 | dotnet_naming_symbols.constant_fields.applicable_kinds = field 58 | dotnet_naming_symbols.constant_fields.required_modifiers = const 59 | dotnet_naming_style.pascal_case_style.capitalization = pascal_case 60 | 61 | # static fields should have s_ prefix 62 | dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion 63 | dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields 64 | dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style 65 | dotnet_naming_symbols.static_fields.applicable_kinds = field 66 | dotnet_naming_symbols.static_fields.required_modifiers = static 67 | dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected 68 | dotnet_naming_style.static_prefix_style.required_prefix = s_ 69 | dotnet_naming_style.static_prefix_style.capitalization = camel_case 70 | 71 | # internal and private fields should be _camelCase 72 | dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion 73 | dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields 74 | dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style 75 | dotnet_naming_symbols.private_internal_fields.applicable_kinds = field 76 | dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal 77 | dotnet_naming_style.camel_case_underscore_style.required_prefix = _ 78 | dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case 79 | 80 | # Code style defaults 81 | csharp_using_directive_placement = outside_namespace:suggestion 82 | dotnet_sort_system_directives_first = true 83 | csharp_prefer_braces = true:refactoring 84 | csharp_preserve_single_line_blocks = true:none 85 | csharp_preserve_single_line_statements = false:none 86 | csharp_prefer_static_local_function = true:suggestion 87 | csharp_prefer_simple_using_statement = false:none 88 | csharp_style_prefer_switch_expression = true:suggestion 89 | 90 | # Code quality 91 | dotnet_style_readonly_field = true:suggestion 92 | dotnet_code_quality_unused_parameters = non_public:suggestion 93 | 94 | # Expression-level preferences 95 | dotnet_style_object_initializer = true:suggestion 96 | dotnet_style_collection_initializer = true:suggestion 97 | dotnet_style_explicit_tuple_names = true:suggestion 98 | dotnet_style_coalesce_expression = true:suggestion 99 | dotnet_style_null_propagation = true:suggestion 100 | dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion 101 | dotnet_style_prefer_inferred_tuple_names = true:suggestion 102 | dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion 103 | dotnet_style_prefer_auto_properties = true:suggestion 104 | dotnet_style_prefer_conditional_expression_over_assignment = true:refactoring 105 | dotnet_style_prefer_conditional_expression_over_return = true:refactoring 106 | csharp_prefer_simple_default_expression = true:suggestion 107 | 108 | # Expression-bodied members 109 | csharp_style_expression_bodied_methods = true:refactoring 110 | csharp_style_expression_bodied_constructors = true:refactoring 111 | csharp_style_expression_bodied_operators = true:refactoring 112 | csharp_style_expression_bodied_properties = true:refactoring 113 | csharp_style_expression_bodied_indexers = true:refactoring 114 | csharp_style_expression_bodied_accessors = true:refactoring 115 | csharp_style_expression_bodied_lambdas = true:refactoring 116 | csharp_style_expression_bodied_local_functions = true:refactoring 117 | 118 | # Pattern matching 119 | csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion 120 | csharp_style_pattern_matching_over_as_with_null_check = true:suggestion 121 | csharp_style_inlined_variable_declaration = true:suggestion 122 | 123 | # Null checking preferences 124 | csharp_style_throw_expression = true:suggestion 125 | csharp_style_conditional_delegate_call = true:suggestion 126 | 127 | # Other features 128 | csharp_style_prefer_index_operator = false:none 129 | csharp_style_prefer_range_operator = false:none 130 | csharp_style_pattern_local_over_anonymous_function = false:none 131 | 132 | # Space preferences 133 | csharp_space_after_cast = false 134 | csharp_space_after_colon_in_inheritance_clause = true 135 | csharp_space_after_comma = true 136 | csharp_space_after_dot = false 137 | csharp_space_after_keywords_in_control_flow_statements = true 138 | csharp_space_after_semicolon_in_for_statement = true 139 | csharp_space_around_binary_operators = before_and_after 140 | csharp_space_around_declaration_statements = do_not_ignore 141 | csharp_space_before_colon_in_inheritance_clause = true 142 | csharp_space_before_comma = false 143 | csharp_space_before_dot = false 144 | csharp_space_before_open_square_brackets = false 145 | csharp_space_before_semicolon_in_for_statement = false 146 | csharp_space_between_empty_square_brackets = false 147 | csharp_space_between_method_call_empty_parameter_list_parentheses = false 148 | csharp_space_between_method_call_name_and_opening_parenthesis = false 149 | csharp_space_between_method_call_parameter_list_parentheses = false 150 | csharp_space_between_method_declaration_empty_parameter_list_parentheses = false 151 | csharp_space_between_method_declaration_name_and_open_parenthesis = false 152 | csharp_space_between_method_declaration_parameter_list_parentheses = false 153 | csharp_space_between_parentheses = false 154 | csharp_space_between_square_brackets = false 155 | 156 | # Analyzers 157 | dotnet_code_quality.ca1802.api_surface = private, internal 158 | 159 | # C++ Files 160 | [*.{cpp,h,in}] 161 | curly_bracket_next_line = true 162 | indent_brace_style = Allman 163 | 164 | # Xml project files 165 | [*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}] 166 | indent_size = 2 167 | 168 | # Xml build files 169 | [*.builds] 170 | indent_size = 2 171 | 172 | # Xml files 173 | [*.{xml,stylecop,resx,ruleset}] 174 | indent_size = 2 175 | 176 | # Xml config files 177 | [*.{props,targets,config,nuspec}] 178 | indent_size = 2 179 | 180 | # Shell scripts 181 | [*.sh] 182 | end_of_line = lf 183 | [*.{cmd, bat}] 184 | end_of_line = crlf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs -------------------------------------------------------------------------------- /Orders.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.26124.0 5 | MinimumVisualStudioVersion = 15.0.26124.0 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{53B04E93-3261-43D8-AA5E-BBE0649BA3B8}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orders.Api", "src\Orders.Api\Orders.Api.csproj", "{821512BF-D64F-4B0E-B7B5-4858BC330F27}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orders.Application", "src\Orders.Application\Orders.Application.csproj", "{E951D0BE-6209-4475-8A3C-5D644F717F5F}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orders.Domain", "src\Orders.Domain\Orders.Domain.csproj", "{FD27C607-EFDB-4574-8ACC-B63C759A88BE}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orders.Infrastructure", "src\Orders.Infrastructure\Orders.Infrastructure.csproj", "{09D57632-BD11-43F2-A232-065957071D45}" 15 | EndProject 16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orders.Worker", "src\Orders.Worker\Orders.Worker.csproj", "{9066596D-A6BD-48C2-8012-9122C1C85BB6}" 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 20 | Debug|Any CPU = Debug|Any CPU 21 | Debug|x64 = Debug|x64 22 | Debug|x86 = Debug|x86 23 | Release|Any CPU = Release|Any CPU 24 | Release|x64 = Release|x64 25 | Release|x86 = Release|x86 26 | EndGlobalSection 27 | GlobalSection(SolutionProperties) = preSolution 28 | HideSolutionNode = FALSE 29 | EndGlobalSection 30 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 31 | {821512BF-D64F-4B0E-B7B5-4858BC330F27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 | {821512BF-D64F-4B0E-B7B5-4858BC330F27}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 | {821512BF-D64F-4B0E-B7B5-4858BC330F27}.Debug|x64.ActiveCfg = Debug|Any CPU 34 | {821512BF-D64F-4B0E-B7B5-4858BC330F27}.Debug|x64.Build.0 = Debug|Any CPU 35 | {821512BF-D64F-4B0E-B7B5-4858BC330F27}.Debug|x86.ActiveCfg = Debug|Any CPU 36 | {821512BF-D64F-4B0E-B7B5-4858BC330F27}.Debug|x86.Build.0 = Debug|Any CPU 37 | {821512BF-D64F-4B0E-B7B5-4858BC330F27}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {821512BF-D64F-4B0E-B7B5-4858BC330F27}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {821512BF-D64F-4B0E-B7B5-4858BC330F27}.Release|x64.ActiveCfg = Release|Any CPU 40 | {821512BF-D64F-4B0E-B7B5-4858BC330F27}.Release|x64.Build.0 = Release|Any CPU 41 | {821512BF-D64F-4B0E-B7B5-4858BC330F27}.Release|x86.ActiveCfg = Release|Any CPU 42 | {821512BF-D64F-4B0E-B7B5-4858BC330F27}.Release|x86.Build.0 = Release|Any CPU 43 | {E951D0BE-6209-4475-8A3C-5D644F717F5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 44 | {E951D0BE-6209-4475-8A3C-5D644F717F5F}.Debug|Any CPU.Build.0 = Debug|Any CPU 45 | {E951D0BE-6209-4475-8A3C-5D644F717F5F}.Debug|x64.ActiveCfg = Debug|Any CPU 46 | {E951D0BE-6209-4475-8A3C-5D644F717F5F}.Debug|x64.Build.0 = Debug|Any CPU 47 | {E951D0BE-6209-4475-8A3C-5D644F717F5F}.Debug|x86.ActiveCfg = Debug|Any CPU 48 | {E951D0BE-6209-4475-8A3C-5D644F717F5F}.Debug|x86.Build.0 = Debug|Any CPU 49 | {E951D0BE-6209-4475-8A3C-5D644F717F5F}.Release|Any CPU.ActiveCfg = Release|Any CPU 50 | {E951D0BE-6209-4475-8A3C-5D644F717F5F}.Release|Any CPU.Build.0 = Release|Any CPU 51 | {E951D0BE-6209-4475-8A3C-5D644F717F5F}.Release|x64.ActiveCfg = Release|Any CPU 52 | {E951D0BE-6209-4475-8A3C-5D644F717F5F}.Release|x64.Build.0 = Release|Any CPU 53 | {E951D0BE-6209-4475-8A3C-5D644F717F5F}.Release|x86.ActiveCfg = Release|Any CPU 54 | {E951D0BE-6209-4475-8A3C-5D644F717F5F}.Release|x86.Build.0 = Release|Any CPU 55 | {FD27C607-EFDB-4574-8ACC-B63C759A88BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 56 | {FD27C607-EFDB-4574-8ACC-B63C759A88BE}.Debug|Any CPU.Build.0 = Debug|Any CPU 57 | {FD27C607-EFDB-4574-8ACC-B63C759A88BE}.Debug|x64.ActiveCfg = Debug|Any CPU 58 | {FD27C607-EFDB-4574-8ACC-B63C759A88BE}.Debug|x64.Build.0 = Debug|Any CPU 59 | {FD27C607-EFDB-4574-8ACC-B63C759A88BE}.Debug|x86.ActiveCfg = Debug|Any CPU 60 | {FD27C607-EFDB-4574-8ACC-B63C759A88BE}.Debug|x86.Build.0 = Debug|Any CPU 61 | {FD27C607-EFDB-4574-8ACC-B63C759A88BE}.Release|Any CPU.ActiveCfg = Release|Any CPU 62 | {FD27C607-EFDB-4574-8ACC-B63C759A88BE}.Release|Any CPU.Build.0 = Release|Any CPU 63 | {FD27C607-EFDB-4574-8ACC-B63C759A88BE}.Release|x64.ActiveCfg = Release|Any CPU 64 | {FD27C607-EFDB-4574-8ACC-B63C759A88BE}.Release|x64.Build.0 = Release|Any CPU 65 | {FD27C607-EFDB-4574-8ACC-B63C759A88BE}.Release|x86.ActiveCfg = Release|Any CPU 66 | {FD27C607-EFDB-4574-8ACC-B63C759A88BE}.Release|x86.Build.0 = Release|Any CPU 67 | {09D57632-BD11-43F2-A232-065957071D45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 68 | {09D57632-BD11-43F2-A232-065957071D45}.Debug|Any CPU.Build.0 = Debug|Any CPU 69 | {09D57632-BD11-43F2-A232-065957071D45}.Debug|x64.ActiveCfg = Debug|Any CPU 70 | {09D57632-BD11-43F2-A232-065957071D45}.Debug|x64.Build.0 = Debug|Any CPU 71 | {09D57632-BD11-43F2-A232-065957071D45}.Debug|x86.ActiveCfg = Debug|Any CPU 72 | {09D57632-BD11-43F2-A232-065957071D45}.Debug|x86.Build.0 = Debug|Any CPU 73 | {09D57632-BD11-43F2-A232-065957071D45}.Release|Any CPU.ActiveCfg = Release|Any CPU 74 | {09D57632-BD11-43F2-A232-065957071D45}.Release|Any CPU.Build.0 = Release|Any CPU 75 | {09D57632-BD11-43F2-A232-065957071D45}.Release|x64.ActiveCfg = Release|Any CPU 76 | {09D57632-BD11-43F2-A232-065957071D45}.Release|x64.Build.0 = Release|Any CPU 77 | {09D57632-BD11-43F2-A232-065957071D45}.Release|x86.ActiveCfg = Release|Any CPU 78 | {09D57632-BD11-43F2-A232-065957071D45}.Release|x86.Build.0 = Release|Any CPU 79 | {9066596D-A6BD-48C2-8012-9122C1C85BB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 80 | {9066596D-A6BD-48C2-8012-9122C1C85BB6}.Debug|Any CPU.Build.0 = Debug|Any CPU 81 | {9066596D-A6BD-48C2-8012-9122C1C85BB6}.Debug|x64.ActiveCfg = Debug|Any CPU 82 | {9066596D-A6BD-48C2-8012-9122C1C85BB6}.Debug|x64.Build.0 = Debug|Any CPU 83 | {9066596D-A6BD-48C2-8012-9122C1C85BB6}.Debug|x86.ActiveCfg = Debug|Any CPU 84 | {9066596D-A6BD-48C2-8012-9122C1C85BB6}.Debug|x86.Build.0 = Debug|Any CPU 85 | {9066596D-A6BD-48C2-8012-9122C1C85BB6}.Release|Any CPU.ActiveCfg = Release|Any CPU 86 | {9066596D-A6BD-48C2-8012-9122C1C85BB6}.Release|Any CPU.Build.0 = Release|Any CPU 87 | {9066596D-A6BD-48C2-8012-9122C1C85BB6}.Release|x64.ActiveCfg = Release|Any CPU 88 | {9066596D-A6BD-48C2-8012-9122C1C85BB6}.Release|x64.Build.0 = Release|Any CPU 89 | {9066596D-A6BD-48C2-8012-9122C1C85BB6}.Release|x86.ActiveCfg = Release|Any CPU 90 | {9066596D-A6BD-48C2-8012-9122C1C85BB6}.Release|x86.Build.0 = Release|Any CPU 91 | EndGlobalSection 92 | GlobalSection(NestedProjects) = preSolution 93 | {821512BF-D64F-4B0E-B7B5-4858BC330F27} = {53B04E93-3261-43D8-AA5E-BBE0649BA3B8} 94 | {E951D0BE-6209-4475-8A3C-5D644F717F5F} = {53B04E93-3261-43D8-AA5E-BBE0649BA3B8} 95 | {FD27C607-EFDB-4574-8ACC-B63C759A88BE} = {53B04E93-3261-43D8-AA5E-BBE0649BA3B8} 96 | {09D57632-BD11-43F2-A232-065957071D45} = {53B04E93-3261-43D8-AA5E-BBE0649BA3B8} 97 | {9066596D-A6BD-48C2-8012-9122C1C85BB6} = {53B04E93-3261-43D8-AA5E-BBE0649BA3B8} 98 | EndGlobalSection 99 | EndGlobal 100 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # .NET Core 3.0 WebApi, BackgroundWorker and RabbitMQ 2 | 3 | Sample implementation of a WebApi that publishes messages to RabbitMQ and consume them using a BackgroundWorker. 4 | 5 | > This is a working in progress. PR are welcome! 6 | 7 | ## Install 8 | 9 | ``` 10 | $ git clone https://github.com/ivanpaulovich/webapi-backgroundworker-rabbitmq.git 11 | ``` 12 | 13 | ## Setup 14 | 15 | ``` 16 | $ ./src/scripts/setup-rabbitmq.sh 17 | $ dotnet run 18 | $ curl https://localhost:5001/Orders 19 | ``` 20 | 21 | ### Development Environment 22 | 23 | * MacOS Mojave :apple: 24 | * Visual Studio Code :heart: 25 | * [.NET Core SDK 3.0](https://dotnet.microsoft.com/download/dotnet-core/3.0) 26 | * Docker :whale: 27 | * RabbitMQ 28 | 29 | ### Support and Issues 30 | 31 | Please `star` it then open an issue. 32 | -------------------------------------------------------------------------------- /src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivanpaulovich/webapi-backgroundworker-rabbitmq/b431b2e5c4ccfaf2aa1f74f2763678f7268f027b/src/.DS_Store -------------------------------------------------------------------------------- /src/Orders.Api/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivanpaulovich/webapi-backgroundworker-rabbitmq/b431b2e5c4ccfaf2aa1f74f2763678f7268f027b/src/Orders.Api/.DS_Store -------------------------------------------------------------------------------- /src/Orders.Api/Controllers/OrdersController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Orders.Application.Boundaries.PlaceOrder; 4 | 5 | namespace Orders.Api.Controllers 6 | { 7 | [ApiController] 8 | [Route("[controller]")] 9 | public class OrdersController : ControllerBase 10 | { 11 | private readonly IPlaceOrderUseCase _placeOrderUseCase; 12 | 13 | public OrdersController(IPlaceOrderUseCase placeOrderUseCase) 14 | { 15 | _placeOrderUseCase = placeOrderUseCase; 16 | } 17 | 18 | [HttpGet] 19 | public IActionResult Get([FromForm]int productId, [FromForm]int quantity) 20 | { 21 | _placeOrderUseCase.Execute(new PlaceOrderInput(productId, quantity, DateTime.Now)); 22 | return Ok(); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /src/Orders.Api/Handlers/ProcessOrderHandler.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | using MediatR; 4 | using Orders.Application.Boundaries.PlaceOrder; 5 | 6 | namespace Orders.Api.Handlers 7 | { 8 | public class ProcessOrderHandler : AsyncRequestHandler 9 | { 10 | private readonly IProcessOrderUseCase _processOrderUseCase; 11 | 12 | public ProcessOrderHandler(IProcessOrderUseCase processOrderUseCase) 13 | { 14 | _processOrderUseCase = processOrderUseCase; 15 | } 16 | 17 | protected async override Task Handle(PlaceOrderInput request, CancellationToken cancellationToken) 18 | { 19 | await _processOrderUseCase.Execute(request); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/Orders.Api/Orders.Api.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Orders.Api/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace Orders.Api 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } -------------------------------------------------------------------------------- /src/Orders.Api/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:5064", 8 | "sslPort": 44390 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "weatherforecast", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "OrdersApi.Api": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | }, 26 | "applicationUrl": "https://localhost:5001;http://localhost:5000" 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/Orders.Api/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.HttpsPolicy; 8 | using Microsoft.AspNetCore.Mvc; 9 | using Microsoft.Extensions.Configuration; 10 | using Microsoft.Extensions.DependencyInjection; 11 | using Microsoft.Extensions.Hosting; 12 | using Microsoft.Extensions.Logging; 13 | using Orders.Application.Boundaries.PlaceOrder; 14 | using Orders.Application.Services; 15 | using Orders.Application.UseCases; 16 | using Orders.Infrastructure.RabbitMQ; 17 | 18 | namespace Orders.Api 19 | { 20 | public class Startup 21 | { 22 | public Startup(IConfiguration configuration) 23 | { 24 | Configuration = configuration; 25 | } 26 | 27 | public IConfiguration Configuration { get; } 28 | 29 | // This method gets called by the runtime. Use this method to add services to the container. 30 | public void ConfigureServices(IServiceCollection services) 31 | { 32 | services.AddControllers(); 33 | 34 | services.AddSingleton(); 35 | 36 | services.AddTransient(); 37 | services.AddTransient(); 38 | } 39 | 40 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 41 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 42 | { 43 | if (env.IsDevelopment()) 44 | { 45 | app.UseDeveloperExceptionPage(); 46 | } 47 | 48 | app.UseHttpsRedirection(); 49 | 50 | app.UseRouting(); 51 | 52 | app.UseAuthorization(); 53 | 54 | app.UseEndpoints(endpoints => 55 | { 56 | endpoints.MapControllers(); 57 | }); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /src/Orders.Api/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/Orders.Api/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "AllowedHosts": "*" 10 | } 11 | -------------------------------------------------------------------------------- /src/Orders.Application/Boundaries/PlaceOrder/IPlaceOrderUseCase.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace Orders.Application.Boundaries.PlaceOrder 4 | { 5 | public interface IPlaceOrderUseCase 6 | { 7 | Task Execute(PlaceOrderInput placeOrderInput); 8 | } 9 | } -------------------------------------------------------------------------------- /src/Orders.Application/Boundaries/PlaceOrder/IProcessOrderUseCase.cs: -------------------------------------------------------------------------------- 1 | using System.Threading.Tasks; 2 | 3 | namespace Orders.Application.Boundaries.PlaceOrder 4 | { 5 | public interface IProcessOrderUseCase 6 | { 7 | Task Execute(PlaceOrderInput placeOrderInput); 8 | } 9 | } -------------------------------------------------------------------------------- /src/Orders.Application/Boundaries/PlaceOrder/PlaceOrderInput.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using MediatR; 3 | 4 | namespace Orders.Application.Boundaries.PlaceOrder 5 | { 6 | public class PlaceOrderInput : IRequest 7 | { 8 | public int ProductId { get; } 9 | public int Quantity { get; } 10 | public DateTime Timestamp { get; set; } 11 | 12 | public PlaceOrderInput(int productId, int quantity, DateTime timestamp) 13 | { 14 | ProductId = productId; 15 | Quantity = quantity; 16 | Timestamp = timestamp; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/Orders.Application/Orders.Application.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | netstandard2.0 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/Orders.Application/Services/IPublisher.cs: -------------------------------------------------------------------------------- 1 | using Orders.Application.Boundaries.PlaceOrder; 2 | 3 | namespace Orders.Application.Services 4 | { 5 | public interface IPublisher 6 | { 7 | void PublishOrder(PlaceOrderInput placeOrderInput); 8 | } 9 | } -------------------------------------------------------------------------------- /src/Orders.Application/UseCases/PlaceOrder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Orders.Application.Boundaries.PlaceOrder; 4 | using Orders.Application.Services; 5 | 6 | namespace Orders.Application.UseCases 7 | { 8 | public class PlaceOrder : IPlaceOrderUseCase 9 | { 10 | private readonly IPublisher _bus; 11 | 12 | public PlaceOrder(IPublisher bus) 13 | { 14 | _bus = bus; 15 | } 16 | 17 | public Task Execute(PlaceOrderInput placeOrderInput) 18 | { 19 | _bus.PublishOrder(placeOrderInput); 20 | 21 | return Task.CompletedTask; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/Orders.Application/UseCases/ProcessOrder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Threading.Tasks; 3 | using Orders.Application.Boundaries.PlaceOrder; 4 | 5 | namespace Orders.Application.UseCases 6 | { 7 | public class ProcessOrder : IProcessOrderUseCase 8 | { 9 | public Task Execute(PlaceOrderInput placeOrderInput) 10 | { 11 | 12 | //return Task.CompletedTask; 13 | throw new Exception(); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /src/Orders.Domain/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivanpaulovich/webapi-backgroundworker-rabbitmq/b431b2e5c4ccfaf2aa1f74f2763678f7268f027b/src/Orders.Domain/.DS_Store -------------------------------------------------------------------------------- /src/Orders.Domain/Orders.Domain.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/Orders.Infrastructure/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivanpaulovich/webapi-backgroundworker-rabbitmq/b431b2e5c4ccfaf2aa1f74f2763678f7268f027b/src/Orders.Infrastructure/.DS_Store -------------------------------------------------------------------------------- /src/Orders.Infrastructure/Orders.Infrastructure.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Orders.Infrastructure/RabbitMQ/RabbitMQBus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Newtonsoft.Json; 5 | using Orders.Application.Boundaries.PlaceOrder; 6 | using Orders.Application.Services; 7 | using RabbitMQ.Client; 8 | 9 | namespace Orders.Infrastructure.RabbitMQ 10 | { 11 | public class RabbitMQBus : IPublisher, IDisposable 12 | { 13 | private IConnection _connection; 14 | private IModel _channel; 15 | private IDictionary _binding; 16 | 17 | public RabbitMQBus() 18 | { 19 | _binding = new Dictionary(); 20 | _binding.Add(typeof(PlaceOrderInput).Name, typeof(PlaceOrderInput)); 21 | InitRabbitMQ(); 22 | } 23 | 24 | private void InitRabbitMQ() 25 | { 26 | var factory = new ConnectionFactory() { HostName = "localhost", UserName = "guest", Password = "guest" }; 27 | _connection = factory.CreateConnection(); 28 | 29 | _channel = _connection.CreateModel(); 30 | _channel.QueueDeclare(typeof(PlaceOrderInput).Name, true, false, false, null); 31 | } 32 | 33 | public void PublishOrder(PlaceOrderInput placeOrderInput) 34 | { 35 | string json = JsonConvert.SerializeObject(placeOrderInput); 36 | 37 | Publish(typeof(PlaceOrderInput).Name, json); 38 | } 39 | 40 | private void Publish(string queueName, string json) 41 | { 42 | byte[] messageBodyBytes = Encoding.UTF8.GetBytes(json); 43 | 44 | _channel.BasicPublish( 45 | string.Empty, 46 | queueName, 47 | basicProperties: null, 48 | body: messageBodyBytes 49 | ); 50 | } 51 | 52 | public void Dispose() 53 | { 54 | _channel?.Close(); 55 | _connection?.Close(); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/Orders.Worker/Orders.Worker.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.0 5 | dotnet-Orders.Worker-D518725C-88EE-4AD6-80CC-33A22A009DC6 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/Orders.Worker/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.Extensions.DependencyInjection; 6 | using Microsoft.Extensions.Hosting; 7 | using MediatR; 8 | 9 | namespace Orders.Worker 10 | { 11 | public class Program 12 | { 13 | public static void Main(string[] args) 14 | { 15 | CreateHostBuilder(args).Build().Run(); 16 | } 17 | 18 | public static IHostBuilder CreateHostBuilder(string[] args) => 19 | Host.CreateDefaultBuilder(args) 20 | .ConfigureServices((hostContext, services) => 21 | { 22 | services.AddMediatR(typeof(Program)); 23 | services.AddHostedService(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Orders.Worker/Worker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Text.Json; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | using MediatR; 8 | using Microsoft.Extensions.Hosting; 9 | using Newtonsoft.Json; 10 | using Orders.Application.Boundaries.PlaceOrder; 11 | using Orders.Application.Services; 12 | using Polly; 13 | using RabbitMQ.Client; 14 | using RabbitMQ.Client.Events; 15 | 16 | namespace Orders.Worker 17 | { 18 | public class RabbitMQBus : IHostedService, IDisposable 19 | { 20 | private IConnection _connection; 21 | private IModel _channel; 22 | private IMediator _mediator; 23 | private IDictionary _binding; 24 | 25 | public RabbitMQBus(IMediator mediator) 26 | { 27 | _mediator = mediator; 28 | _binding = new Dictionary(); 29 | _binding.Add(typeof(PlaceOrderInput).Name, typeof(PlaceOrderInput)); 30 | InitRabbitMQ(); 31 | } 32 | 33 | private void InitRabbitMQ() 34 | { 35 | var factory = new ConnectionFactory() { HostName = "localhost", UserName = "guest", Password = "guest" }; 36 | _connection = factory.CreateConnection(); 37 | 38 | _channel = _connection.CreateModel(); 39 | _channel.QueueDeclare(typeof(PlaceOrderInput).Name, true, false, false, null); 40 | } 41 | 42 | public virtual Task StartAsync(CancellationToken cancellationToken) 43 | { 44 | var consumer = new EventingBasicConsumer(_channel); 45 | 46 | consumer.Received += OnReceived; 47 | 48 | _channel.BasicConsume(typeof(PlaceOrderInput).Name, false, consumer); 49 | return Task.CompletedTask; 50 | } 51 | 52 | private void OnReceived(object ch, BasicDeliverEventArgs ea) 53 | { 54 | var retryPolicy = Policy 55 | .Handle() 56 | .RetryAsync(3); 57 | 58 | var fallbackPolicy = Policy 59 | .Handle() 60 | .FallbackAsync(async (cancellationToken) => await Task.Run(() => Console.WriteLine(ea.RoutingKey))); 61 | 62 | fallbackPolicy 63 | .WrapAsync(retryPolicy) 64 | .ExecuteAsync(async () => await Send(ea.RoutingKey, ea.Body, ea.DeliveryTag).ConfigureAwait(false)) 65 | .ConfigureAwait(false) 66 | .GetAwaiter() 67 | .GetResult(); 68 | } 69 | 70 | private async Task Send(string key, byte[] body, ulong deliveryTag) 71 | { 72 | var messageType = _binding[key]; 73 | var content = Encoding.UTF8.GetString(body); 74 | 75 | var request = (IRequest)JsonConvert.DeserializeObject(content, messageType); 76 | await _mediator.Send(request); 77 | 78 | _channel.BasicAck(deliveryTag, false); 79 | } 80 | 81 | public void Dispose() 82 | { 83 | _channel?.Close(); 84 | _connection?.Close(); 85 | } 86 | 87 | public Task StopAsync(CancellationToken cancellationToken) 88 | { 89 | return Task.CompletedTask; 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/Orders.Worker/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/Orders.Worker/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/scripts/setup-rabbitmq.sh: -------------------------------------------------------------------------------- 1 | docker run -d -p 5672:5672 -p 15672:15672 rabbitmq:management --------------------------------------------------------------------------------