12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using EventBus;
- namespace ActiveMQCommunication
- {
- public class MQEventData<TData, T> : IEventData<TData, T>
- {
- EasyMQ.IBus _Bus;
- public MQEventData(EasyMQ.IBus bus,string eventName,string hash)
- {
- _Bus = bus;
- EventName = eventName;
- Hash = hash;
- }
- public string EventName { get; private set; }
- public string Hash { get; private set; }
- public void Clear()
- {
- }
- public T Publish(object sender, TData data, Properties? properties = null)
- {
- bool timeout = false;
- var val = _Bus.RPC.Request<TData, T>(data, ref timeout, properties == null ?null: properties.PropertiesToDic());
- if (timeout || val==null) return default;
- return val;
- }
- public Task<T> PublishAsync(object sender, TData data, Properties? properties = null)
- {
- return Task.Run(() => Publish(sender, data, properties));
- }
- public List<T> PublishList(object sender, TData data, Properties? properties = null)
- {
- bool timeout = false;
- var val = _Bus.RPC.Request<TData, List<T>>(data, ref timeout, properties == null ? null : properties.PropertiesToDic());
- if (timeout || val == null) return new List<T>();
- return val;
- }
- public Task<List<T>> PublishListAsync(object sender, TData data, Properties? properties = null)
- {
- return Task.Run(() => PublishList(sender, data, properties));
- }
- public Guid Subscrip(Func<object, EventArgs<TData>, T> func, Properties? properties = null)
- {
- _Bus.RPC.Respond<TData, T>((data, pro) =>
- {
- return func.Invoke(this, new EventArgs<TData>(data, Guid.Empty, this));
- },properties==null?"":properties.PropertiesToselector());
- return Guid.Empty;
- }
- public Guid SubscripList(Func<object, EventArgs<TData>, List<T>> func, Properties? properties = null)
- {
- _Bus.RPC.Respond<TData, List<T>>((data, pro) =>
- {
- return func.Invoke(this, new EventArgs<TData>(data, Guid.Empty, this));
- }, properties == null ? "" : properties.PropertiesToselector());
- return Guid.Empty;
- }
- public void UnSubscrip(Guid guid)
- {
- }
- }
- }
|