在Go中开发微服务的框架:Kite

jopen 9年前

Kite是一个框架用于在Go中开发微服务。
实际上Kite是一个RPC服务器及客户端。它连接到其他Kite和实现同行互相通信。他们能够使用一种称为KONTROL服务来发现其它Kite,并与他们沟通通信。该通信协议使用WebSocket作为传输,以便允许web应用程序直接连接到Kite。

Kites 可以彼此发送dnode消息通过websocket进行交谈。.如果客户端知道Kites 服务器的URL就可以直接连接到它。如果不知道URL,客户可以从KONTROL询问。

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()  }

现在,让我们连接到它并发送4作为参数。

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())  }

项目主页:http://www.open-open.com/lib/view/home/1416887349022