Skip to content

Commit

Permalink
first version for 1.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
xrain0610 committed Mar 14, 2018
0 parents commit 55cae84
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
out
bin
obj
29 changes: 29 additions & 0 deletions BLogger.cs
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());
}
}
}
29 changes: 29 additions & 0 deletions EventServer.cs
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;
}
}
}
84 changes: 84 additions & 0 deletions Program.cs
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("----------------------------------------------");
}
}
}
12 changes: 12 additions & 0 deletions README.md
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]
29 changes: 29 additions & 0 deletions RpcServer.cs
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;
}

}
}
12 changes: 12 additions & 0 deletions test.csproj
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>

0 comments on commit 55cae84

Please sign in to comment.