Event.java 900 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package com.primeton.dgs.kernel.core.message;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. /**
  5. * <pre>
  6. *
  7. * Created by zhaopx.
  8. * User: zhaopx
  9. * Date: 2019/11/11
  10. * Time: 16:02
  11. *
  12. * </pre>
  13. *
  14. * @author zhaopx
  15. */
  16. public class Event<T> {
  17. /**
  18. * 包含的消息 头
  19. */
  20. private final Map<String, Object> header = new HashMap<>(4);
  21. /**
  22. * 要发送的通道
  23. */
  24. private final String topic;
  25. /**
  26. * 消息体
  27. */
  28. private final T payload;
  29. public Event(String topic, T payload) {
  30. this.topic = topic;
  31. this.payload = payload;
  32. }
  33. public void addHeader(String key, Object value) {
  34. header.put(key, value);
  35. }
  36. public Map<String, Object> getHeader() {
  37. return header;
  38. }
  39. public String getTopic() {
  40. return topic;
  41. }
  42. public T getPayload() {
  43. return payload;
  44. }
  45. }