service

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

README

service

  • 该方法是全局创建服务端的方法

  • 实现了

    • 注册发现
    • 链路追踪
    • 服务治理
      • 熔断
      • 重试
      • 降级
      • 限流
  • 使用grpc作为传输协议

  • 异步消息使用框架默认的 http broker 组件

但有其致命问题,存储消息的 inbox 参数,最大存储消息只为64,多出来的消息不处理

故实际上不能作为生产环境使用

······

// HTTP Broker is a point to point async broker
type httpBroker struct {

	······

	// offline message inbox
	mtx   sync.RWMutex
	inbox map[string][][]byte
}

······

func (h *httpBroker) saveMessage(topic string, msg []byte) {
	h.mtx.Lock()
	defer h.mtx.Unlock()

	// get messages
	c := h.inbox[topic]

	// save message
	c = append(c, msg)

	// max length 64
	if len(c) > 64 {
		c = c[:64]
	}

	// save inbox
	h.inbox[topic] = c
}

Documentation

Index

Constants

View Source
const CALL_FUNC_IS_NULL = "create service: The CallFunc cannot be empty~"
View Source
const SERVICE_NAME_IS_NULL = "create service: The ServiceName cannot be empty!"

Variables

View Source
var (
	DEFAULT_RPC_ADDR   = ":8090"
	DEFAULT_HTTP_ADDR  = ":8080"
	DEFAULT_BIND_ROUTE = func(engine *gin.Engine) {
		engine.GET("/", func(c *gin.Context) {
			c.JSON(200, gin.H{"msg": "call sxx-micro http server success"})
		})
	}
)

Functions

func Create

func Create(opts ...Option) error

Types

type Mode added in v1.0.8

type Mode uint8
const (
	RPC Mode = iota
	HTTP
)

type Option

type Option func(opts *Options)

func Address added in v1.0.8

func Address(val string) Option
func Advertise(val string) Option

registry node address

func BindRoute added in v1.0.8

func BindRoute(val func(*gin.Engine)) Option

when server type is http, bind route for server

func CallFunc

func CallFunc(val func(service micro.Service)) Option

func Init

func Init(val []micro.Option) Option

func Name

func Name(val string) Option

func RabbitmqBroker

func RabbitmqBroker(val bool) Option

func ServerType added in v1.0.8

func ServerType(val Mode) Option

func SetOption

func SetOption(k, v interface{}) Option

type Options

type Options struct {
	Context context.Context

	Name string
	// listen rpc addr
	RpcAddr string
	// listen http addr
	HttpAddr string
	// service registered address
	Advertise string

	Init     []micro.Option
	CallFunc func(micro.Service)

	// use rabbitmq as the broker driver
	Rabbitmq bool

	// set server type ,RPC || HTTP
	ServerType Mode
	Server     server.Server
	BindRoute  func(*gin.Engine)
}

Directories

Path Synopsis
http

Jump to

Keyboard shortcuts

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