dmicro

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2021 License: Apache-2.0 Imports: 0 Imported by: 0

README

dmicro GitHub release report card github issues github closed issues GoDoc view examples

dmicro简介

dmicro是一个高效、可扩展且简单易用的微服务框架。包含drpc,easyserver等组件。

该项目的诞生离不开erpcGoFrame两个优秀的项目。

其中drpc组件参考erpc项目的架构思想,依赖的基础库是GoFrame

详细文档

中文文档

安装

go get -u -v github.com/osgochina/dmicro

推荐使用 go.mod:

require github.com/osgochina/dmicro latest
  • import
import "github.com/osgochina/dmicro"

限制

golang版本 >= 1.13

rpc服务

如何快速的通过简单的代码创建一个真正的rpc服务。 以下就是示例代码:

package main

import (
	"github.com/osgochina/dmicro/drpc"
	"github.com/osgochina/dmicro/logger"
)

func main() {
	//开启信号监听
	go drpc.GraceSignal()
	// 创建一个rpc服务
	svr := drpc.NewEndpoint(drpc.EndpointConfig{
		CountTime:   true,
		LocalIP:     "127.0.0.1",
		ListenPort:  9091,
		PrintDetail: true,
	})
	//注册处理方法
	svr.RouteCall(new(Math))
	//启动监听
	err := svr.ListenAndServe()
	logger.Warning(err)
}

// Math rpc请求的最终处理器,必须集成drpc.CallCtx
type Math struct {
	drpc.CallCtx
}

func (m *Math) Add(arg *[]int) (int, *drpc.Status) {
	// test meta
	logger.Infof("author: %s", m.PeekMeta("author"))
	// add
	var r int
	for _, a := range *arg {
		r += a
	}
	// response
	return r, nil
}

rpc客户端

服务已经建立完毕,如何通过client链接它呢?


package main

import (
	"github.com/osgochina/dmicro/drpc"
	"github.com/osgochina/dmicro/drpc/message"
	"github.com/osgochina/dmicro/logger"
	"time"
)

func main() {

	cli := drpc.NewEndpoint(drpc.EndpointConfig{PrintDetail: true, RedialTimes: -1, RedialInterval: time.Second})
	defer cli.Close()
	

	sess, stat := cli.Dial("127.0.0.1:9091")
	if !stat.OK() {
		logger.Fatalf("%v", stat)
	}
    var result int
    stat = sess.Call("/math/add",
        []int{1, 2, 3, 4, 5},
        &result,
        message.WithSetMeta("author", "liuzhiming"),
    ).Status()
    if !stat.OK() {
        logger.Fatalf("%v", stat)
    }
    logger.Printf("result: %d", result)
}

通过以上的代码事例,大家基本可以了解drpc框架是怎么使用。

Documentation

Index

Constants

View Source
const Authors = "ClownFish(osgochina@gmail.com)"
View Source
const Version = "v0.1.0"

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
message
Package message 消息对象
Package message 消息对象
plugin/ignorecase
Package ignorecase dynamically ignoring the case of path
Package ignorecase dynamically ignoring the case of path
supervisor

Jump to

Keyboard shortcuts

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