在Go中開發微服務的框架:Kite
Kite是一個框架用于在Go中開發微服務。
實際上Kite是一個RPC服務器及客戶端。它連接到其他Kite和實現同行互相通信。他們能夠使用一種稱為KONTROL服務來發現其它Kite,并與他們溝通通信。該通信協議使用WebSocket作為傳輸,以便允許web應用程序直接連接到Kite。
Kites 可以彼此發送dnode消息通過websocket進行交談。.如果客戶端知道Kites 服務器的URL就可以直接連接到它。如果不知道URL,客戶可以從KONTROL詢問。
package mainimport "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()
}</pre>
現在,讓我們連接到它并發送4作為參數。
package mainimport ( "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())
}</pre>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!