MQAnonymousEventData.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using EventBus;
  2. using System.Runtime.CompilerServices;
  3. using System.Text;
  4. using TcpEventBus;
  5. namespace ActiveMQCommunication
  6. {
  7. public class MQAnonymousEventData : IAnonymousEventData
  8. {
  9. EasyMQ.IBus _Bus;
  10. private Dictionary<string, string> dic = new Dictionary<string, string>();
  11. public MQAnonymousEventData(EasyMQ.IBus socket, string eventName, string hash)
  12. {
  13. _Bus = socket;
  14. EventName = eventName;
  15. Hash = hash;
  16. dic[nameof(EventName)] = eventName;
  17. }
  18. public string EventName { get; private set; }
  19. public string Hash { get; private set; }
  20. public void Clear()
  21. {
  22. }
  23. public async void Publish(object sender, Properties? properties = null, params object[] data)
  24. {
  25. var msg = this.GetAnonyMsg(data, properties);
  26. await _Bus.PubSub.PublishAsync(msg, dic);
  27. }
  28. public Task PublishAsync(object sender, Properties? properties = null, params object[] data)
  29. {
  30. var msg = this.GetAnonyMsg(data, properties);
  31. return _Bus.PubSub.PublishAsync(msg, dic);
  32. }
  33. public Guid Subscrip(Action<object, EventArgs<object[]>> action, Properties? properties = null)
  34. {
  35. _Bus.PubSub.Subscribe<DataMsg>((data,pro)=>
  36. {
  37. action?.Invoke(this,new EventArgs<object[]>(MsgTool.GetAnonyDatas(data.GetBytes()),Guid.Empty,this));
  38. }, properties == null ? $"{nameof(EventName)}={EventName}" : properties.PropertiesToselector() + $" and {nameof(EventName)}={EventName}");
  39. return Guid.Empty;
  40. }
  41. public void UnSubscrip(Guid guid)
  42. {
  43. }
  44. }
  45. }