gomicro

package module
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: MIT Imports: 14 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

    1. 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
    1. install protoc-gen-go
$ go get -u github.com/golang/protobuf/protoc-gen-go
    1. install protoc-gen-micro v2
$ go get -u github.com/micro/protoc-gen-micro/v2

Documentation

Index

Constants

View Source
const (
	DISCOVERY_DEFAULT_INTERVAL = 3
	DISCOVERY_DEFAULT_TTL      = 10
	DEFAULT_RPC_TIMEOUT        = 30
)

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, timeout int) context.Context

NewContext md -> metadata of RPC call, set to nil if have no any meta-data timeout -> timeout seconds of RPC call, if <=0 will set it to DEFAULT_RPC_TIMEOUT

Types

type Discovery

type Discovery 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]
	Endpoints   []string // register endpoints of etcd/consul/zookeeper eg. ["192.168.0.10:2379","192.168.0.11:2379"]
}

type GoRPC

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

func NewGoRPC

func NewGoRPC(registryType RegistryType, maxSize ...int) (g *GoRPC)

sizes: max send or receive msg size in byte

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) (s *GoRPCServer)

NewServer new a go-micro server

type GoRPCClient

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

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 (*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

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

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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