From 55cae841c09a1854c10d321b146da897a42ab121 Mon Sep 17 00:00:00 2001 From: xRain Date: Thu, 15 Mar 2018 05:44:40 +0800 Subject: [PATCH] first version for 1.4.3 --- .gitignore | 3 ++ BLogger.cs | 29 +++++++++++++++++ EventServer.cs | 29 +++++++++++++++++ Program.cs | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 12 ++++++++ RpcServer.cs | 29 +++++++++++++++++ test.csproj | 12 ++++++++ 7 files changed, 198 insertions(+) create mode 100644 .gitignore create mode 100644 BLogger.cs create mode 100644 EventServer.cs create mode 100644 Program.cs create mode 100644 README.md create mode 100644 RpcServer.cs create mode 100644 test.csproj diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cb09597 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +out +bin +obj \ No newline at end of file diff --git a/BLogger.cs b/BLogger.cs new file mode 100644 index 0000000..70e007b --- /dev/null +++ b/BLogger.cs @@ -0,0 +1,29 @@ +using System; +using RabbitMQ.Client.Events; +using System.Text; +using Rpc.Synapse.Icarus; +using Newtonsoft.Json.Linq; + +namespace test +{ + public class BLogger : BaseLogger + { + public override void All(JObject data, BasicDeliverEventArgs ea) + { + Console.WriteLine("所有LOG记录: {0} \n{1}", ea.RoutingKey, data.ToString()); + } + + public override void Event(JObject data, BasicDeliverEventArgs ea) + { + Console.WriteLine("事件LOG记录: {0} \n{1}", ea.RoutingKey, data.ToString()); + } + public override void Request(JObject data, BasicDeliverEventArgs ea) + { + Console.WriteLine("请求LOG记录: {0} \n{1}", ea.RoutingKey, data.ToString()); + } + public override void Response(JObject data, BasicDeliverEventArgs ea) + { + Console.WriteLine("响应LOG记录: {0} \n{1}", ea.RoutingKey, data.ToString()); + } + } +} diff --git a/EventServer.cs b/EventServer.cs new file mode 100644 index 0000000..86b37a0 --- /dev/null +++ b/EventServer.cs @@ -0,0 +1,29 @@ +using System; +using System.Text; +using System.Collections.Generic; +using Rpc.Synapse.Icarus; +using RabbitMQ.Client.Events; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +namespace test +{ + public class EventServer : BaseCallback + { + public override Dictionary RegAlias() + { + return new Dictionary(){ + {"dotnet.test","tb"}, + {"ruby.test","tb"}, + {"golang.test","tb"}, + {"java.test","tb"}, + {"python.test","tb"}, + {"php.test","tb"}, + }; + } + public bool tb(JObject data, BasicDeliverEventArgs ea) + { + Console.WriteLine("**收到EVENT: {0}@{1} \n{2}", ea.BasicProperties.Type, ea.BasicProperties.ReplyTo, data.ToString()); + return true; + } + } +} diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..09cb8c6 --- /dev/null +++ b/Program.cs @@ -0,0 +1,84 @@ +using System; +using Rpc.Synapse.Icarus; +using Newtonsoft.Json.Linq; +using Shuttle.Core.Cli; + +namespace test +{ + class Program + { + static void Main(string[] args) + { + var cmd = new Arguments(args); + if (!cmd.Contains("host") || !cmd.Contains("user") || !cmd.Contains("pass") || !cmd.Contains("sys_name")) + { + Console.WriteLine("Usage: dotnet test.dll --host MQ_HOST --user MQ_USER --pass MQ_PASS --sys_name SYSTEM_NAME [--debug] [--log]"); + return; + } + var app = new Synapse(); + app.MqHost = cmd.Get("host"); + app.MqUser = cmd.Get("user"); + app.MqPass = cmd.Get("pass"); + app.SysName = cmd.Get("sys_name"); + app.AppName = "dotnet"; + if (cmd.Contains("debug")) + { + app.Debug = true; + } + app.EventCallback = new EventServer(); + app.RpcCallback = new RpcServer(); + if (cmd.Contains("log")) + { + app.LoggerCallback = new BLogger(); + } + app.Serve(); + string input; + JObject ht; + string[] inputs; + showHelp(); + while (true) + { + Console.Write("Input >> "); + input = Console.ReadLine(); + inputs = input.Split(" "); + switch (inputs[0]) + { + case "event": + if (inputs.Length != 3) + { + showHelp(); + continue; + } + ht = new JObject(); + ht.Add("msg", inputs[2]); + app.SendEvent(inputs[1], ht); + break; + case "rpc": + if (inputs.Length != 4) + { + showHelp(); + continue; + } + ht = new JObject(); + ht.Add("msg", inputs[3]); + JObject res = app.SendRpc(inputs[1], inputs[2], ht); + Console.WriteLine("{0}", res.ToString()); + break; + default: + showHelp(); + break; + } + } + } + + static void showHelp() + { + Console.WriteLine("----------------------------------------------"); + Console.WriteLine("| event usage: |"); + Console.WriteLine("| > event [event] [msg] |"); + Console.WriteLine("| rpc usage: |"); + Console.WriteLine("| > rpc [app] [method] [msg] |"); + Console.WriteLine("----------------------------------------------"); + } + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..4c79a73 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +## 西纳普斯 - synapse (C# Version) +## 测试程序 + +### 此为系统核心交互组件,包含了事件和RPC系统 + +请从release中下载程序包 + +### 需要: +> .net core 2.0 + +### 运行方式: +> dotnet test.dll --host MQ_HOST --user MQ_USER --pass MQ_PASS --sys_name SYSTEM_NAME [--debug] [--log] \ No newline at end of file diff --git a/RpcServer.cs b/RpcServer.cs new file mode 100644 index 0000000..b454781 --- /dev/null +++ b/RpcServer.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; +using System.Text; +using Rpc.Synapse.Icarus; +using RabbitMQ.Client.Events; +using Newtonsoft.Json.Linq; +namespace test +{ + public class RpcServer : BaseCallback + { + public override Dictionary RegAlias() + { + return new Dictionary() + { + {"test","tb"} + }; + } + public JObject tb(JObject data, BasicDeliverEventArgs ea) + { + var ret = new JObject(); + ret.Add("suceess", "I 收到了"); + ret.Add("m", data.GetValue("msg")); + ret.Add("number", 5233); + return ret; + } + + } +} diff --git a/test.csproj b/test.csproj new file mode 100644 index 0000000..b6b32b0 --- /dev/null +++ b/test.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp2.0 + + + + + + +