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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. func (msg Message) From() string {
  21. return msg.from
  22. }
  23. func (msg Message) Version() string {
  24. return msg.version
  25. }
  26. func (msg Message) Time() string {
  27. return msg.time
  28. }
  29. func (msg Message) Kind() int {
  30. return msg.kind
  31. }
  32. type MsgUnit interface {
  33. // ConvertToJson - send 전 json형식으로 바꾸는 함수
  34. ConvertToJson() ([]byte, error)
  35. // CheckType - Message의 타입을 알려줌
  36. CheckType() int
  37. }
  38. //*****각 메세지 형식 및 정의**********
  39. //KeyGen 명령 메세지
  40. type KeyGenMsg struct {
  41. Message
  42. iptable []string
  43. }
  44. //Key공유 메세지
  45. type KeyShareMsg struct {
  46. Message
  47. key string
  48. }
  49. //전달할 내용을 담은 메세지
  50. type PublishMsg struct {
  51. Message
  52. topic []int64 //대주제
  53. value []int64 //topic의 세부적인 내용
  54. content []int64 // 내용
  55. }
  56. //구독 정보를 담은 메세지
  57. type SubscriptionMsg struct {
  58. Message
  59. topic []int64 //대주제
  60. value []int64 //피연산자
  61. operator []string //연산자
  62. isAlpha bool // 범위연산인지 단순비교연산인지 구분 가능하게 함
  63. }
  64. //Microservice 등록 메세지
  65. type RegisterMsg struct {
  66. Message
  67. }
  68. //Microservice 탈퇴 메세지(없앰)
  69. type WithdrawMsg struct {
  70. Message
  71. }
  72. //**************************
  73. func (msg *KeyGenMsg) ConvertToJson() ([]byte, error) {
  74. js := msg
  75. jsonBytes, err := json.Marshal(js)
  76. return jsonBytes, err
  77. }
  78. func (msg *KeyShareMsg) ConvertToJson() ([]byte, error) {
  79. js := msg
  80. jsonBytes, err := json.Marshal(js)
  81. return jsonBytes, err
  82. }
  83. func (msg *PublishMsg) ConvertToJson() ([]byte, error) {
  84. js := msg
  85. jsonBytes, err := json.Marshal(js)
  86. return jsonBytes, err
  87. }
  88. func (msg *SubscriptionMsg) ConvertToJson() ([]byte, error) {
  89. js := msg
  90. jsonBytes, err := json.Marshal(js)
  91. return jsonBytes, err
  92. }
  93. func (msg *RegisterMsg) ConvertToJson() ([]byte, error) {
  94. js := msg
  95. jsonBytes, err := json.Marshal(js)
  96. return jsonBytes, err
  97. }
  98. func (msg *WithdrawMsg) ConvertToJson() ([]byte, error) {
  99. js := msg
  100. jsonBytes, err := json.Marshal(js)
  101. return jsonBytes, err
  102. }
  103. func (msg Message) CheckType() int {
  104. return msg.kind
  105. }
  106. //KeyGenMsg 생성자
  107. func NewKeyGenMsg(table *MStable) *KeyGenMsg{
  108. m:= &KeyGenMsg{}
  109. for _,value:= range table.NodeTable{
  110. m.iptable=append(m.iptable,value.Getipaddr())
  111. }
  112. return m
  113. }