Skip to content

Commit

Permalink
Support golang sdk (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiehongfeng100 committed Mar 6, 2022
1 parent 5897999 commit ab87459
Show file tree
Hide file tree
Showing 47 changed files with 2,162 additions and 0 deletions.
33 changes: 33 additions & 0 deletions eventmesh-sdk-go/common/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package common

var Constants = struct {
LANGUAGE_GO string
HTTP_PROTOCOL_PREFIX string
HTTPS_PROTOCOL_PREFIX string
PROTOCOL_TYPE string
PROTOCOL_VERSION string
PROTOCOL_DESC string
DEFAULT_HTTP_TIME_OUT int64
EVENTMESH_MESSAGE_CONST_TTL string

// Client heartbeat interval
HEARTBEAT int64

// Protocol type
CLOUD_EVENTS_PROTOCOL_NAME string
EM_MESSAGE_PROTOCOL_NAME string
OPEN_MESSAGE_PROTOCOL_NAME string
}{
LANGUAGE_GO: "GO",
HTTP_PROTOCOL_PREFIX: "http://",
HTTPS_PROTOCOL_PREFIX: "https://",
PROTOCOL_TYPE: "protocoltype",
PROTOCOL_VERSION: "protocolversion",
PROTOCOL_DESC: "protocoldesc",
DEFAULT_HTTP_TIME_OUT: 15000,
EVENTMESH_MESSAGE_CONST_TTL: "ttl",
HEARTBEAT: 30 * 1000,
CLOUD_EVENTS_PROTOCOL_NAME: "cloudevents",
EM_MESSAGE_PROTOCOL_NAME: "eventmeshmessage",
OPEN_MESSAGE_PROTOCOL_NAME: "openmessage",
}
9 changes: 9 additions & 0 deletions eventmesh-sdk-go/common/protocol/http/body/body.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package body

type Body struct {
ToMap map[string]interface{}
}

func (b *Body) BuildBody(requestCode string, originalMap map[string]interface{}) *Body {
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package client

import (
"eventmesh/common/protocol/http/body"
)

var HeartbeatRequestBodyKey = struct {
CLIENTTYPE string
CONSUMERGROUP string
HEARTBEATENTITIES string
}{
CLIENTTYPE: "clientType",
HEARTBEATENTITIES: "heartbeatEntities",
CONSUMERGROUP: "consumerGroup",
}

type HeartbeatEntity struct {
Topic string `json:"topic"`
Url string `json:"url"`
ServiceId string `json:"serviceId"`
InstanceId string `json:"instanceId"`
}

type HeartbeatRequestBody struct {
body.Body
consumerGroup string
clientType string
heartbeatEntities string
}

func (h *HeartbeatRequestBody) ConsumerGroup() string {
return h.consumerGroup
}

func (h *HeartbeatRequestBody) SetConsumerGroup(consumerGroup string) {
h.consumerGroup = consumerGroup
}

func (h *HeartbeatRequestBody) ClientType() string {
return h.clientType
}

func (h *HeartbeatRequestBody) SetClientType(clientType string) {
h.clientType = clientType
}

func (h *HeartbeatRequestBody) HeartbeatEntities() string {
return h.heartbeatEntities
}

func (h *HeartbeatRequestBody) SetHeartbeatEntities(heartbeatEntities string) {
h.heartbeatEntities = heartbeatEntities
}

func (h *HeartbeatRequestBody) BuildBody(bodyParam map[string]interface{}) *HeartbeatRequestBody {
return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package client

import (
"eventmesh/common/protocol"
"eventmesh/common/protocol/http/body"
)

var SubscribeRequestBodyKey = struct {
TOPIC string
URL string
CONSUMERGROUP string
}{
TOPIC: "topic",
URL: "url",
CONSUMERGROUP: "consumerGroup",
}

type SubscribeRequestBody struct {
body.Body
topics []protocol.SubscriptionItem
url string
consumerGroup string
}
20 changes: 20 additions & 0 deletions eventmesh-sdk-go/common/protocol/http/common/client_type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package common

type ClientType struct {
Type int `json:"type"`
Desc string `json:"desc"`
}

var DefaultClientType = struct {
PUB ClientType
SUB ClientType
}{
PUB: ClientType{
Type: 1,
Desc: "Client for publishing",
},
SUB: ClientType{
Type: 2,
Desc: "Client for subscribing",
},
}
12 changes: 12 additions & 0 deletions eventmesh-sdk-go/common/protocol/http/common/eventmesh_ret_code.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package common

type EventMeshRetCode struct {
RetCode int `json:"retCode"`
ErrMsg string `json:"errMsg"`
}

var DefaultEventMeshRetCode = struct {
SUCCESS EventMeshRetCode
}{
SUCCESS: EventMeshRetCode{RetCode: 0, ErrMsg: "success"},
}
70 changes: 70 additions & 0 deletions eventmesh-sdk-go/common/protocol/http/common/protocol_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package common

type ClientInstanceKey struct {
//Protocol layer requester description
ENV string
IDC string
SYS string
PID string
IP string
USERNAME string
PASSWORD string
BIZSEQNO string
UNIQUEID string
}

type EventMeshInstanceKey struct {
//Protocol layer EventMesh description
EVENTMESHCLUSTER string
EVENTMESHIP string
EVENTMESHENV string
EVENTMESHIDC string
}

var ProtocolKey = struct {
REQUEST_CODE string
LANGUAGE string
VERSION string
PROTOCOL_TYPE string
PROTOCOL_VERSION string
PROTOCOL_DESC string

ClientInstanceKey ClientInstanceKey

EventMeshInstanceKey EventMeshInstanceKey

//return of CLIENT <-> EventMesh
RETCODE string
RETMSG string
RESTIME string
}{
REQUEST_CODE: "code",
LANGUAGE: "language",
VERSION: "version",
PROTOCOL_TYPE: "protocoltype",
PROTOCOL_VERSION: "protocolversion",
PROTOCOL_DESC: "protocoldesc",

ClientInstanceKey: ClientInstanceKey{
ENV: "env",
IDC: "idc",
SYS: "sys",
PID: "pid",
IP: "ip",
USERNAME: "username",
PASSWORD: "passwd",
BIZSEQNO: "bizseqno",
UNIQUEID: "uniqueid",
},

EventMeshInstanceKey: EventMeshInstanceKey{
EVENTMESHCLUSTER: "eventmeshcluster",
EVENTMESHIP: "eventmeship",
EVENTMESHENV: "eventmeshenv",
EVENTMESHIDC: "eventmeshidc",
},

RETCODE: "retCode",
RETMSG: "retMsg",
RESTIME: "resTime",
}
25 changes: 25 additions & 0 deletions eventmesh-sdk-go/common/protocol/http/common/protocol_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package common

type ProtocolVersion struct {
version string
}

func (p *ProtocolVersion) Version() string {
return p.version
}

func (p *ProtocolVersion) SetVersion(version string) {
p.version = version
}

var DefaultProtocolVersion = struct {
V1 ProtocolVersion
V2 ProtocolVersion
}{
V1: ProtocolVersion{
version: "1.0",
},
V2: ProtocolVersion{
version: "2.0",
},
}
80 changes: 80 additions & 0 deletions eventmesh-sdk-go/common/protocol/http/common/request_code.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package common

type RequestCode struct {
RequestCode int `json:"requestCode"`
Desc string `json:"desc"`
}

var DefaultRequestCode = struct {
MSG_BATCH_SEND RequestCode
MSG_BATCH_SEND_V2 RequestCode
MSG_SEND_SYNC RequestCode
MSG_SEND_ASYNC RequestCode
HTTP_PUSH_CLIENT_ASYNC RequestCode
HTTP_PUSH_CLIENT_SYNC RequestCode
REGISTER RequestCode
UNREGISTER RequestCode
HEARTBEAT RequestCode
SUBSCRIBE RequestCode
UNSUBSCRIBE RequestCode
REPLY_MESSAGE RequestCode
ADMIN_METRICS RequestCode
ADMIN_SHUTDOWN RequestCode
}{
MSG_BATCH_SEND: RequestCode{
RequestCode: 102,
Desc: "SEND BATCH MSG",
},
MSG_BATCH_SEND_V2: RequestCode{
RequestCode: 107,
Desc: "SEND BATCH MSG V2",
},
MSG_SEND_SYNC: RequestCode{
RequestCode: 101,
Desc: "SEND SINGLE MSG SYNC",
},
MSG_SEND_ASYNC: RequestCode{
RequestCode: 104,
Desc: "SEND SINGLE MSG ASYNC",
},
HTTP_PUSH_CLIENT_ASYNC: RequestCode{
RequestCode: 105,
Desc: "PUSH CLIENT BY HTTP POST",
},
HTTP_PUSH_CLIENT_SYNC: RequestCode{
RequestCode: 106,
Desc: "PUSH CLIENT BY HTTP POST",
},
REGISTER: RequestCode{
RequestCode: 201,
Desc: "REGISTER",
},
UNREGISTER: RequestCode{
RequestCode: 202,
Desc: "UNREGISTER",
},
HEARTBEAT: RequestCode{
RequestCode: 203,
Desc: "HEARTBEAT",
},
SUBSCRIBE: RequestCode{
RequestCode: 206,
Desc: "SUBSCRIBE",
},
UNSUBSCRIBE: RequestCode{
RequestCode: 207,
Desc: "UNSUBSCRIBE",
},
REPLY_MESSAGE: RequestCode{
RequestCode: 301,
Desc: "REPLY MESSAGE",
},
ADMIN_METRICS: RequestCode{
RequestCode: 603,
Desc: "ADMIN METRICS",
},
ADMIN_SHUTDOWN: RequestCode{
RequestCode: 601,
Desc: "ADMIN SHUTDOWN",
},
}
Loading

0 comments on commit ab87459

Please sign in to comment.