Skip to content

Commit

Permalink
integrate new go sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
kubemq committed Jul 17, 2019
1 parent 87d0880 commit b7e172f
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 5 deletions.
20 changes: 16 additions & 4 deletions cmd/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"errors"
"fmt"
"github.com/kubemq-io/kubemq-go"
"log"
"time"

Expand Down Expand Up @@ -86,12 +87,14 @@ func runSend(args []string, kind string) {

switch kind {
case "events":
err = client.SendEvent(ctx, args[0], msg)
err:=client.E().SetChannel(args[0]).SetBody(msg.Marshal()).SetId(msg.Id).Send(ctx)

if err != nil {
log.Printf("error sending event: %s", err.Error())
}

case "events_store":
err:=client.ES().SetChannel(args[0]).SetBody(msg.Marshal()).SetId(msg.Id).Send(ctx)
err = client.SendEventStore(ctx, args[0], msg)
if err != nil {
log.Printf("error sending event_store: %s", err.Error())
Expand Down Expand Up @@ -125,18 +128,27 @@ func init() {

}

func getSendClient(ctx context.Context) (transport.Transport, error) {
func getSendClient(ctx context.Context) (*kubemq.Client, error) {
switch sendTransport {
case "grpc":
for _, conn := range cfg.Connections {
if conn.Kind == option.ConnectionTypeGrpc {
return grpc.New(ctx, conn)
client,err:=kubemq.NewClient(ctx,
kubemq.WithAddress(conn.Host,conn.Port),
kubemq.WithClientId(uuid.New().String()),
kubemq.WithTransportType(kubemq.TransportTypeGRPC))

return client,err
}
}
case "rest":
for _, conn := range cfg.Connections {
if conn.Kind == option.ConnectionTypeRest {
return rest.New(ctx, conn)
client,err:=kubemq.NewClient(ctx,
kubemq.WithUri(conn.Uri()),
kubemq.WithClientId(uuid.New().String()),
kubemq.WithTransportType(kubemq.TransportTypeRest))
return client,err
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/google/uuid v1.1.1
github.com/gorilla/websocket v1.4.0
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kubemq-io/kubemq-go v1.1.2
github.com/kubemq-io/kubemq-go v1.2.0
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.3.2
Expand Down
Loading

0 comments on commit b7e172f

Please sign in to comment.