gomicro

package module
v2.6.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 15 Imported by: 0

README

gomicro

golang grpc+go-micro.v2 wrapper

install protoc and golang plugins binaries

https://github.com/civet148/protoc-plugins

install protoc from source code

  • download proto compiler source code
$ wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.1/protobuf-cpp-3.19.1.tar.gz
$ tar xvfz protobuf-cpp-3.19.0.tar.gz
$ cd protobuf-cpp-3.19.0
$ ./configure && sudo make && sudo make install
  • install protoc-gen-go
$ go get -u github.com/golang/protobuf/protoc-gen-go
  • install protoc-gen-micro v2
$ go get -u github.com/micro/protoc-gen-micro/v2

A&Q

compile problem

  • grpc imports
go: finding module for package google.golang.org/grpc/naming
go: finding module for package google.golang.org/grpc/examples/helloworld/helloworld
go: found google.golang.org/grpc/examples/helloworld/helloworld in google.golang.org/grpc/examples v0.0.0-20230516222055-92e65c890c9a
go: finding module for package google.golang.org/grpc/naming
node-agent/pkg/client imports
        github.com/civet148/gomicro/v2 imports
        github.com/micro/go-micro/v2/registry/etcd imports
        github.com/coreos/etcd/clientv3 tested by
        github.com/coreos/etcd/clientv3.test imports
        github.com/coreos/etcd/integration imports
        github.com/coreos/etcd/proxy/grpcproxy imports
        google.golang.org/grpc/naming: module google.golang.org/grpc@latest found (v1.55.0), but does not contain package google.golang.org/grpc/naming
make: *** [Makefile:10: agent] Error 1

replace in go.mod file

replace google.golang.org/grpc => google.golang.org/grpc v1.26.0
  • go-micro imports
go: github.com/micro/go-micro/v2@v2.9.1 requires
        github.com/micro/cli/v2@v2.1.2: reading https://goproxy.io/github.com/micro/cli/v2/@v/v2.1.2.mod: 404 Not Found
        server response:
        not found: github.com/micro/cli/v2@v2.1.2: invalid version: git ls-remote -q origin in /data1/golang/pkg/mod/cache/vcs/2f5431eb5439e9d79f82a6d853348656f17b78125db9eda81300bc014d0f0a5d: exit status 128:                fatal: could not read Username for 'https://github.com': terminal prompts disabled
        Confirm the import path was entered correctly.
        If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.
make: *** [Makefile:4: gomicro] Error 1

replace in go.mod file

replace github.com/micro/cli/v2 => github.com/civet148/micro-cli/v2 v2.1.2

Documentation

Index

Constants

View Source
const (
	DISCOVERY_DEFAULT_INTERVAL = 3
	DISCOVERY_DEFAULT_TTL      = 10
	DEFAULT_RPC_TIMEOUT        = 30
	LOAD_BALANCE_KEY_WEIGTHT   = "gomicro.LoadBalanceWeight"
)

Variables

View Source
var (
	DefaultMaxMsgSize = 512 * 1024 * 1024 //default allow 512 MiB data transport
)

Functions

func FromContext

func FromContext(ctx context.Context) (md metadata.Metadata)

FromContext get metadata from context

func NewContext

func NewContext(md map[string]string) context.Context

NewContext md -> metadata of RPC call, set to nil if have no any meta-data

func NewContextWithTimeout added in v2.2.0

func NewContextWithTimeout(md map[string]string, timeout int) (context.Context, context.CancelFunc)

NewContextWithTimeout md -> metadata of RPC call, set to nil if have no any meta-data timeout -> timeout seconds of RPC call

Types

type GoRPC

type GoRPC struct {
	// contains filtered or unexported fields
}

func (*GoRPC) NewClient

func (g *GoRPC) NewClient(endPoints ...string) (c *GoRPCClient)

NewClient new a go-micro client

func (*GoRPC) NewServer

