Project Moscato Team Messaging Middleware Implemetation Message Middleware by Golang Operate as Secure, Effectively
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

message.go 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package modules
  2. import "encoding/json"
  3. //import "strconv"
  4. //*****메세지 타입 상수화
  5. const (
  6. KGM = 1 + iota
  7. KSM
  8. PM
  9. SM
  10. RM
  11. WM
  12. )
  13. //*****메세지 틀*****
  14. type Message struct {
  15. from string //ip주소
  16. version string
  17. time string
  18. kind int //종류
  19. }
  20. type MsgUnit interface {
  21. // ConvertToJson - send 전 json형식으로 바꾸는 함수
  22. ConvertToJson() ([]byte, error)
  23. // CheckType - Message의 타입을 알려줌
  24. CheckType() int
  25. }
  26. //*****각 메세지 형식 및 정의**********
  27. //KeyGen 명령 메세지
  28. type KeyGenMsg struct {
  29. Message
  30. iptable []string
  31. }
  32. //Key공유 메세지
  33. type KeyShareMsg struct {
  34. Message
  35. key string
  36. }
  37. //전달할 내용을 담은 메세지
  38. type PublishMsg struct {
  39. Message
  40. topic []int64 //대주제
  41. value []int64 //topic의 세부적인 내용
  42. content []int64 // 내용
  43. }
  44. //구독 정보를 담은 메세지
  45. type SubscriptionMsg struct {
  46. Message
  47. topic []int64 //대주제
  48. value []string //범위 및 세부조건, 피연산자 연산자 순으로 등장
  49. isAlpha bool // 범위연산인지 단순비교연산인지 구분 가능하게 함
  50. }
  51. //Microservice 등록 메세지
  52. type RegisterMsg struct {
  53. Message
  54. }
  55. //Microservice 탈퇴 메세지(없앰)
  56. type WithdrawMsg struct {
  57. Message
  58. }
  59. //**************************
  60. func (msg *KeyGenMsg) ConvertToJson() ([]byte, error) {
  61. js := msg
  62. jsonBytes, err := json.Marshal(js)
  63. return jsonBytes, err
  64. }
  65. func (msg *KeyShareMsg) ConvertToJson() ([]byte, error) {
  66. js := msg
  67. jsonBytes, err := json.Marshal(js)
  68. return jsonBytes, err
  69. }
  70. func (msg *PublishMsg) ConvertToJson() ([]byte, error) {
  71. js := msg
  72. jsonBytes, err := json.Marshal(js)
  73. return jsonBytes, err
  74. }
  75. func (msg *SubscriptionMsg) ConvertToJson() ([]byte, error) {
  76. js := msg
  77. jsonBytes, err := json.Marshal(js)
  78. return jsonBytes, err
  79. }
  80. func (msg *RegisterMsg) ConvertToJson() ([]byte, error) {
  81. js := msg
  82. jsonBytes, err := json.Marshal(js)
  83. return jsonBytes, err
  84. }
  85. func (msg *WithdrawMsg) ConvertToJson() ([]byte, error) {
  86. js := msg
  87. jsonBytes, err := json.Marshal(js)
  88. return jsonBytes, err
  89. }
  90. func (msg Message) CheckType() int {
  91. return msg.kind
  92. }
  93. //KeyGenMsg 생성자
  94. func NewKeyGenMsg(table *MStable) *KeyGenMsg{
  95. m:= &KeyGenMsg{}
  96. for _,value:= range table.NodeTable{
  97. m.iptable=append(m.iptable,value.Getipaddr())
  98. }
  99. return m
  100. }