123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using EventBus;
- using TcpEventBus;
- namespace ActiveMQCommunication
- {
- public class MQAnonymousEventData<T> : IAnonymousEventData<T>
- {
- EasyMQ.IBus _Bus;
- private Dictionary<string, string> dic = new Dictionary<string, string>();
- 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<DataMsg, T>(msg, ref timeout,dic);
- if (timeout || val == null) return default;
- return val;
- }
- public Task<T> PublishAsync(object sender, Properties? properties = null, params object[] data)
- {
- return Task.Run(() => Publish(sender, properties, data));
- }
- public List<T> PublishList(object sender, Properties? properties = null, params object[] data)
- {
- bool timeout = false;
- var msg = this.GetAnonyMsg(data, properties);
- var val = _Bus.RPC.Request<DataMsg, List<T>>(msg, ref timeout, dic);
- if (timeout || val == null) return new List<T>();
- return val;
- }
- public Task<List<T>> PublishListAsync(object sender, Properties? properties = null, params object[] data)
- {
- return Task.Run(() => PublishList(sender, properties, data));
- }
- public Guid Subscrip(Func<object, EventArgs<object[]>, T> func, Properties? properties = null)
- {
- _Bus.RPC.Respond<DataMsg,T>((data,pro)=>
- {
- return func.Invoke(this, new EventArgs<object[]>(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<object, EventArgs<object[]>, List<T>> func, Properties? properties = null)
- {
- _Bus.RPC.Respond<DataMsg, List<T>>((data, pro) =>
- {
- return func.Invoke(this, new EventArgs<object[]>(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)
- {
- }
- }
- }
|