-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventClient.cs
35 lines (32 loc) · 1.13 KB
/
EventClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Text;
using RabbitMQ.Client;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Rpc.Synapse.Icarus
{
public class EventClient
{
private Synapse mSynapse;
private IModel mChannel;
public EventClient(Synapse synapse)
{
mSynapse = synapse;
mChannel = mSynapse.CreateChannel(0, "EventClient");
}
public void Send(string eventName, JObject param)
{
var paramJson = JsonConvert.SerializeObject(param);
var router = string.Format("event.{0}.{1}", mSynapse.AppName, eventName);
var props = mChannel.CreateBasicProperties();
props.AppId = mSynapse.AppId;
props.MessageId = Synapse.RandomString();
props.ReplyTo = mSynapse.AppName;
props.Type = eventName;
mChannel.BasicPublish(mSynapse.SysName, router, props, Encoding.UTF8.GetBytes(paramJson));
if (mSynapse.Debug)
{
Synapse.Log(string.Format("Event Publish: {0}@{1} {2}", eventName, mSynapse.AppName, paramJson), Synapse.LogDebug);
}
}
}
}