using EventBus; using TcpEventBus; namespace ActiveMQCommunication { public class MQAnonymousEventData : IAnonymousEventData { EasyMQ.IBus _Bus; private Dictionary dic = new Dictionary(); public MQAnonymousEventData(EasyMQ.IBus socket, string eventName, string hash) { _Bus = socket; EventName = eventName; Hash = hash; dic[nameof(EventName)] = eventName + ";" + typeof(T).FullName; } public string EventName { get; private set; } public string Hash { get; private set; } public void Clear() { } public T Publish(object sender, Properties? properties = null, params object[] data) { bool timeout = false; var msg =this.GetAnonyMsg(data, properties); var val = _Bus.RPC.Request(msg, ref timeout,dic); if (timeout || val == null) return default; return val; } public Task PublishAsync(object sender, Properties? properties = null, params object[] data) { return Task.Run(() => Publish(sender, properties, data)); } public List PublishList(object sender, Properties? properties = null, params object[] data) { bool timeout = false; var msg = this.GetAnonyMsg(data, properties); var val = _Bus.RPC.Request>(msg, ref timeout, dic); if (timeout || val == null) return new List(); return val; } public Task> PublishListAsync(object sender, Properties? properties = null, params object[] data) { return Task.Run(() => PublishList(sender, properties, data)); } public Guid Subscrip(Func, T> func, Properties? properties = null) { _Bus.RPC.Respond((data,pro)=> { return func.Invoke(this, new EventArgs(MsgTool.GetAnonyDatas(data.GetBytes()), Guid.Empty, this)); }, properties == null ? $"{nameof(EventName)}={EventName}" : properties.PropertiesToselector() + $" and {nameof(EventName)}={EventName}"); return Guid.Empty; } public Guid SubscripList(Func, List> func, Properties? properties = null) { _Bus.RPC.Respond>((data, pro) => { return func.Invoke(this, new EventArgs(MsgTool.GetAnonyDatas(data.GetBytes()), Guid.Empty, this)); }, properties == null ? $"{nameof(EventName)}={EventName}" : properties.PropertiesToselector() + $" and {nameof(EventName)}={EventName}"); return Guid.Empty; } public void UnSubscrip(Guid guid) { } } }