Micro-service framework in Go

Overview

Kite Micro-Service Framework

Kite is a framework for developing micro-services in Go.

GoDoc Build Status

Kite

Kite is both the name of the framework and the micro-service that is written by using this framework. Basically, Kite is a RPC server as well as a client. It connects to other kites and peers to communicate with each other. They can discover other kites using a service called Kontrol, and communicate with them bidirectionaly. The communication protocol uses a WebSocket (or XHR) as transport in order to allow web applications to connect directly to kites.

Kites can talk with each other by sending dnode messages over a socket session. If the client knows the URL of the server kite it can connect to it directly. If the URL is not known, client can ask for it from Kontrol (Service Discovery).

For more info checkout the blog post at GopherAcademy which explains Kite in more detail: http://blog.gopheracademy.com/birthday-bash-2014/kite-microservice-library/

Install and Usage

Install the package with:

go get github.com/koding/kite

Import it with:

import "github.com/koding/kite"

and use kite as the package name inside the code.

What is Kontrol?

Kontrol is the service registry and authentication service used by Kites. It is itself a kite too.

When a kite starts to run, it can registers itself to Kontrol with the Register() method if wished. That enables others to find it by querying Kontrol. There is also a Proxy Kite for giving public URLs to registered kites.

Query has 7 fields:

/<username>/<environment>/<name>/<version>/<region>/<hostname>/<id>
  • You must at least give the username.
  • The order of the fields is from general to specific.
  • Query cannot contains empty parts between fields.

Installing Kontrol

Install Kontrol:

go get github.com/koding/kite/kontrol/kontrol

Generate keys for the Kite key:

openssl genrsa -out key.pem 2048
openssl rsa -in key.pem -pubout > key_pub.pem

Set environment variables:

KONTROL_PORT=6000
KONTROL_USERNAME="kontrol"
KONTROL_STORAGE="etcd"
KONTROL_KONTROLURL="http://127.0.0.1:6000/kite"
KONTROL_PUBLICKEYFILE="certs/key_pub.pem"
KONTROL_PRIVATEKEYFILE="certs/key.pem"

Generate initial Kite key:

./bin/kontrol -initial

How can I use kites from a browser?

A browser can also be a Kite. It has it's own methods ("log" for logging a message to the console, "alert" for displaying alert to the user, etc.). A connected kite can call methods defined on the webpage.

See kite.js library for more information.

How can I write a new kite?

  • Import kite package.
  • Create a new instance with kite.New().
  • Add your method handlers with k.HandleFunc() or k.Handle().
  • Call k.Run()

Below you can find an example, a math kite which calculates the square of a received number:

package main

import "github.com/koding/kite"

func main() {
	// Create a kite
	k := kite.New("math", "1.0.0")

	// Add our handler method with the name "square"
	k.HandleFunc("square", func(r *kite.Request) (interface{}, error) {
		a := r.Args.One().MustFloat64()
		result := a * a    // calculate the square
		return result, nil // send back the result
	}).DisableAuthentication()

	// Attach to a server with port 3636 and run it
	k.Config.Port = 3636
	k.Run()
}

Now let's connect to it and send a 4 as an argument.

package main

import (
	"fmt"

	"github.com/koding/kite"
)

func main() {
	k := kite.New("exp2", "1.0.0")

	// Connect to our math kite
	mathWorker := k.NewClient("http://localhost:3636/kite")
	mathWorker.Dial()

	response, _ := mathWorker.Tell("square", 4) // call "square" method with argument 4
	fmt.Println("result:", response.MustFloat64())
}

Check out the examples folder for more examples.

