Project Moscato Team Messaging Middleware Implemetation Message Middleware by Golang Operate as Secure, Effectively
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. subscription []int64 //대주제
  41. content []int64 // 내용
  42. }
  43. //구독 정보를 담은 메세지
  44. type SubscriptionMsg struct {
  45. Message
  46. subscription []int64 //대주제
  47. content []int64 //내용
  48. value string //범위
  49. }
  50. //Microservice 등록 메세지
  51. type RegisterMsg struct {
  52. Message
  53. }
  54. //Microservice 탈퇴 메세지
  55. type WithdrawMsg struct {
  56. Message
  57. }
  58. //**************************
  59. func (msg *KeyGenMsg) ConvertToJson() ([]byte, error) {
  60. js := msg
  61. jsonBytes, err := json.Marshal(js)
  62. return jsonBytes, err
  63. }
  64. func (msg *KeyShareMsg) ConvertToJson() ([]byte, error) {
  65. js := msg
  66. jsonBytes, err := json.Marshal(js)
  67. return jsonBytes, err
  68. }
  69. func (msg *PublishMsg) ConvertToJson() ([]byte, error) {
  70. js := msg
  71. jsonBytes, err := json.Marshal(js)
  72. return jsonBytes, err
  73. }
  74. func (msg *SubscriptionMsg) ConvertToJson() ([]byte, error) {
  75. js := msg
  76. jsonBytes, err := json.Marshal(js)
  77. return jsonBytes, err
  78. }
  79. func (msg *RegisterMsg) ConvertToJson() ([]byte, error) {
  80. js := msg
  81. jsonBytes, err := json.Marshal(js)
  82. return jsonBytes, err
  83. }
  84. func (msg *WithdrawMsg) ConvertToJson() ([]byte, error) {
  85. js := msg
  86. jsonBytes, err := json.Marshal(js)
  87. return jsonBytes, err
  88. }
  89. func (msg Message) CheckType() int {
  90. return msg.kind
  91. }
  92. //KeyGenMsg 생성자
  93. func NewKeyGenMsg(table *MStable) *KeyGenMsg{
  94. m:= &KeyGenMsg{}
  95. for _,value:= range table.NodeTable{
  96. m.iptable=append(m.iptable,value.Getipaddr())
  97. }
  98. return m
  99. }