MQEventData{TData}.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using EventBus;
  2. namespace ActiveMQCommunication
  3. {
  4. public class MQEventData<TData> : IEventData<TData>
  5. {
  6. private EasyMQ.IBus _Bus;
  7. public MQEventData(EasyMQ.IBus bus,string eventName,string hash)
  8. {
  9. _Bus = bus;
  10. EventName = eventName;
  11. Hash = hash;
  12. }
  13. public string EventName { get;private set; }
  14. public string Hash { get; private set; }
  15. public void Clear()
  16. {
  17. }
  18. public async void Publish(object sender, TData data, Properties? properties = null)
  19. {
  20. await _Bus.PubSub.PublishAsync(data, properties == null ? null : properties.PropertiesToDic());
  21. }
  22. public Task PublishAsync(object sender, TData data, Properties? properties = null)
  23. {
  24. return _Bus.PubSub.PublishAsync(data, properties == null ? null : properties.PropertiesToDic());
  25. }
  26. public Guid Subscrip(Action<object, EventArgs<TData>> action, Properties? properties = null)
  27. {
  28. _Bus.PubSub.Subscribe<TData>((data, pro) =>
  29. {
  30. action?.Invoke(this, new EventArgs<TData>(data, Guid.Empty, this));
  31. },properties==null ?"":properties.PropertiesToselector());
  32. return Guid.Empty;
  33. }
  34. public void UnSubscrip(Guid guid)
  35. {
  36. }
  37. }
  38. }