func (g *GoRPC) NewServer(discovery *discovery, metadata map[string]string) (s *GoRPCServer)

NewServer new a go-micro server with metadata

type GoRPCClient

type GoRPCClient struct {
	// contains filtered or unexported fields
}

func NewClient added in v2.2.0

func NewClient(strRegistry string) (c *GoRPCClient)

func (*GoRPCClient) Call

func (c *GoRPCClient) Call(ctx context.Context, req client.Request, rsp interface{}, opts ...client.CallOption) error

func (*GoRPCClient) Init

func (c *GoRPCClient) Init(opts ...client.Option) error

func (*GoRPCClient) NewMessage

func (c *GoRPCClient) NewMessage(topic string, msg interface{}, opts ...client.MessageOption) client.Message

func (*GoRPCClient) NewRequest

func (c *GoRPCClient) NewRequest(service, endpoint string, req interface{}, reqOpts ...client.RequestOption) client.Request

func (*GoRPCClient) Options

func (c *GoRPCClient) Options() client.Options

func (*GoRPCClient) Publish

func (c *GoRPCClient) Publish(ctx context.Context, msg client.Message, opts ...client.PublishOption) error

func (*GoRPCClient) Stream

func (c *GoRPCClient) Stream(ctx context.Context, req client.Request, opts ...client.CallOption) (client.Stream, error)

func (*GoRPCClient) String

func (c *GoRPCClient) String() string

type GoRPCServer

type GoRPCServer struct {
	// contains filtered or unexported fields
}

func NewServer added in v2.2.0

func NewServer(strRegistry string, option *ServerOption) (s *GoRPCServer)

func (*GoRPCServer) Close

func (s *GoRPCServer) Close() error

func (*GoRPCServer) Handle

func (s *GoRPCServer) Handle(h server.Handler) error

Register a handler

func (*GoRPCServer) Init

func (s *GoRPCServer) Init(opts ...server.Option) error

Initialise options

func (*GoRPCServer) NewHandler

func (s *GoRPCServer) NewHandler(h interface{}, opts ...server.HandlerOption) server.Handler

Create a new handler

func (*GoRPCServer) NewSubscriber

func (s *GoRPCServer) NewSubscriber(topic string, sb interface{}, opts ...server.SubscriberOption) server.Subscriber

Create a new subscriber

func (*GoRPCServer) Options

func (s *GoRPCServer) Options() server.Options

Retrieve the options

func (*GoRPCServer) Start

func (s *GoRPCServer) Start() error

Start the server

func (*GoRPCServer) Stop

func (s *GoRPCServer) Stop() error

Stop the server

func (*GoRPCServer) String

func (s *GoRPCServer) String() string

Server implementation

func (*GoRPCServer) Subscribe

func (s *GoRPCServer) Subscribe(subscriber server.Subscriber) error

Register a subscriber

func (*GoRPCServer) Weight added in v2.6.1

func (s *GoRPCServer) Weight() int

Server weight of load balance

type RegistryType

type RegistryType int
const (
	RegistryType_MDNS RegistryType = 0 // multicast DNS
	RegistryType_ETCD RegistryType = 1 // etcd

)

func ParseRegistry added in v2.1.0

func ParseRegistry(strRegistry string) (typ RegistryType, endpoints []string)

"etcd://192.168.1.108:2379,192.168.1.109:2379" "consul://192.168.1.108:8500,192.168.1.109:8500" "zk://192.168.1.108:2181, 192.168.1.109:2181"

func (RegistryType) String

func (t RegistryType) String() string

type ServerOption added in v2.2.0

type ServerOption struct {
	ServiceName string            // register service name [required]
	RpcAddr     string            // register server RPC address [required]
	Interval    int               // register interval default 3 seconds [optional]
	TTL         int               // register TTL default 10 seconds [optional]
	Weight      int               // server weight of load balance [optional]
	Metadata    map[string]string // register node metadata [optional]
}

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL