braid

package module
v1.2.27 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2021 License: MIT Imports: 24 Imported by: 0

README

Braid


Go Report Card CI Coverage Status

中文

Intro

Description of Service Node Module RPC Pub-sub

image.png


  • RPC Client/Server - Used for request / response from service to service
  • Pub-sub - Used to publish & subscribe messages from module to module
  • Discover - Automatic service discovery, and broadcast the node's entry, exit, update and other messages
  • Balancer - Client side load balancing which built on service discovery. Provide smooth weighted round-robin balancing by default
  • Elector - Select a unique master node for the same name service
  • Tracer - Distributed tracing system, used to monitor the internal state of the program running in microservices
  • Linkcache - Link cache used to maintain connection information in distributed systems

Modules

Discovery Balancing Elector RPC Pub-sub Tracer LinkCache
discoverconsul balancerrandom electorconsul grpc-client mailbox jaegertracer linkerredis
balancerswrr electork8s grpc-server

Quick start


s := braid.NewService("gate")   // create a new node in the service gate

// register module in node
s.Register(
    braid.Module(braid.LoggerZap),
    braid.Module(braid.PubsubNsq,
        pubsubnsq.WithLookupAddr([]string{mock.NSQLookupdAddr}),
        pubsubnsq.WithNsqdAddr([]string{mock.NsqdAddr}, []string{mock.NsqdHttpAddr}),
    ),
    braid.Module(
        braid.DiscoverConsul,    // discover module
        discoverconsul.WithConsulAddr(consulAddr)
    ),
)

s.Init()
s.Run()

defer s.Close()

Pub-sub Benchmark
  • ScopeProc
$ go test -benchmem -run=^$ -bench ^BenchmarkTestProc -cpu 2,4,8
cpu: 2.2 GHz 4 Cores Intel Core i7
goos: darwin
goarch: amd64
pkg: github.com/pojol/braid-go/modules/mailboxnsq
BenchmarkTestProc-2   4340389   302 ns/op   109 B/op   3 allocs/op
BenchmarkTestProc-4   8527536   151 ns/op   122 B/op   3 allocs/op
BenchmarkTestProc-8   7564869   161 ns/op   118 B/op   3 allocs/op
PASS
  • ScopeCluster
$ go test -benchmem -run=^$ -bench ^BenchmarkClusterBroadcast -cpu 2,4,8
tencent cloud 4 Cores
goos: linux
goarch: amd64
BenchmarkClusterBroadcast-2   70556   17234 ns/op   540 B/op   16 allocs/op
BenchmarkClusterBroadcast-4   71202   18975 ns/op   676 B/op   20 allocs/op
BenchmarkClusterBroadcast-8   62098   19037 ns/op   662 B/op   20 allocs/op

Documentation

Index

Constants

View Source
const (
	// Version of braid-go
	Version = "v1.2.26"
)

Variables

View Source
var (
	ErrTypeConvFailed = errors.New("type conversion failed")

	// 默认提供的模块
	LoggerZap      = zaplogger.Name
	PubsubNsq      = pubsubnsq.Name
	DiscoverConsul = discoverconsul.Name
	ElectorConsul  = electorconsul.Name
	ElectorK8s     = electork8s.Name
	ClientGRPC     = grpcclient.Name
	ServerGRPC     = grpcserver.Name
	TracerJaeger   = jaegertracing.Name
	BalancerSWRR   = balancernormal.Name
	LinkcacheRedis = linkerredis.Name
)

Functions

func Client

func Client() client.IClient

GetClient get client interface

func Module

func Module(name string, opts ...interface{}) module.IBuilder

func Pubsub added in v1.2.25

func Pubsub() pubsub.IPubsub

Mailbox pub-sub

func Server

func Server() server.IServer

func Tracer

func Tracer() tracer.ITracer

Tracer tracing

Types

type Braid

type Braid struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Braid framework instance

func NewService added in v1.2.25

func NewService(name string) (*Braid, error)

func (*Braid) Close

func (b *Braid) Close()

Close 关闭braid

func (*Braid) Init

func (b *Braid) Init()

Init braid init

func (*Braid) Register added in v1.2.25

func (b *Braid) Register(builders ...module.IBuilder) error

func (*Braid) Run

func (b *Braid) Run()

Run 运行braid

Directories

Path Synopsis
3rd
log
internal
balancer
接口文件 balancer 负载均衡
接口文件 balancer 负载均衡
discover
接口文件 discover 服务发现 这个模块会创建 ServiceUpdate Topic,通过这个 Topic 发布集群中相关服务的变更信息
接口文件 discover 服务发现 这个模块会创建 ServiceUpdate Topic,通过这个 Topic 发布集群中相关服务的变更信息
elector
接口文件 elector 选举,主要用于分布式系统中的选举 这个模块会创建 ChangeState Topic,通过这个 Topic 发布当前进程所处于的状态
接口文件 elector 选举,主要用于分布式系统中的选举 这个模块会创建 ChangeState Topic,通过这个 Topic 发布当前进程所处于的状态
linkcache
接口文件 linkcache 链路缓存,主要用于维护携带 token 相关的链路调用信息 1.
接口文件 linkcache 链路缓存,主要用于维护携带 token 相关的链路调用信息 1.
logger
接口文件 logger 日志接口
接口文件 logger 日志接口
pubsub
接口文件 mailbox 邮箱,主要用于包装 Pub-sub 消息模型
接口文件 mailbox 邮箱,主要用于包装 Pub-sub 消息模型
rpc/client
接口文件 client 定义 RPC 服务的客户端接口
接口文件 client 定义 RPC 服务的客户端接口
rpc/server
接口文件 server 定义 RPC 服务的服务端接口
接口文件 server 定义 RPC 服务的服务端接口
tracer
接口文件 tracer 分布式追踪服务
接口文件 tracer 分布式追踪服务
modules
balancernormal
实现文件 brandom 随机负载均衡算法实现 实现文件 balancernormal 负载均衡管理器,主要用于统筹管理 服务:负载均衡算法 实现文件 balancerswrr 平滑加权负载均衡算法实现
实现文件 brandom 随机负载均衡算法实现 实现文件 balancernormal 负载均衡管理器,主要用于统筹管理 服务:负载均衡算法 实现文件 balancerswrr 平滑加权负载均衡算法实现
discoverconsul
实现文件 基于 consul 实现的服务发现
实现文件 基于 consul 实现的服务发现
electorconsul
实现文件 electorconsul 基于 consul 实现的选举
实现文件 electorconsul 基于 consul 实现的选举
electork8s
实现文件 electork8s 基于 k8sclient 实现的选举
实现文件 electork8s 基于 k8sclient 实现的选举
grpcclient
实现文件 基于 grpc 实现的 rpc-client
实现文件 基于 grpc 实现的 rpc-client
grpcserver
实现文件 grpcserver 基于 grpc 实现的 rpc-server
实现文件 grpcserver 基于 grpc 实现的 rpc-server
jaegertracing
实现文件 jaegertracing 基于 jaeger 实现的分布式追踪服务
实现文件 jaegertracing 基于 jaeger 实现的分布式追踪服务
linkerredis
实现文件 linkerredis 基于 redis 实现的链路缓存
实现文件 linkerredis 基于 redis 实现的链路缓存
pubsubnsq
实现文件 基于 nsq 实现的 pubsub
实现文件 基于 nsq 实现的 pubsub
zaplogger
实现文件 zaplogger 基于 zap 实现的logger
实现文件 zaplogger 基于 zap 实现的logger

Jump to

Keyboard shortcuts

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