message.go 985 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package ruleEngine
  2. import "time"
  3. type Message struct {
  4. QueueName string
  5. Id string
  6. Ts time.Time
  7. Type string
  8. Data string
  9. RuleChanId string
  10. RuleNodeId string
  11. Callback IMessageCallBack
  12. }
  13. // IMessageCallBack message call back
  14. type IMessageCallBack interface {
  15. // on success do sth.
  16. OnSuccess()
  17. // on failure do sth.
  18. OnFailure(err error)
  19. // on process start do sth.
  20. onProcessingStart(ruleNodeInfo *RuleNodeInfo)
  21. // on process end do sth.
  22. onProcessingEnd(ruleNodeId string)
  23. }
  24. type emptyCallBack struct {
  25. }
  26. func (e emptyCallBack) onProcessingStart(ruleNodeInfo *RuleNodeInfo) {
  27. }
  28. func (e emptyCallBack) onProcessingEnd(ruleNodeId string) {
  29. }
  30. var EmptyCallBack = emptyCallBack{}
  31. func (e emptyCallBack) OnSuccess() {
  32. }
  33. func (e emptyCallBack) OnFailure(err error) {
  34. }
  35. // GetCallBack get message call back
  36. func (a *Message) GetCallBack() IMessageCallBack {
  37. if a.Callback == nil {
  38. return EmptyCallBack
  39. } else {
  40. return a.Callback
  41. }
  42. }