hprose_go_nats

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2018 License: Apache-2.0 Imports: 16 Imported by: 1

README

Hprose

Hprose for nats

简体中文

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

Documentation

Index

Constants

View Source
const DEFAULT_DELAY = 45
View Source
const DEFAULT_QUEUE = 64
View Source
const DEFAULT_TIMEOUT = 15

Variables

View Source
var ErrClosed = errors.New("connect is closed")
View Source
var ErrIllegalUrl = errors.New("illegal url")
View Source
var ErrNotConnect = errors.New("not connect")
View Source
var ErrTimeout = NewTimeout("request timeout")

Functions

func ClientCert

func ClientCert(certFile, keyFile string) func(*NatsOption)

func Delay

func Delay(t time.Duration) func(*NatsOption)

func Group

func Group(group string) func(*NatsOption)

func Id

func Id(id string) func(*NatsOption)

func NewClient

func NewClient(opt *NatsOption) rpc.Client

func NewServer

func NewServer(opt *NatsOption) rpc.Server

func NewTimeout

func NewTimeout(s string) net.Error

func NewTimeoutFunc

func NewTimeoutFunc(f func() string) net.Error

func Options

func Options(o ...nats.Option) func(*NatsOption)

func Queue

func Queue(num int) func(*NatsOption)

func RootCAs

func RootCAs(ca ...string) func(*NatsOption)

func Secure

func Secure(tls ...*tls.Config) func(*NatsOption)

func Timeout

func Timeout(t time.Duration) func(*NatsOption)

func Topic

func Topic(topic string) func(*NatsOption)

func Uri

func Uri(uri ...string) func(*NatsOption)

Types

type NatsClient

type NatsClient struct {
	rpc.BaseClient
	// contains filtered or unexported fields
}

func (*NatsClient) Close

func (nc *NatsClient) Close()

func (*NatsClient) SendAndReceive

func (nc *NatsClient) SendAndReceive(data []byte, ctx *rpc.ClientContext) ([]byte, error)

type NatsOption

type NatsOption struct {
	// contains filtered or unexported fields
}

func NewOption

func NewOption(option ...func(*NatsOption)) *NatsOption

type NatsServer

type NatsServer struct {
	rpc.BaseService
	// contains filtered or unexported fields
}

func (*NatsServer) Close

func (ns *NatsServer) Close()

func (*NatsServer) Handle

func (ns *NatsServer) Handle() error

func (*NatsServer) Restart

func (ns *NatsServer) Restart()

func (*NatsServer) Start

func (ns *NatsServer) Start() (err error)

func (*NatsServer) Stop

func (ns *NatsServer) Stop()

func (*NatsServer) URI

func (ns *NatsServer) URI() string

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

func NewPool

func NewPool() *Pool

func (*Pool) Get

func (p *Pool) Get(ttl int64) *Request

func (*Pool) Push

func (p *Pool) Push(seq Sequence, data []byte, err error)

func (*Pool) Put

func (p *Pool) Put(req *Request)

func (*Pool) Remove

func (p *Pool) Remove(seq Sequence)

func (*Pool) Reset

func (p *Pool) Reset(err error)

func (*Pool) Wheel

func (p *Pool) Wheel() *timer.TimingWheel

type Request

type Request struct {
	// contains filtered or unexported fields
}

func (*Request) Close

func (r *Request) Close()

func (*Request) Id

func (r *Request) Id() Sequence

func (*Request) Reset

func (r *Request) Reset() *Request

func (*Request) Response

func (r *Request) Response() ([]byte, error)

func (*Request) String

func (r *Request) String() string

type Sequence

type Sequence uint64

func NewSequence

func NewSequence(s string) Sequence

func (Sequence) String

func (s Sequence) String() string

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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