Selaa lähdekoodia

dotnet solutions

Grega Bremec 3 vuotta sitten
vanhempi
commit
22da957a3e

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

@@ -0,0 +1,30 @@
+namespace metrics_collector
+{
+    using System;
+    using Amqp;
+    class MetricsCollector
+    {
+        static void Main(string[] args)
+        {
+            string url = "amqp://localhost:61616";
+            string address = "sampleQueue";
+
+            Address a = new Address(url);
+            Connection c = new Connection(a);
+            Session s = new Session(c);
+            ReceiverLink rl = new ReceiverLink(s, "receiver", address);
+
+            Console.WriteLine("Receiving random metrics from " + url + "/" + address);
+            while (true) {
+                Message m = rl.Receive();
+                rl.Accept(m);
+                if (m != null) {
+                    Console.WriteLine("Got: " + m.Body.ToString());
+                    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>

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

@@ -0,0 +1,29 @@
+using System;
+using Amqp;
+
+namespace send
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            string url = "amqp://localhost:61616";
+            string addr = "sampleTopic";
+
+            Address a = new Address(url);
+            Connection c = new Connection(a);
+            Session s = new Session(c);
+            SenderLink sl = new SenderLink(s, "sender", addr);
+
+            Console.WriteLine("Sending random metrics to " + url + "/" + addr);
+
+            var rand = new Random();
+            while (true) {
+                Message msg = new Message(rand.Next(10000).ToString());
+                sl.Send(msg);
+                Console.WriteLine("Sent: " + msg.Body.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>

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

@@ -0,0 +1,28 @@
+namespace metrics_sender
+{
+    using System;
+    using Amqp;
+
+    class MetricsSender
+    {
+        static void Main(string[] args)
+        {
+            string url = "amqp://localhost:61616";
+            string address = "sampleQueue";
+
+            Address addr = new Address(url);
+            Connection c = new Connection(addr);
+            Session s = new Session(c);
+            SenderLink sl = new SenderLink(s, "sender", address);
+
+            Console.WriteLine("Sending random metrics to " + url + "/" + address);
+            var rand = new Random();
+            while (true) {
+                Message msg = new Message(rand.Next(10000).ToString());
+                sl.Send(msg);
+                Console.WriteLine("Sent: " + msg.Body.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>

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

@@ -0,0 +1,68 @@
+using System;
+using Amqp;
+using Amqp.Framing;
+using Amqp.Sasl;
+using Amqp.Types;
+
+namespace receive
+{
+    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();
+            }
+
+            Address a = new Address(url);
+            Connection c;
+            if (durable) {
+                c = new Connection(a, SaslProfile.Anonymous,
+                                            new Open() { ContainerId = cid },
+                                            null);
+            } else {
+                c = new Connection(a);
+            }
+
+            Console.WriteLine("Created new " + (durable ? "" : "non-") + "durable subscriber" + (durable ? " with ID " + cid : ""));
+
+            Session s = new Session(c);
+
+            ReceiverLink rl;
+
+            if (durable) {
+                Source src = new Source() {
+                    Address = addr,
+                    Durable = 2,
+                    ExpiryPolicy = new Symbol("never"),
+                };
+                rl = new ReceiverLink(s, "receiver", src, null);
+            } else {
+                rl = new ReceiverLink(s, "receiver", addr);
+            }
+
+            Console.WriteLine("Receiving random metrics from " + url + "/" + addr);
+            while (true) {
+                Message m = rl.Receive();
+                rl.Accept(m);
+                if (m != null) {
+                    Console.WriteLine("Got: " + m.Body.ToString());
+                    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>