Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go SDK for EventMesh gRPC #911

Merged
merged 47 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
61501c5
add grpc-sdk moudle
qqeasonchen Mar 2, 2022
94cf229
Merge pull request #800 from qqeasonchen/grpc-sdk
qqeasonchen Mar 2, 2022
d137a9f
rename moudle
qqeasonchen Mar 2, 2022
c74ee6b
Merge pull request #801 from qqeasonchen/grpc-sdk
qqeasonchen Mar 2, 2022
3602ba0
Delete README.md
qqeasonchen Mar 2, 2022
dc6bd50
Support golang sdk (#762)
xiehongfeng100 Mar 6, 2022
c9f408f
Merge pull request #803 from xiehongfeng100/go-sdk
qqeasonchen Apr 1, 2022
8732d4e
1. change the module to github.com/apache/incubator-eventmesh/eventme…
walleliu1016 Apr 3, 2022
9bcfd3e
add logger api, remove main.go code, add simple readme.md
walleliu1016 Apr 3, 2022
c12e490
update logger api, add internal package
walleliu1016 Apr 3, 2022
4f9ee55
update proto go files
walleliu1016 Apr 4, 2022
2c48df4
add consumer, producer, heartbeat
walleliu1016 Apr 4, 2022
2b48dfd
add msg dispatcher on rece msg from mesh server
walleliu1016 Apr 4, 2022
66b5d1a
add client api
walleliu1016 Apr 6, 2022
0ae9bfa
add goroutine pool panic handler
walleliu1016 Apr 6, 2022
3e0703c
setup the idg, add test
walleliu1016 Apr 13, 2022
0e86f31
update log
walleliu1016 Apr 14, 2022
d12c364
add test case for rule
walleliu1016 Apr 14, 2022
1b7e3fd
add fake server for test
walleliu1016 Apr 15, 2022
7af142e
add fake server for test
walleliu1016 Apr 15, 2022
7336ef8
add test case
walleliu1016 Apr 15, 2022
9c99e54
add fake server test
walleliu1016 Apr 17, 2022
aea36c7
add example
walleliu1016 Apr 17, 2022
a5fec9f
add example
walleliu1016 Apr 18, 2022
c12948f
update README.md
walleliu1016 Apr 18, 2022
61dd832
update grpc proto package
walleliu1016 Apr 19, 2022
40d60b1
heartbeat ok
walleliu1016 Apr 20, 2022
2a91442
publish, batch publish ok
walleliu1016 Apr 20, 2022
d4982f4
change logic, only support one server
walleliu1016 May 2, 2022
6704e7a
add webhook fake server
walleliu1016 May 2, 2022
9e2dfc8
add webhook fake server
walleliu1016 May 2, 2022
b8c7f24
add webhook fakeserver for tests
walleliu1016 May 3, 2022
ffd371d
add request reply
walleliu1016 May 9, 2022
d618a54
add request reply
walleliu1016 May 10, 2022
f40eef1
publish success
walleliu1016 May 12, 2022
9c19cb4
publish success
walleliu1016 May 12, 2022
febbe38
do not reply on async subscription
walleliu1016 May 12, 2022
e53103a
do not reply on async subscription
walleliu1016 May 12, 2022
e716bd3
do not reply on async subscription
walleliu1016 May 12, 2022
360406a
fix test
walleliu1016 May 23, 2022
22fbb2f
add webhook demo
walleliu1016 May 23, 2022
a0e70d1
change log api
walleliu1016 May 23, 2022
3c743e6
update tcp/http module log api
walleliu1016 May 23, 2022
72f72a8
Merge pull request #887 from walleliu1016/go-sdk
qqeasonchen May 24, 2022
3d547bd
update example
walleliu1016 Jun 6, 2022
5b85819
Merge branch 'go-sdk'
walleliu1016 Jun 6, 2022
bd77cc6
update em host in example
walleliu1016 Jun 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions eventmesh-sdk-go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
EventMesh Go SDK
---
support api
1. gRPC
2. HTTP
3. TCP
48 changes: 48 additions & 0 deletions eventmesh-sdk-go/common/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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",
}
22 changes: 22 additions & 0 deletions eventmesh-sdk-go/common/id/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package id

// Interface api to generate uniq id
type Interface interface {
// Next create uniq ID
Next() string
}
79 changes: 79 additions & 0 deletions eventmesh-sdk-go/common/id/id_snake.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package id

import (
"bytes"
"fmt"
"net"
"strconv"
"strings"

"github.com/sony/sonyflake"
)

// flake generate uid by flake
type flake struct {
sf *sonyflake.Sonyflake
}

func NewFlake() Interface {
macAddr := getMacAddr()
st := sonyflake.Settings{
MachineID: func() (uint16, error) {
ma := strings.Split(macAddr, ":")
mid, err := strconv.ParseInt(ma[0]+ma[1], 16, 16)
return uint16(mid), err
},
}
return &flake{
sf: sonyflake.NewSonyflake(st),
}
}

// getMacAddr return the current machine mac address
func getMacAddr() (addr string) {
interfaces, err := net.Interfaces()
if err == nil {
for _, i := range interfaces {
if i.Flags&net.FlagUp != 0 && bytes.Compare(i.HardwareAddr, nil) != 0 {
// Don't use random as we have a real address
addr = i.HardwareAddr.String()
break
}
}
}
return
}

// Nextv generates next id as an uint64
func (f *flake) Nextv() (id uint64, err error) {
var i uint64
if f.sf != nil {
i, err = f.sf.NextID()
if err == nil {
id = i
}
}
return
}

// Next generates next id as a string
func (f *flake) Next() string {
var i uint64
i, _ = f.Nextv()
return fmt.Sprintf("%d", i)
}
34 changes: 34 additions & 0 deletions eventmesh-sdk-go/common/id/id_uuid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package id

import (
"github.com/google/uuid"
"strings"
)

// UUID generate id by uuid
type UUID struct {
}

// NewUUID uuid instance
func NewUUID() Interface {
return &UUID{}
}

func (u *UUID) Next() string {
return strings.ReplaceAll(uuid.New().String(), "-", "")
}
24 changes: 24 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,24 @@
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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,72 @@
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package client

import (
"github.com/apache/incubator-eventmesh/eventmesh-sdk-go/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,38 @@
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package client

import (
"github.com/apache/incubator-eventmesh/eventmesh-sdk-go/common/protocol"
"github.com/apache/incubator-eventmesh/eventmesh-sdk-go/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
}
35 changes: 35 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,35 @@
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

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",
},
}
27 changes: 27 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,27 @@
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package common

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

var DefaultEventMeshRetCode = struct {
SUCCESS EventMeshRetCode
}{
SUCCESS: EventMeshRetCode{RetCode: 0, ErrMsg: "success"},
}
Loading