Skip to content

vlorc/hprose-go-nats

Repository files navigation

Hprose

简体中文

License codebeat badge Go Report Card GoDoc Build Status Coverage Status

Hprose based on NATs message queue

Features

  • timeout
  • lazy load
  • failround
  • load balancing

Installing

go get github.com/vlorc/hprose-go-nats

License

This project is under the apache License. See the LICENSE file for the full license text.

Examples

Client

client := rpc.NewClient("nats://localhost:4222?topic=test&timeout=1")
method := &struct{ Hello func(string) (string, error) }{}
client.UseService(method)
for i := 0; i < 10; i++ {
	log.Print(method.Hello(fmt.Sprintf("baby(%d)",i)))
}

Server

server := rpc.NewServer(rpc.NewOption(rpc.Uri("nats://localhost:4222?topic=test&group=balancer")))
server.AddFunction("hello", func(msg string) string {
	log.Print("hello: ", msg)
	return "hi bitch!"
})
server.Start()