-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 55cae84
Showing
7 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
out | ||
bin | ||
obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string, string> RegAlias() | ||
{ | ||
return new Dictionary<string, string>(){ | ||
{"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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string>("host"); | ||
app.MqUser = cmd.Get<string>("user"); | ||
app.MqPass = cmd.Get<string>("pass"); | ||
app.SysName = cmd.Get<string>("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("----------------------------------------------"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string, string> RegAlias() | ||
{ | ||
return new Dictionary<string, string>() | ||
{ | ||
{"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; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Shuttle.Core.Cli" Version="10.0.0" /> | ||
<PackageReference Include="Rpc.Synpase.Icarus" Version="1.4.3" /> | ||
</ItemGroup> | ||
</Project> |