├── .gitattributes ├── .gitignore ├── README.md ├── RabbitMQ.DefaultExchange ├── Consumer │ ├── Consumer.csproj │ └── Program.cs ├── Publisher │ ├── Program.cs │ └── Publisher.csproj └── RabbitMQ.sln ├── RabbitMQ.DirectExchange ├── Consumer.All │ ├── Consumer.All.csproj │ └── Program.cs ├── Consumer.Error │ ├── Consumer.Error.csproj │ └── Program.cs ├── Consumer.Info │ ├── Consumer.Info.csproj │ └── Program.cs ├── Consumer.Warning │ ├── Consumer.Warning.csproj │ └── Program.cs ├── Producer │ ├── Producer.csproj │ └── Program.cs └── RabbitMQ.DirectExchange.sln ├── RabbitMQ.FunoutExchange ├── Consumer.BankCharger │ ├── Consumer.BankCharger.csproj │ └── Program.cs ├── Consumer.Tax │ ├── Consumer.Tax.csproj │ └── Program.cs ├── Producer │ ├── Producer.csproj │ └── Program.cs └── RabbitMQ.FunoutExchange.sln ├── RabbitMQ.HeadersExchange ├── Consumer.Abroad.Usd │ ├── Consumer.Abroad.Usd.csproj │ └── Program.cs ├── Consumer.All.Usd │ ├── Consumer.All.Usd.csproj │ └── Program.cs ├── Cunsumer.Internal.All │ ├── Cunsumer.Internal.All.csproj │ └── Program.cs ├── Producer │ ├── Producer.csproj │ └── Program.cs └── RabbitMQ.HeadersExchange.sln └── RabbitMQ.TopicExchange ├── Consumer.Ecological ├── Consumer.Ecological.csproj └── Program.cs ├── Consumer.Red ├── Consumer.Red.csproj └── Program.cs ├── Consumer.Tesla ├── Consumer.Tesla.csproj └── Program.cs ├── Producer ├── Producer.csproj └── Program.cs └── RabbitMQ.TopicExchange.sln /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.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 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RabbitMQ 2 | The RabbitMQ Tutorial is a course on the basics of a message broker, 3 | consisting of short but complete lessons posted on YouTube here: 4 | https://youtube.com/playlist?list=PLCpsrvs6hImZShRjUbqewZWgjJgU6SIvU 5 | -------------------------------------------------------------------------------- /RabbitMQ.DefaultExchange/Consumer/Consumer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RabbitMQ.DefaultExchange/Consumer/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using RabbitMQ.Client.Events; 3 | using System; 4 | using System.Text; 5 | 6 | namespace Consumer 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | var factory = new ConnectionFactory() { HostName = "localhost" }; 13 | using (var connection = factory.CreateConnection()) 14 | using (var channel = connection.CreateModel()) 15 | { 16 | channel.QueueDeclare(queue: "dev-queue", 17 | durable: false, 18 | exclusive: false, 19 | autoDelete: false, 20 | arguments: null); 21 | 22 | var consumer = new EventingBasicConsumer(channel); 23 | 24 | consumer.Received += (sender, e) => 25 | { 26 | var body = e.Body; 27 | var message = Encoding.UTF8.GetString(body.ToArray()); 28 | Console.WriteLine(" Received message: {0}", message); 29 | }; 30 | 31 | channel.BasicConsume(queue: "dev-queue", 32 | autoAck: true, 33 | consumer: consumer); 34 | 35 | Console.WriteLine("Subscribed to the queue 'dev-queue'"); 36 | 37 | Console.ReadLine(); 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /RabbitMQ.DefaultExchange/Publisher/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using System; 3 | using System.Text; 4 | using System.Threading; 5 | 6 | namespace Publisher 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | var counter = 0; 13 | do 14 | { 15 | int timeToSleep = new Random().Next(1000, 3000); 16 | Thread.Sleep(timeToSleep); 17 | 18 | var factory = new ConnectionFactory() { HostName = "localhost" }; 19 | using (var connection = factory.CreateConnection()) 20 | using (var channel = connection.CreateModel()) 21 | { 22 | channel.QueueDeclare(queue: "dev-queue", 23 | durable: false, 24 | exclusive: false, 25 | autoDelete: false, 26 | arguments: null); 27 | 28 | string message = $"Message from publisher N {counter}"; 29 | 30 | var body = Encoding.UTF8.GetBytes(message); 31 | 32 | channel.BasicPublish(exchange: "", 33 | routingKey: "dev-queue", 34 | basicProperties: null, 35 | body: body); 36 | 37 | Console.WriteLine($"Message is sent into Default Exchange [N:{counter++}]"); 38 | } 39 | } while (true); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /RabbitMQ.DefaultExchange/Publisher/Publisher.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RabbitMQ.DefaultExchange/RabbitMQ.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31005.135 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Publisher", "Publisher\Publisher.csproj", "{EA02BFEF-C7F5-4E5B-B002-6D38B8365100}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Consumer", "Consumer\Consumer.csproj", "{B59C2CC1-7DF0-40D1-89CC-D85255F59E43}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {EA02BFEF-C7F5-4E5B-B002-6D38B8365100}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {EA02BFEF-C7F5-4E5B-B002-6D38B8365100}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {EA02BFEF-C7F5-4E5B-B002-6D38B8365100}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {EA02BFEF-C7F5-4E5B-B002-6D38B8365100}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {B59C2CC1-7DF0-40D1-89CC-D85255F59E43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {B59C2CC1-7DF0-40D1-89CC-D85255F59E43}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {B59C2CC1-7DF0-40D1-89CC-D85255F59E43}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {B59C2CC1-7DF0-40D1-89CC-D85255F59E43}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {4704AEA6-0332-4D44-8282-B21B9593061D} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /RabbitMQ.DirectExchange/Consumer.All/Consumer.All.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RabbitMQ.DirectExchange/Consumer.All/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using RabbitMQ.Client.Events; 3 | using System; 4 | using System.Text; 5 | 6 | namespace Consumer.All 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | var factory = new ConnectionFactory() { HostName = "localhost" }; 13 | using (var connection = factory.CreateConnection()) 14 | using (var channel = connection.CreateModel()) 15 | { 16 | channel.ExchangeDeclare(exchange: "direct_logs", type: ExchangeType.Direct); 17 | 18 | var queueName = channel.QueueDeclare().QueueName; 19 | 20 | channel.QueueBind(queue: queueName, 21 | exchange: "direct_logs", 22 | routingKey: "error"); 23 | channel.QueueBind(queue: queueName, 24 | exchange: "direct_logs", 25 | routingKey: "info"); 26 | channel.QueueBind(queue: queueName, 27 | exchange: "direct_logs", 28 | routingKey: "warning"); 29 | 30 | var consumer = new EventingBasicConsumer(channel); 31 | 32 | consumer.Received += (sender, e) => 33 | { 34 | var body = e.Body; 35 | var message = Encoding.UTF8.GetString(body.ToArray()); 36 | Console.WriteLine(" Received message: {0}", message); 37 | }; 38 | 39 | channel.BasicConsume(queue: queueName, 40 | autoAck: true, 41 | consumer: consumer); 42 | 43 | Console.WriteLine($"Subscribed to the queue '{queueName}'"); 44 | 45 | Console.ReadLine(); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /RabbitMQ.DirectExchange/Consumer.Error/Consumer.Error.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RabbitMQ.DirectExchange/Consumer.Error/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using RabbitMQ.Client.Events; 3 | using System; 4 | using System.Text; 5 | 6 | namespace Consumer.Error 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | var factory = new ConnectionFactory() { HostName = "localhost" }; 13 | using (var connection = factory.CreateConnection()) 14 | using (var channel = connection.CreateModel()) 15 | { 16 | channel.ExchangeDeclare(exchange: "direct_logs", type: ExchangeType.Direct); 17 | 18 | var queueName = channel.QueueDeclare().QueueName; 19 | 20 | channel.QueueBind(queue: queueName, 21 | exchange: "direct_logs", 22 | routingKey: "error"); 23 | 24 | var consumer = new EventingBasicConsumer(channel); 25 | 26 | consumer.Received += (sender, e) => 27 | { 28 | var body = e.Body; 29 | var message = Encoding.UTF8.GetString(body.ToArray()); 30 | Console.WriteLine(" Received message: {0}", message); 31 | }; 32 | 33 | channel.BasicConsume(queue: queueName, 34 | autoAck: true, 35 | consumer: consumer); 36 | 37 | Console.WriteLine($"Subscribed to the queue '{queueName}'"); 38 | 39 | Console.ReadLine(); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /RabbitMQ.DirectExchange/Consumer.Info/Consumer.Info.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RabbitMQ.DirectExchange/Consumer.Info/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using RabbitMQ.Client.Events; 3 | using System; 4 | using System.Text; 5 | 6 | namespace Consumer.Info 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | var factory = new ConnectionFactory() { HostName = "localhost" }; 13 | using (var connection = factory.CreateConnection()) 14 | using (var channel = connection.CreateModel()) 15 | { 16 | channel.ExchangeDeclare(exchange: "direct_logs", type: ExchangeType.Direct); 17 | 18 | var queueName = channel.QueueDeclare().QueueName; 19 | 20 | channel.QueueBind(queue: queueName, 21 | exchange: "direct_logs", 22 | routingKey: "info"); 23 | 24 | var consumer = new EventingBasicConsumer(channel); 25 | 26 | consumer.Received += (sender, e) => 27 | { 28 | var body = e.Body; 29 | var message = Encoding.UTF8.GetString(body.ToArray()); 30 | Console.WriteLine(" Received message: {0}", message); 31 | }; 32 | 33 | channel.BasicConsume(queue: queueName, 34 | autoAck: true, 35 | consumer: consumer); 36 | 37 | Console.WriteLine($"Subscribed to the queue '{queueName}'"); 38 | 39 | Console.ReadLine(); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /RabbitMQ.DirectExchange/Consumer.Warning/Consumer.Warning.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RabbitMQ.DirectExchange/Consumer.Warning/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using RabbitMQ.Client.Events; 3 | using System; 4 | using System.Text; 5 | 6 | namespace Consumer.Warning 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | var factory = new ConnectionFactory() { HostName = "localhost" }; 13 | using (var connection = factory.CreateConnection()) 14 | using (var channel = connection.CreateModel()) 15 | { 16 | channel.ExchangeDeclare(exchange: "direct_logs", type: ExchangeType.Direct); 17 | 18 | var queueName = channel.QueueDeclare().QueueName; 19 | 20 | channel.QueueBind(queue: queueName, 21 | exchange: "direct_logs", 22 | routingKey: "warning"); 23 | 24 | var consumer = new EventingBasicConsumer(channel); 25 | 26 | consumer.Received += (sender, e) => 27 | { 28 | var body = e.Body; 29 | var message = Encoding.UTF8.GetString(body.ToArray()); 30 | Console.WriteLine(" Received message: {0}", message); 31 | }; 32 | 33 | channel.BasicConsume(queue: queueName, 34 | autoAck: true, 35 | consumer: consumer); 36 | 37 | Console.WriteLine($"Subscribed to the queue '{queueName}'"); 38 | 39 | Console.ReadLine(); 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /RabbitMQ.DirectExchange/Producer/Producer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RabbitMQ.DirectExchange/Producer/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using System; 3 | using System.Text; 4 | using System.Threading; 5 | using System.Threading.Tasks; 6 | 7 | namespace Producer 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | Task.Run(CreateTask(12000, "error")); 14 | Task.Run(CreateTask(10000, "info")); 15 | Task.Run(CreateTask(8000, "warning")); 16 | 17 | Console.ReadKey(); 18 | } 19 | 20 | static Func CreateTask(int timeToSleepTo, string routingKey) 21 | { 22 | return () => 23 | { 24 | var counter = 0; 25 | do 26 | { 27 | int timeToSleep = new Random().Next(1000, timeToSleepTo); 28 | Thread.Sleep(timeToSleep); 29 | 30 | var factory = new ConnectionFactory() { HostName = "localhost" }; 31 | using (var connection = factory.CreateConnection()) 32 | using (var channel = connection.CreateModel()) 33 | { 34 | channel.ExchangeDeclare(exchange: "direct_logs", type: ExchangeType.Direct); 35 | 36 | string message = $"Message type [{routingKey}] from publisher N {counter}"; 37 | 38 | var body = Encoding.UTF8.GetBytes(message); 39 | 40 | channel.BasicPublish(exchange: "direct_logs", 41 | routingKey: routingKey, 42 | basicProperties: null, 43 | body: body); 44 | 45 | Console.WriteLine($"Message type [{routingKey}] is sent into Direct Exchange [N:{counter++}]"); 46 | } 47 | } while (true); 48 | }; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /RabbitMQ.DirectExchange/RabbitMQ.DirectExchange.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31005.135 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Producer", "Producer\Producer.csproj", "{62EDFA90-164B-4E7C-8095-51086C3EAD8F}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Consumer.Error", "Consumer.Error\Consumer.Error.csproj", "{7315914A-65CC-45DD-A7B3-D1F870E9993B}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Consumer.Info", "Consumer.Info\Consumer.Info.csproj", "{F8402DE9-C09D-431C-AF54-46EBCDFAE398}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Consumer.Warning", "Consumer.Warning\Consumer.Warning.csproj", "{5028FF52-C5C8-4DB0-A2A9-D9460F4070AF}" 13 | EndProject 14 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Consumer.All", "Consumer.All\Consumer.All.csproj", "{89D91608-12B6-4992-87E0-2A7A89FCC7A1}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Any CPU = Debug|Any CPU 19 | Release|Any CPU = Release|Any CPU 20 | EndGlobalSection 21 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 22 | {62EDFA90-164B-4E7C-8095-51086C3EAD8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {62EDFA90-164B-4E7C-8095-51086C3EAD8F}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {62EDFA90-164B-4E7C-8095-51086C3EAD8F}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {62EDFA90-164B-4E7C-8095-51086C3EAD8F}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {7315914A-65CC-45DD-A7B3-D1F870E9993B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {7315914A-65CC-45DD-A7B3-D1F870E9993B}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {7315914A-65CC-45DD-A7B3-D1F870E9993B}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {7315914A-65CC-45DD-A7B3-D1F870E9993B}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {F8402DE9-C09D-431C-AF54-46EBCDFAE398}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {F8402DE9-C09D-431C-AF54-46EBCDFAE398}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {F8402DE9-C09D-431C-AF54-46EBCDFAE398}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {F8402DE9-C09D-431C-AF54-46EBCDFAE398}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {5028FF52-C5C8-4DB0-A2A9-D9460F4070AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {5028FF52-C5C8-4DB0-A2A9-D9460F4070AF}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {5028FF52-C5C8-4DB0-A2A9-D9460F4070AF}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {5028FF52-C5C8-4DB0-A2A9-D9460F4070AF}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {89D91608-12B6-4992-87E0-2A7A89FCC7A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {89D91608-12B6-4992-87E0-2A7A89FCC7A1}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {89D91608-12B6-4992-87E0-2A7A89FCC7A1}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {89D91608-12B6-4992-87E0-2A7A89FCC7A1}.Release|Any CPU.Build.0 = Release|Any CPU 42 | EndGlobalSection 43 | GlobalSection(SolutionProperties) = preSolution 44 | HideSolutionNode = FALSE 45 | EndGlobalSection 46 | GlobalSection(ExtensibilityGlobals) = postSolution 47 | SolutionGuid = {A639EC61-7C66-4992-9978-47D3FC83DE4B} 48 | EndGlobalSection 49 | EndGlobal 50 | -------------------------------------------------------------------------------- /RabbitMQ.FunoutExchange/Consumer.BankCharger/Consumer.BankCharger.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RabbitMQ.FunoutExchange/Consumer.BankCharger/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using RabbitMQ.Client.Events; 3 | using System; 4 | using System.Text; 5 | 6 | namespace Consumer.BankCharger 7 | { 8 | class Program 9 | { 10 | private static int _totalHold = 0; 11 | 12 | static void Main(string[] args) 13 | { 14 | var factory = new ConnectionFactory() { HostName = "localhost" }; 15 | using (var connection = factory.CreateConnection()) 16 | using (var channel = connection.CreateModel()) 17 | { 18 | channel.ExchangeDeclare(exchange: "notifier", type: ExchangeType.Fanout); 19 | 20 | var queueName = channel.QueueDeclare().QueueName; 21 | channel.QueueBind(queue: queueName, 22 | exchange: "notifier", 23 | routingKey: string.Empty); 24 | 25 | var consumer = new EventingBasicConsumer(channel); 26 | 27 | consumer.Received += (sender, e) => 28 | { 29 | var body = e.Body; 30 | var message = Encoding.UTF8.GetString(body.ToArray()); 31 | 32 | var payment = GetPayment(message); 33 | _totalHold += payment; 34 | 35 | Console.WriteLine($"Payment received for the amount of {payment}"); 36 | Console.WriteLine($"${_totalHold} held from this person"); 37 | }; 38 | 39 | channel.BasicConsume(queue: queueName, 40 | autoAck: true, 41 | consumer: consumer); 42 | 43 | Console.WriteLine($"Subscribed to the queue {queueName}"); 44 | Console.WriteLine("Listening . . ."); 45 | 46 | Console.ReadLine(); 47 | } 48 | } 49 | 50 | private static int GetPayment(string message) 51 | { 52 | var messageWords = message.Split(' '); 53 | 54 | return int.Parse(messageWords[^1]); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /RabbitMQ.FunoutExchange/Consumer.Tax/Consumer.Tax.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RabbitMQ.FunoutExchange/Consumer.Tax/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using RabbitMQ.Client.Events; 3 | using System; 4 | using System.Text; 5 | 6 | namespace Consumer.Tax 7 | { 8 | class Program 9 | { 10 | private static double _totalHold = 0; 11 | 12 | static void Main(string[] args) 13 | { 14 | var factory = new ConnectionFactory() { HostName = "localhost" }; 15 | using (var connection = factory.CreateConnection()) 16 | using (var channel = connection.CreateModel()) 17 | { 18 | channel.ExchangeDeclare(exchange: "notifier", type: ExchangeType.Fanout); 19 | 20 | var queueName = channel.QueueDeclare().QueueName; 21 | channel.QueueBind(queue: queueName, 22 | exchange: "notifier", 23 | routingKey: string.Empty); 24 | 25 | Console.WriteLine("Waiting for payments . . ."); 26 | 27 | var consumer = new EventingBasicConsumer(channel); 28 | 29 | consumer.Received += (sender, e) => 30 | { 31 | var body = e.Body; 32 | var message = Encoding.UTF8.GetString(body.ToArray()); 33 | 34 | var payment = GetPayment(message); 35 | _totalHold += payment * 0.01; 36 | 37 | Console.WriteLine($"Payment received for the amount of {payment}"); 38 | Console.WriteLine($"${_totalHold} held from this person"); 39 | }; 40 | 41 | channel.BasicConsume(queue: queueName, 42 | autoAck: true, 43 | consumer: consumer); 44 | 45 | Console.WriteLine($"Subscribed to the queue {queueName}"); 46 | Console.WriteLine("Listening . . ."); 47 | 48 | Console.ReadLine(); 49 | } 50 | } 51 | 52 | private static int GetPayment(string message) 53 | { 54 | var messageWords = message.Split(' '); 55 | 56 | return int.Parse(messageWords[^1]); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /RabbitMQ.FunoutExchange/Producer/Producer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net5.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RabbitMQ.FunoutExchange/Producer/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using System; 3 | using System.Text; 4 | using System.Threading; 5 | 6 | namespace Producer 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | var random = new Random(); 13 | do 14 | { 15 | int timeToSleep = random.Next(1000, 3000); 16 | Thread.Sleep(timeToSleep); 17 | 18 | var factory = new ConnectionFactory() { HostName = "localhost" }; 19 | using (var connection = factory.CreateConnection()) 20 | using (var channel = connection.CreateModel()) 21 | { 22 | channel.ExchangeDeclare(exchange: "notifier", type: ExchangeType.Fanout); 23 | 24 | var moneyCount = random.Next(1000, 10_000); 25 | string message = $"Payment received for the amount of {moneyCount}"; 26 | 27 | var body = Encoding.UTF8.GetBytes(message); 28 | 29 | channel.BasicPublish(exchange: "notifier", 30 | routingKey: "", 31 | basicProperties: null, 32 | body: body); 33 | 34 | Console.WriteLine($"Payment received for amount of {moneyCount}.\nNotifying by 'notifier' Exchange"); 35 | } 36 | } while (true); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /RabbitMQ.FunoutExchange/RabbitMQ.FunoutExchange.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31005.135 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Producer", "Producer\Producer.csproj", "{1EAC6092-362D-4786-9D59-2B78AE47F40B}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Consumer.BankCharger", "Consumer.BankCharger\Consumer.BankCharger.csproj", "{71AD0AEF-087C-4636-B082-EFAAF2C11E72}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Consumer.Tax", "Consumer.Tax\Consumer.Tax.csproj", "{FF4C0C3C-02AE-4A82-8459-E717B1A5E093}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {1EAC6092-362D-4786-9D59-2B78AE47F40B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {1EAC6092-362D-4786-9D59-2B78AE47F40B}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {1EAC6092-362D-4786-9D59-2B78AE47F40B}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {1EAC6092-362D-4786-9D59-2B78AE47F40B}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {71AD0AEF-087C-4636-B082-EFAAF2C11E72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {71AD0AEF-087C-4636-B082-EFAAF2C11E72}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {71AD0AEF-087C-4636-B082-EFAAF2C11E72}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {71AD0AEF-087C-4636-B082-EFAAF2C11E72}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {FF4C0C3C-02AE-4A82-8459-E717B1A5E093}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {FF4C0C3C-02AE-4A82-8459-E717B1A5E093}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {FF4C0C3C-02AE-4A82-8459-E717B1A5E093}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {FF4C0C3C-02AE-4A82-8459-E717B1A5E093}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {56D04728-5C49-4F4D-B9DD-C4559F9EE02E} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /RabbitMQ.HeadersExchange/Consumer.Abroad.Usd/Consumer.Abroad.Usd.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /RabbitMQ.HeadersExchange/Consumer.Abroad.Usd/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using RabbitMQ.Client.Events; 3 | using System.Text; 4 | 5 | namespace Consumer.Abroad.Usd 6 | { 7 | class Program 8 | { 9 | public static void Main() 10 | { 11 | Console.Title = "Consumer: Counts abroad USD transfers only"; 12 | 13 | int counter = 0; 14 | var factory = new ConnectionFactory() { HostName = "localhost" }; 15 | using (var connection = factory.CreateConnection()) 16 | using (var channel = connection.CreateModel()) 17 | { 18 | channel.ExchangeDeclare(exchange: "headers_ex", type: ExchangeType.Headers); 19 | Dictionary headers = new Dictionary(); 20 | headers.Add("x-match", "all"); 21 | headers.Add("currency", "usd"); 22 | headers.Add("transfer", "abroad"); 23 | 24 | var queueName = channel.QueueDeclare().QueueName; 25 | 26 | channel.QueueBind(queue: queueName, 27 | exchange: "headers_ex", 28 | routingKey: "-", 29 | arguments: headers); 30 | 31 | var consumer = new EventingBasicConsumer(channel); 32 | 33 | consumer.Received += (sender, e) => 34 | { 35 | var body = e.Body; 36 | var message = Encoding.UTF8.GetString(body.ToArray()); 37 | 38 | counter++; 39 | 40 | Console.WriteLine($"Received message: {message} {Environment.NewLine}" + 41 | $"Total abroad USD transfers: {counter}"); 42 | }; 43 | 44 | channel.BasicConsume(queue: queueName, 45 | autoAck: true, 46 | consumer: consumer); 47 | 48 | Console.WriteLine($"Subscribed to the queue '{queueName}'"); 49 | Console.WriteLine($"Counts abroad USD transfers only"); 50 | 51 | Console.ReadLine(); 52 | } 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /RabbitMQ.HeadersExchange/Consumer.All.Usd/Consumer.All.Usd.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /RabbitMQ.HeadersExchange/Consumer.All.Usd/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using RabbitMQ.Client.Events; 3 | using System.Text; 4 | 5 | namespace Consumer.All.Usd 6 | { 7 | class Program 8 | { 9 | public static void Main() 10 | { 11 | Console.Title = "Consumer: Counts all USD transfers"; 12 | 13 | int counter = 0; 14 | var factory = new ConnectionFactory() { HostName = "localhost" }; 15 | using (var connection = factory.CreateConnection()) 16 | using (var channel = connection.CreateModel()) 17 | { 18 | channel.ExchangeDeclare(exchange: "headers_ex", type: ExchangeType.Headers); 19 | Dictionary headers = new Dictionary(); 20 | headers.Add("x-match", "any"); //we can ignore that header if it's "any" 21 | headers.Add("currency", "usd"); 22 | 23 | var queueName = channel.QueueDeclare().QueueName; 24 | 25 | channel.QueueBind(queue: queueName, 26 | exchange: "headers_ex", 27 | routingKey: "-", 28 | arguments: headers); 29 | 30 | var consumer = new EventingBasicConsumer(channel); 31 | 32 | consumer.Received += (sender, e) => 33 | { 34 | var body = e.Body; 35 | var message = Encoding.UTF8.GetString(body.ToArray()); 36 | 37 | counter++; 38 | 39 | Console.WriteLine($"Received message: {message} {Environment.NewLine}" + 40 | $"Total USD transfers: {counter}"); 41 | }; 42 | 43 | channel.BasicConsume(queue: queueName, 44 | autoAck: true, 45 | consumer: consumer); 46 | 47 | Console.WriteLine($"Subscribed to the queue '{queueName}'"); 48 | Console.WriteLine($"Counts all USD transfers"); 49 | 50 | Console.ReadLine(); 51 | } 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /RabbitMQ.HeadersExchange/Cunsumer.Internal.All/Cunsumer.Internal.All.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /RabbitMQ.HeadersExchange/Cunsumer.Internal.All/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using RabbitMQ.Client.Events; 3 | using System.Text; 4 | 5 | namespace Cunsumer.Internal.All 6 | { 7 | class Program 8 | { 9 | public static void Main() 10 | { 11 | Console.Title = "Consumer: Counts all internal transfers"; 12 | 13 | int counter = 0; 14 | var factory = new ConnectionFactory() { HostName = "localhost" }; 15 | using (var connection = factory.CreateConnection()) 16 | using (var channel = connection.CreateModel()) 17 | { 18 | channel.ExchangeDeclare(exchange: "headers_ex", type: ExchangeType.Headers); 19 | Dictionary headers = new Dictionary(); 20 | headers.Add("x-match", "any"); 21 | headers.Add("transfer", "internal"); 22 | 23 | var queueName = channel.QueueDeclare().QueueName; 24 | 25 | channel.QueueBind(queue: queueName, 26 | exchange: "headers_ex", 27 | routingKey: "-", 28 | arguments: headers); 29 | 30 | var consumer = new EventingBasicConsumer(channel); 31 | 32 | consumer.Received += (sender, e) => 33 | { 34 | var body = e.Body; 35 | var message = Encoding.UTF8.GetString(body.ToArray()); 36 | 37 | counter++; 38 | 39 | Console.WriteLine($"Received message: {message} {Environment.NewLine}" + 40 | $"Total internal transfers: {counter}"); 41 | }; 42 | 43 | channel.BasicConsume(queue: queueName, 44 | autoAck: true, 45 | consumer: consumer); 46 | 47 | Console.WriteLine($"Subscribed to the queue '{queueName}'"); 48 | Console.WriteLine($"Counts all internal transfers"); 49 | 50 | Console.ReadLine(); 51 | } 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /RabbitMQ.HeadersExchange/Producer/Producer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /RabbitMQ.HeadersExchange/Producer/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using System.Text; 3 | 4 | namespace Producer 5 | { 6 | class Program 7 | { 8 | public static void Main() 9 | { 10 | Console.Title = "Produser"; 11 | 12 | Thread.Sleep(2000); 13 | int count = 0; 14 | Task.Run(() => 15 | { 16 | do 17 | { 18 | int timeToSleep = new Random().Next(2000, 7000); 19 | Thread.Sleep(timeToSleep); 20 | 21 | var factory = new ConnectionFactory() { HostName = "localhost" }; 22 | using (var connection = factory.CreateConnection()) 23 | using (var channel = connection.CreateModel()) 24 | { 25 | channel.ExchangeDeclare(exchange: "headers_ex", type: ExchangeType.Headers); 26 | 27 | Dictionary headers = new Dictionary(); 28 | headers.Add("currency", "usd"); 29 | headers.Add("transfer", "abroad"); 30 | 31 | var properties = channel.CreateBasicProperties(); 32 | properties.Headers = headers; 33 | 34 | string message = $"[{count}] sent with headers: [currencu:usd] [transfer:abroad]"; 35 | 36 | var body = Encoding.UTF8.GetBytes(message); 37 | 38 | channel.BasicPublish(exchange: "headers_ex", 39 | routingKey: "doesnt metter", 40 | basicProperties: properties, 41 | body: body); 42 | 43 | Console.WriteLine($"[{count++} USD transfer from abroad]"); 44 | } 45 | } while (true); 46 | }); 47 | 48 | Task.Run(() => 49 | { 50 | do 51 | { 52 | int timeToSleep = new Random().Next(2000, 5000); 53 | Thread.Sleep(timeToSleep); 54 | 55 | var factory = new ConnectionFactory() { HostName = "localhost" }; 56 | using (var connection = factory.CreateConnection()) 57 | using (var channel = connection.CreateModel()) 58 | { 59 | channel.ExchangeDeclare(exchange: "headers_ex", type: ExchangeType.Headers); 60 | 61 | Dictionary headers = new Dictionary(); 62 | headers.Add("currency", "usd"); 63 | headers.Add("transfer", "internal"); 64 | 65 | var properties = channel.CreateBasicProperties(); 66 | properties.Headers = headers; 67 | 68 | string message = $"[{count}] sent with headers: [currencu:usd] [transfer:internal]"; 69 | 70 | var body = Encoding.UTF8.GetBytes(message); 71 | 72 | channel.BasicPublish(exchange: "headers_ex", 73 | routingKey: "doesnt metter", 74 | basicProperties: properties, 75 | body: body); 76 | 77 | Console.WriteLine($"[{count++} USD transfer internal]"); 78 | } 79 | } while (true); 80 | }); 81 | 82 | Task.Run(() => 83 | { 84 | do 85 | { 86 | int timeToSleep = new Random().Next(2000, 6000); 87 | Thread.Sleep(timeToSleep); 88 | 89 | var factory = new ConnectionFactory() { HostName = "localhost" }; 90 | using (var connection = factory.CreateConnection()) 91 | using (var channel = connection.CreateModel()) 92 | { 93 | channel.ExchangeDeclare(exchange: "headers_ex", type: ExchangeType.Headers); 94 | 95 | Dictionary headers = new Dictionary(); 96 | headers.Add("currency", "eur"); 97 | headers.Add("transfer", "internal"); 98 | 99 | var properties = channel.CreateBasicProperties(); 100 | properties.Headers = headers; 101 | 102 | string message = $"[{count}] sent with headers: [currencu:usd] [transfer:internal]"; 103 | 104 | var body = Encoding.UTF8.GetBytes(message); 105 | 106 | channel.BasicPublish(exchange: "headers_ex", 107 | routingKey: "doesnt metter", 108 | basicProperties: properties, 109 | body: body); 110 | 111 | Console.WriteLine($"[{count++} EUR transfer internal]"); 112 | } 113 | } while (true); 114 | }); 115 | 116 | Console.ReadKey(); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /RabbitMQ.HeadersExchange/RabbitMQ.HeadersExchange.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.0.31903.59 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Producer", "Producer\Producer.csproj", "{7C89306F-4613-49E0-B316-219F2E2AC61D}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Consumer.All.Usd", "Consumer.All.Usd\Consumer.All.Usd.csproj", "{FD538AF7-5E32-4B3B-B883-7CC467C4F1CC}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Consumer.Abroad.Usd", "Consumer.Abroad.Usd\Consumer.Abroad.Usd.csproj", "{38AC21AD-A5C3-446A-BFD6-9C8D6FDE7614}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cunsumer.Internal.All", "Cunsumer.Internal.All\Cunsumer.Internal.All.csproj", "{227029A7-BDEC-449F-8E62-6E536A49B831}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {7C89306F-4613-49E0-B316-219F2E2AC61D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {7C89306F-4613-49E0-B316-219F2E2AC61D}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {7C89306F-4613-49E0-B316-219F2E2AC61D}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {7C89306F-4613-49E0-B316-219F2E2AC61D}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {FD538AF7-5E32-4B3B-B883-7CC467C4F1CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {FD538AF7-5E32-4B3B-B883-7CC467C4F1CC}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {FD538AF7-5E32-4B3B-B883-7CC467C4F1CC}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {FD538AF7-5E32-4B3B-B883-7CC467C4F1CC}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {38AC21AD-A5C3-446A-BFD6-9C8D6FDE7614}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {38AC21AD-A5C3-446A-BFD6-9C8D6FDE7614}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {38AC21AD-A5C3-446A-BFD6-9C8D6FDE7614}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {38AC21AD-A5C3-446A-BFD6-9C8D6FDE7614}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {227029A7-BDEC-449F-8E62-6E536A49B831}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {227029A7-BDEC-449F-8E62-6E536A49B831}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {227029A7-BDEC-449F-8E62-6E536A49B831}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {227029A7-BDEC-449F-8E62-6E536A49B831}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(ExtensibilityGlobals) = postSolution 41 | SolutionGuid = {CE53D601-D07A-4974-AB75-634D4009DE58} 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /RabbitMQ.TopicExchange/Consumer.Ecological/Consumer.Ecological.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RabbitMQ.TopicExchange/Consumer.Ecological/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using RabbitMQ.Client.Events; 3 | using System; 4 | using System.Text; 5 | 6 | namespace Consumer.Ecological 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | var factory = new ConnectionFactory() { HostName = "localhost" }; 13 | using (var connection = factory.CreateConnection()) 14 | using (var channel = connection.CreateModel()) 15 | { 16 | channel.ExchangeDeclare(exchange: "topic_logs", type: ExchangeType.Topic); 17 | 18 | var queueName = channel.QueueDeclare().QueueName; 19 | 20 | channel.QueueBind(queue: queueName, 21 | exchange: "topic_logs", 22 | routingKey: "*.*.*.ecological"); 23 | 24 | var consumer = new EventingBasicConsumer(channel); 25 | 26 | consumer.Received += (sender, e) => 27 | { 28 | var body = e.Body; 29 | var message = Encoding.UTF8.GetString(body.ToArray()); 30 | Console.WriteLine(" Received message: {0}", message); 31 | }; 32 | 33 | channel.BasicConsume(queue: queueName, 34 | autoAck: true, 35 | consumer: consumer); 36 | 37 | Console.WriteLine($"Subscribed to the queue '{queueName}'"); 38 | Console.WriteLine("Listerning to [*.*.*.ecological]"); 39 | 40 | Console.ReadLine(); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /RabbitMQ.TopicExchange/Consumer.Red/Consumer.Red.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RabbitMQ.TopicExchange/Consumer.Red/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using RabbitMQ.Client.Events; 3 | using System; 4 | using System.Text; 5 | 6 | namespace Consumer.Red 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | var factory = new ConnectionFactory() { HostName = "localhost" }; 13 | using (var connection = factory.CreateConnection()) 14 | using (var channel = connection.CreateModel()) 15 | { 16 | channel.ExchangeDeclare(exchange: "topic_logs", type: ExchangeType.Topic); 17 | 18 | var queueName = channel.QueueDeclare().QueueName; 19 | 20 | channel.QueueBind(queue: queueName, 21 | exchange: "topic_logs", 22 | routingKey: "*.red.#"); 23 | 24 | var consumer = new EventingBasicConsumer(channel); 25 | 26 | consumer.Received += (sender, e) => 27 | { 28 | var body = e.Body; 29 | var message = Encoding.UTF8.GetString(body.ToArray()); 30 | Console.WriteLine(" Received message: {0}", message); 31 | }; 32 | 33 | channel.BasicConsume(queue: queueName, 34 | autoAck: true, 35 | consumer: consumer); 36 | 37 | Console.WriteLine($"Subscribed to the queue '{queueName}'"); 38 | Console.WriteLine("Listerning to [*.red.#]"); 39 | 40 | Console.ReadLine(); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /RabbitMQ.TopicExchange/Consumer.Tesla/Consumer.Tesla.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RabbitMQ.TopicExchange/Consumer.Tesla/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using RabbitMQ.Client.Events; 3 | using System; 4 | using System.Text; 5 | 6 | namespace Consumer.Tesla 7 | { 8 | class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | var factory = new ConnectionFactory() { HostName = "localhost" }; 13 | using (var connection = factory.CreateConnection()) 14 | using (var channel = connection.CreateModel()) 15 | { 16 | channel.ExchangeDeclare(exchange: "topic_logs", type: ExchangeType.Topic); 17 | 18 | var queueName = channel.QueueDeclare().QueueName; 19 | 20 | channel.QueueBind(queue: queueName, 21 | exchange: "topic_logs", 22 | routingKey: "Tesla.#"); 23 | 24 | var consumer = new EventingBasicConsumer(channel); 25 | 26 | consumer.Received += (sender, e) => 27 | { 28 | var body = e.Body; 29 | var message = Encoding.UTF8.GetString(body.ToArray()); 30 | Console.WriteLine(" Received message: {0}", message); 31 | }; 32 | 33 | channel.BasicConsume(queue: queueName, 34 | autoAck: true, 35 | consumer: consumer); 36 | 37 | Console.WriteLine($"Subscribed to the queue '{queueName}'"); 38 | Console.WriteLine("Listerning to [Tesla.#]"); 39 | 40 | Console.ReadLine(); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /RabbitMQ.TopicExchange/Producer/Producer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp3.1 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /RabbitMQ.TopicExchange/Producer/Program.cs: -------------------------------------------------------------------------------- 1 | using RabbitMQ.Client; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | using System.Threading; 6 | 7 | namespace Producer 8 | { 9 | class Program 10 | { 11 | private static readonly List cars = new List { "BMW", "Audi", "Tesla", "Mercedes" }; 12 | private static readonly List colors = new List { "red", "white", "black" }; 13 | private static readonly Random random = new Random(); 14 | static void Main(string[] args) 15 | { 16 | var counter = 0; 17 | do 18 | { 19 | int timeToSleep = random.Next(1000, 2000); 20 | Thread.Sleep(timeToSleep); 21 | 22 | var factory = new ConnectionFactory() { HostName = "localhost" }; 23 | using (var connection = factory.CreateConnection()) 24 | using (var channel = connection.CreateModel()) 25 | { 26 | channel.ExchangeDeclare(exchange: "topic_logs", type: ExchangeType.Topic); 27 | 28 | string routingKey = counter % 4 == 0 29 | ? "Tesla.red.fast.ecological" 30 | : counter % 5 == 0 31 | ? "Mercedes.exclusive.expensive.ecological" 32 | : GenerateRoutingKey(); 33 | 34 | string message = $"Message type [{routingKey}] from publisher N {counter}"; 35 | 36 | var body = Encoding.UTF8.GetBytes(message); 37 | 38 | channel.BasicPublish(exchange: "topic_logs", 39 | routingKey: routingKey, 40 | basicProperties: null, 41 | body: body); 42 | 43 | Console.WriteLine($"Message type [{routingKey}] is sent into Topic Exchange [N:{counter++}]"); 44 | } 45 | } while (true); 46 | } 47 | 48 | private static string GenerateRoutingKey() 49 | { 50 | return $"{cars[random.Next(0, 3)]}.{colors[random.Next(0, 2)]}"; 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /RabbitMQ.TopicExchange/RabbitMQ.TopicExchange.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31005.135 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Producer", "Producer\Producer.csproj", "{9A33A45D-A285-45E8-A596-56409F5C6E0C}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Consumer.Ecological", "Consumer.Ecological\Consumer.Ecological.csproj", "{C4E6CF3C-DAFC-4F66-89F7-8DBEAFD5E70A}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Consumer.Red", "Consumer.Red\Consumer.Red.csproj", "{FE9267A7-89B7-437B-AD07-793C88F48304}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Consumer.Tesla", "Consumer.Tesla\Consumer.Tesla.csproj", "{186268F3-418B-4046-A9CA-B148C8CF96DE}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {9A33A45D-A285-45E8-A596-56409F5C6E0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {9A33A45D-A285-45E8-A596-56409F5C6E0C}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {9A33A45D-A285-45E8-A596-56409F5C6E0C}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {9A33A45D-A285-45E8-A596-56409F5C6E0C}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {C4E6CF3C-DAFC-4F66-89F7-8DBEAFD5E70A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {C4E6CF3C-DAFC-4F66-89F7-8DBEAFD5E70A}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {C4E6CF3C-DAFC-4F66-89F7-8DBEAFD5E70A}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {C4E6CF3C-DAFC-4F66-89F7-8DBEAFD5E70A}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {FE9267A7-89B7-437B-AD07-793C88F48304}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {FE9267A7-89B7-437B-AD07-793C88F48304}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {FE9267A7-89B7-437B-AD07-793C88F48304}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {FE9267A7-89B7-437B-AD07-793C88F48304}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {186268F3-418B-4046-A9CA-B148C8CF96DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {186268F3-418B-4046-A9CA-B148C8CF96DE}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {186268F3-418B-4046-A9CA-B148C8CF96DE}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {186268F3-418B-4046-A9CA-B148C8CF96DE}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(ExtensibilityGlobals) = postSolution 41 | SolutionGuid = {18DC65BF-1552-44B9-9672-E87C5E9BAD56} 42 | EndGlobalSection 43 | EndGlobal 44 | --------------------------------------------------------------------------------