add Synapse System

This commit is contained in:
2023-10-20 12:33:18 +08:00
parent 56b5421290
commit ef721b227b
11 changed files with 576 additions and 10 deletions
+34
View File
@@ -0,0 +1,34 @@
using System;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Unicode;
using Microsoft.Extensions.Logging;
namespace SimApi;
public partial class Synapse
{
private void RunEventClient()
{
EventClientChannel = CreateChannel(0, "EventClient");
}
private void FireEvent(string eventName, object param)
{
var paramJson = JsonSerializer.Serialize(param, new JsonSerializerOptions
{
Encoder = JavaScriptEncoder.Create(UnicodeRanges.All),
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
});
var router = $"event.{Options.AppName}.{eventName}";
var props = EventClientChannel.CreateBasicProperties();
props.AppId = Options.AppId;
props.MessageId = Guid.NewGuid().ToString();
props.ReplyTo = Options.AppName;
props.Type = eventName;
EventClientChannel.BasicPublish(Options.SysName, router, false, props, Encoding.UTF8.GetBytes(paramJson));
Logger.LogDebug("Event Publish: {OptionsAppName}.{EventName}\n{ParamJson}", Options.AppName, eventName,
paramJson);
}
}