Issues
  • kontrol: ERROR 100: Key not found

    kontrol: ERROR 100: Key not found

    I got a problem: [kontrol] CRITICAL Could not create KitesPrefix "/kites": client: etcd cluster is unavailable or misconfigured; error #0: unsupported protocol scheme ""

    etcd version: 3.2.9 I started etcd with default config kontrol -initial kontrol -ip=127.0.0.1 -port=6000

    opened by xuanjiang1985 10
  • How to Let Dockerized Kites Register to Kontrol

    How to Let Dockerized Kites Register to Kontrol

    I've 3 kites, each dockerizied with its own container. The container running kontrol is fine as the first time the container is started, command kontrol -inital is executed and file kite.key created in folder ~/.kite. However, the containers running my own kites fail because file ~/.kite/kite.key doesn't exist. Does this mean I should run kontrol -inital in each container? How should I use kitectl to register my kites to kontrol, which is running on a different container?

    I've read the documentation but it is not very clear to me (kitectl is not explained very extensively and I was unable to find at least a working example). I've tried this...

    ./kitectl register
    Username: gonzo
    

    but it doesn't work:

    Starting new session failed. Want: 200 Got: 404
    

    Any help would be really appreciated. Many thanks :-)

    opened by giuseppegreco 7
  • Server and Client do not communicate

    Server and Client do not communicate

    Tried your demo example but client blocks waiting for the server to send back an answer. Communication between client and server is in place but sounds like the server is not returning the result (square) to the client and the client is hanging. (go 1.6)

    opened by advancedlogic 7
  • kontrol: expose handlers to let users customize methods

    kontrol: expose handlers to let users customize methods

    This is needed so the certain methods can be altered/changed in a custom Kontrol implementation. Such as disabling authenticating or adding throttling.

    opened by fatih 7
  • kontrol: re-add when update fails

    kontrol: re-add when update fails

    when the ttl expires, update will no longer work due to etcd returning a key not found error. try to add the kite again, which gets things working again. without this, kite keeps retrying and failing forever, and the service needs to be restarted for it to work.

    opened by mischief 6
  • fix building examples

    fix building examples

    Hey,

    Running go build ./... fails with:

    $ go build ./...
    go build github.com/koding/kite/test: no buildable Go source files in /Users/rjeczalik/src/github.com/koding/kite/test
    # github.com/koding/kite/examples/exp2-watch
    examples/exp2-watch/exp2-watch.go:23: undefined: kite.Event
    examples/exp2-watch/exp2-watch.go:28: k.WatchKites undefined (type *kite.Kite has no field or method WatchKites)
    # github.com/koding/kite/examples/math
    examples/math/math.go:27: r.Response undefined (type *kite.Request has no field or method Response)
    

    This CL tries to fix that problem. I took opportunity and extended the math example to be a bit more interactive.

    opened by rjeczalik 6
  • Question: production examples

    Question: production examples

    Hi! I'm evaluating Kite for future projects and I thought it would really help to have a list of production projects that are using Kite. Is it available anywhere? Cheers!

    opened by tanis2000 6
  • Rename kite binary to kitectl and restructure the kite/cmd directory.

    Rename kite binary to kitectl and restructure the kite/cmd directory.

    Lets be consistent against our -and with the rest of the world- tools and use kitectl instead of kite.

    Kite package stays as is. Control applications name will be kitectl (like kloudctl and possible future fooctl's). github.com/koding/kite/cmd package is also restructed for better readability. All subcommands resides in kitectl/command directory now.

    opened by igungor 6
  • kontrol: Added NewWithoutHandlers func

    kontrol: Added NewWithoutHandlers func

    To allow a library user to provide their own handlers, the NewWithoutHandlers function has been introduced. This creates a kontrol instance with the normal config, but without any default kontrol handlers. The user can then provide their own handlers, or the existing kontrol handlers, as they see fit.

    cc @cihangir @fatih

    opened by leeola 5
  • kite: implement Pre and Post middleware chaining

    kite: implement Pre and Post middleware chaining

    This PR enables us to chain global and method based handlers with existing methods. There are two main kite methods, which are globablly invoked. That means any handler added here is going to be executed whatever a request comes regardless the method name. The api is in the form of:

    // PreHandle registers an handler which is executed before a kite.Handler
    // method is executed. Calling PreHandle multiple times registers multiple
    // handlers. The execution order is FIFO.
    func (k *Kite) PreHandle(handler Handler)  {}
    func (k *Kite) PreHandleFunc(handler HandlerFunc) { }
    
    // PostHandle registers an handler which is executed after a kite.Handler
    // method is executed. Calling PostHandler multiple times registers multiple
    // handlers. The execution order is FIFO.
    func (k *Kite) PostHandle(handler Handler) {}
    func (k *Kite) PostHandleFunc(handler HandlerFunc) { }
    

    This is useful for application based throttling, logging or any other specific task that needs to be done for all methods.

    One has also the ability to add handlers for individual methods:

    // PreHandler adds a new kite handler which is executed before the method.
    func (m *Method) PreHandle(handler Handler) *Method { }
    func (m *Method) PreHandleFunc(handler HandlerFunc) *Method { }
    
    
    // PostHandle adds a new kite handler which is executed after the method.
    func (m *Method) PostHandle(handler Handler) *Method { }
    func (m *Method) PostHandleFunc(handler HandlerFunc) *Method { }
    

    And example usage for a method called foo is:

    k.HandleFunc("foo", Square).PreHandleFunc(func(r *kite.Request) (interface{}, error) {
        fmt.Println("This pre handler is only valid for this individual method")
        return nil, nil
    })
    
    opened by fatih 5
  • etcd support broken

    etcd support broken

    So I messed up etcd support the other day with PR #205. The last time etcd support worked was before my PR with git SHA cc90c7b091275e606ad0ca7102a23fb2072f3f5e of coreos/go-etcd (the deprecated lib). I'm working to fix but this is just so all are aware.

    opened by pdxjohnny 4
  • Kontrol installation issue

    Kontrol installation issue

    hi I try to install kontrol using the command

    go get github.com/koding/kite/kontrol/kontrol
    

    and i get

    	module declares its path as: github.com/Masterminds/squirrel
    	        but was required as: github.com/lann/squirrel
    
    opened by sagadsalem 2
  • Install Issue

    Install Issue

    Go version: Go1.14 command: go get github.com/koding/kite OS: macOS Catalina v.10.15.5 error:

    pkg/mod/github.com/koding/[email protected]/kite.go:177:21: not enough arguments in call to uuid.Must
    	have (uuid.UUID)
    	want (uuid.UUID, error)
    
    opened by Saxy 6
  • why undefined sockjs.SessionState?

    why undefined sockjs.SessionState?

    In my environment, the demo can not be compiled. Wrong is:

    github.com/koding/kite/sockjsclient ../../../go/pkg/mod/github.com/koding/[email protected]/sockjsclient/sockjsclient.go:39:8: undefined: sockjs.SessionState

    The import statement of package sockjs is:

    import "github.com/igm/sockjs-go/sockjs"

    In go.mod, the version of this package is:

    github.com/igm/sockjs-go v2.0.1+incompatible

    I've tried to change the version of sockjs-go package, but it didn't work, it is really confused.

    opened by sowhat001 1
  • getting Error when running exp2-watch.go from examples folder

    getting Error when running exp2-watch.go from examples folder

    I'm getting this error when running exp2-watch.go from examples folder

    # github.com/Shashwatsh/kite_example
    ./exp2-watch.go:25:21: undefined: kite.Event
    ./exp2-watch.go:30:13: k.WatchKites undefined (type *kite.Kite has no field or method WatchKites)
    

    full code

    
    import (
            "fmt"
            "log"
            "math/rand"
            "time"
    
            "github.com/koding/kite"
            "github.com/koding/kite/config"
            "github.com/koding/kite/protocol"
    )
    
    func init() {
            rand.Seed(time.Now().UnixNano())
    }
    
    func main() {
            // Create a kite
            k := kite.New("exp2", "1.0.0")
            k.Config = config.MustGet()
    
            //k.Register(&url.URL{Scheme: "http", Host: "localhost:3636/kite"})
    
            onEvent := func(e *kite.Event, err *kite.Error) {
                    fmt.Printf("e %+v\n", e)
                    fmt.Printf("err %+v\n", err)
            }
    
            _, err := k.WatchKites(protocol.KontrolQuery{
                    Username:    k.Config.Username,
                    Environment: k.Config.Environment,
                    Name:        "math",
                    // ID: "48bb002b-79f6-4a4e-6bba-a40567a08b6c",
            }, onEvent)
            if err != nil {
                    log.Fatalln(err)
            }
    
            // This is a bad example, it's just for testing the watch functionality :)
            fmt.Println("listening to events")
    
            select {}
    }
    
    opened by Shashwatsh 0
  • Is it necessary to close the client in the sample code?

    Is it necessary to close the client in the sample code?

    Is it necessary to close the client in the sample code?

    package main
    
    import (
    	"fmt"
    
    	"github.com/koding/kite"
    )
    
    func main() {
    	k := kite.New("exp2", "1.0.0")
    
    	// Connect to our math kite
    	mathWorker := k.NewClient("http://localhost:3636/kite")
    	mathWorker.Dial()
           **defer  mathWorker.Close()**
    
    	response, _ := mathWorker.Tell("square", 4) // call "square" method with argument 4
    	fmt.Println("result:", response.MustFloat64())
    }
    
    opened by aapelismith 0
Micro-service framework in Go

Kite Micro-Service Framework Kite is a framework for developing micro-services in Go. Kite is both the name of the framework and the micro-service tha

Koding, Inc. 3.1k May 15, 2022
NewSQL distributed storage database based on micro service framework

QLite 是基于微服务的 NewSQL 型数据库系统,与传统的一体化数据库不同,该系统将本该内置的多种数据结构(STL)拆分成多个服务模块,每个模块都是独立的一个节点,每个节点都与其主网关进行连接,从而形成分布式存储结构。

null 30 Mar 25, 2022
🦄🌈 YoyoGo is a simple, light and fast , dependency injection based micro-service framework written in Go.

???? YoyoGo is a simple, light and fast , dependency injection based micro-service framework written in Go. Support Nacos ,Consoul ,Etcd ,Eureka ,kubernetes.

YoyoFx 533 May 1, 2022
Another excellent micro service framework

xservice [WIP] Another excellent micro service framework Features RESTful API (base on echo/v4) gRPC & gRPC gateway service & Swagger document generat

新片场 8 Apr 27, 2022
Automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio.

Mesh RPC MeshRPC provides automatic Service Mesh and RPC generation for Go micro services, it's a humble alternative to gRPC with Istio. In a nutshell

AstraNet Toolkit 68 Apr 19, 2022
White Matrix Micro Service Generate CLI Tool

micro-service-gen-tool White Matrix Micro Service Generate CLI Tool usage templa

null 5 Jan 5, 2022
Micro service frame

MicroFrame MicroFrame是基于go-micro结合go的plugin(需要go1.8或以上)开发的一个微服务框架。 go-micro本身已经做了非常好的抽象和插件化。MicroFrame没有直接采用go-micro,而是在它的基础上重新开发有下面一些原因。 对纯粹的业务开发屏蔽掉掉

never lee 11 Nov 9, 2021
Zdpgo micro service inventory - Golang开发的库存微服务

zdpgo_micro_service_goods Golang开发的商品微服务service层 生成proto 安装插件 go install google.

张大鹏 0 Feb 3, 2022
Go Micro is a framework for distributed systems development

Go Micro Go Micro is a framework for distributed systems development. Overview Go Micro provides the core requirements for distributed systems develop

Asim Aslam 18.2k May 15, 2022
a microservice framework for rapid development of micro services in Go with rich eco-system

中文版README Go-Chassis is a microservice framework for rapid development of microservices in Go. it focus on helping developer to deliver cloud native a

null 2.5k May 9, 2022
Fastglue is an opinionated, bare bones wrapper that glues together fasthttp and fasthttprouter to act as a micro HTTP framework.

fastglue Overview fastglue is an opinionated, bare bones wrapper that glues together fasthttp and fasthttprouter to act as a micro HTTP framework. It

Zerodha Technology 70 Apr 7, 2022
😈 Simple micro-front-end framework.

Development and Maintenance Status RancherOS 1.x is no longer being actively maintained. There are two significant reasons behind this product decisio

Matt D 0 Jan 5, 2022
A code generator that turns plain old Go services into RPC-enabled (micro)services with robust HTTP APIs.

Frodo is a code generator and runtime library that helps you write RPC-enabled (micro) services and APIs.

Monadic 17 Apr 21, 2022
Micro is a platform for cloud native development

Micro Overview Micro addresses the key requirements for building services in the cloud. It leverages the microservices architecture pattern and provid

Micro 11.1k May 15, 2022
goTempM is a full stack Golang microservices sample application built on top of the Micro platform.

goTempM is a full stack Golang microservices sample application built on top of the Micro platform.

null 25 Apr 28, 2022
微服务架构-micro-基于go-zero zrpc etcd 单独集成orm-gorm 日志-uber/zap

micro目录结构 pkg ├── api 业务接口逻辑层 所有的业务逻辑存放目录。 │ ├── model 数据模型 数据管理层,仅用于操作管理数据,如数据库操作 ├── assets

jiwei 8 Apr 26, 2022
A Micro-UTP, plug-able sanity checker for any on-prem JFrog platform instance

hello-frog About this plugin This plugin is a template and a functioning example for a basic JFrog CLI plugin. This README shows the expected structur

rdar 0 Dec 7, 2021
Go micro frame cli tool

go-micro-frame cli tool install git clone [email protected]:jettjia/go-micro-frame-cli.git cd go-micro-frame-cli go build -ldflags "-w -s" -o go-micro-f

jettjia 5 Apr 13, 2022
An open network for Micro services.

Micro Network The micro network is an open network for Micro services. Note: The network is still in early development. This document serves as a star

Micro 10 May 10, 2022