Quellcode durchsuchen

finish dotnet exercises

Grega Bremec vor 3 Jahren
Ursprung
Commit
2dcc202de4

+ 2 - 0
.gitignore

@@ -5,4 +5,6 @@ tmp*
 broker
 target
 .vscode
+bin
+obj
 amq-clients-2.10.4-dotnet-core

+ 25 - 0
dotnet/metrics-collector/Program.cs

@@ -0,0 +1,25 @@
+namespace metrics_collector
+{
+    using System;
+    // TODO: import library
+    class MetricsCollector
+    {
+        static void Main(string[] args)
+        {
+            string url = "amqp://localhost:61616";
+            string address = "sampleQueue";
+
+            // TODO: create and initialise messaging objects
+
+            Console.WriteLine("Receiving random metrics from " + url + "/" + address);
+            while (true) {
+                // TODO: receive the message, if any
+                // TODO: only display the message if there is one
+                Console.WriteLine("Got: " + null);
+                //continue;
+
+                System.Threading.Thread.Sleep(1000);
+            }
+        }
+    }
+}

+ 11 - 0
dotnet/metrics-collector/metrics-collector.csproj

@@ -0,0 +1,11 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net5.0</TargetFramework>
+    <RootNamespace>metrics_collector</RootNamespace>
+  </PropertyGroup>
+  <ItemGroup>
+    <PackageReference Include="amq-dotnet" Version="2.4.0" />
+  </ItemGroup>
+</Project>

+ 24 - 0
dotnet/metrics-publish/Program.cs

@@ -0,0 +1,24 @@
+namespace send
+{
+    using System;
+    // TODO: import library
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            string url = "amqp://localhost:61616";
+            string addr = "sampleTopic";
+
+            // TODO: create and initialise messaging objects
+
+            Console.WriteLine("Sending random metrics to " + url + "/" + addr);
+
+            var rand = new Random();
+            while (true) {
+                // TODO: send a message containing a random number to the topic
+                Console.WriteLine("Sent: " + rand.Next(10000).ToString());
+                System.Threading.Thread.Sleep(1000);
+            }
+        }
+    }
+}

+ 10 - 0
dotnet/metrics-publish/publish.csproj

@@ -0,0 +1,10 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net5.0</TargetFramework>
+  </PropertyGroup>
+  <ItemGroup>
+    <PackageReference Include="amq-dotnet" Version="2.4.0"/>
+  </ItemGroup>
+</Project>

+ 23 - 0
dotnet/metrics-sender/Program.cs

@@ -0,0 +1,23 @@
+namespace metrics_sender
+{
+    using System;
+    // TODO: import library
+    class MetricsSender
+    {
+        static void Main(string[] args)
+        {
+            string url = "amqp://localhost:61616";
+            string address = "sampleQueue";
+
+            // TODO: create and initialise messaging objects
+
+            Console.WriteLine("Sending random metrics to " + url + "/" + address);
+            var rand = new Random();
+            while (true) {
+                // TODO: send a new random number to the message queue
+                Console.WriteLine("Sent: " + rand.Next(10000).ToString());
+                System.Threading.Thread.Sleep(1000);
+            }
+        }
+    }
+}

+ 11 - 0
dotnet/metrics-sender/metrics-sender.csproj

@@ -0,0 +1,11 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net5.0</TargetFramework>
+    <RootNamespace>metrics_sender</RootNamespace>
+  </PropertyGroup>
+  <ItemGroup>
+    <PackageReference Include="amq-dotnet" Version="2.4.0" />
+  </ItemGroup>
+</Project>

+ 53 - 0
dotnet/metrics-subscribe/Program.cs

@@ -0,0 +1,53 @@
+namespace receive
+{
+    using System;
+    // TODO: import all the libraries, including Framing, Sasl, and Types
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            string url = "amqp://localhost:61616";
+            string addr = "sampleTopic";
+
+            bool durable = false;
+            string cid = "";
+            if (args.Length > 0) {
+                durable = bool.Parse(args[0]);
+            }
+
+            if (durable && args.Length > 1) {
+                cid = args[1];
+            } else if (durable) {
+                cid = Guid.NewGuid().ToString();
+            }
+
+            // TODO: create an address
+            if (durable) {
+                // TODO: create a connection using a client ID
+            } else {
+                // TODO: create an anonymous connection
+            }
+
+            Console.WriteLine("Created new " + (durable ? "" : "non-") + "durable subscriber" + (durable ? " with ID " + cid : ""));
+
+            // TODO: obtain the session
+
+            if (durable) {
+                // TODO: create a durable receiver
+            } else {
+                // TODO: create a non-durable receiver
+            }
+
+            Console.WriteLine("Receiving random metrics from " + url + "/" + addr);
+            while (true) {
+                // TODO: receive a message, if there is one
+                // TODO: only write out the message if there was one
+                Console.WriteLine("Got: " + null);
+                //continue;
+
+                System.Threading.Thread.Sleep(1000);
+            }
+
+        }
+    }
+}

+ 10 - 0
dotnet/metrics-subscribe/subscribe.csproj

@@ -0,0 +1,10 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <TargetFramework>net5.0</TargetFramework>
+  </PropertyGroup>
+  <ItemGroup>
+    <PackageReference Include="amq-dotnet" Version="2.4.0"/>
+  </ItemGroup>
+</Project>