utils

package
v0.0.0-...-4cabc89 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2015 License: MIT Imports: 10 Imported by: 3

Documentation

Overview

Package utils provides zmq connection pool

Package utils provides ...

这里提供Mutex锁, 如果需要多线程访问zmq的socket,使用这个

Index

Constants

View Source
const (
	BLOCK_DURATION = 3 * time.Second //默认阻塞时间
)

Variables

This section is empty.

Functions

func Dump

func Dump(soc *zmq.Socket)

func GetLocalIdentity

func GetLocalIdentity(namespace string) (string, error)

func ReqNewer

func ReqNewer(endpoint string) func() (*zmq.Socket, error)

{{{ func ReqNewer(endpoint string) func() (*zmq.Socket, error) * 为了连接池准备

func RequestAndReply

func RequestAndReply(soc *zmq.Socket, timeout time.Duration, msg ...interface{}) (reply []string, err error)

{{{ func RequestAndReply(soc *zmq.Socket, msg interface{}) (reply []string, err error) { * 支持超时时间,但要注意如果一个socket失败之后,因为req严格同步,连接池模式下这个socket最好销毁

func Unwrap

func Unwrap(msg []string) (head string, tail []string)

{{{ func Unwrap(msg []string) (head string, tail []string) * Pops frame off front of message and returns it as 'head' * If next frame is empty, pops that empty frame. * Return remaining frames of message as 'tail'

Types

type MQ

type MQ struct {
	Queue chan []string
	// contains filtered or unexported fields
}

type MQPool

type MQPool struct {
	//Pool map[string]*msgqueue
	Pool map[string]*MQ
	// contains filtered or unexported fields
}

func NewMQPool

func NewMQPool() *MQPool

{{{ func NewMQPool() { *

func (*MQPool) Destroy

func (m *MQPool) Destroy()

{{{ func (m *MQPool) Destroy() { * 销毁pool

func (*MQPool) Get

func (m *MQPool) Get(key string) (mq *MQ, err error)

{{{ func (m *MQPool) Get(key string) (mq *MQ, err error) { * 获取相关key的队列

func (*MQPool) Pop

func (m *MQPool) Pop(k string, bt time.Duration) (v []string, err error)

{{{ func (m *MQPool) Pop(k string,bt time.Duration) (v string, err error) * 出栈

func (*MQPool) Push

func (m *MQPool) Push(k string, v []string) error

{{{ func (m *MQPool) Push(k string, v []string) error { * 入栈

func (*MQPool) Reach

func (m *MQPool) Reach(key string) (mq *MQ, err error)

{{{ func (m *MQPool) Reach(key string) (mq *MQ, err error) { * 获取相关key的队列(不新建)

type Pool

type Pool struct {

	// 获取新连接的方法
	New func() (*zmq.Socket, error)

	Max int

	Wait bool //当连接池满的时候是否等待

	Life time.Duration
	// contains filtered or unexported fields
}

func NewPool

func NewPool(newFn func() (*zmq.Socket, error), ext ...interface{}) *Pool
{{{ func NewPool(newFn func() (*zmq.Socket, error), ext ...interface{}) *Pool
* NewPool creates a new pool. This function is deprecated. Applications should
* initialize the Pool fields directly as shown in example.

func NewPool(newFn func() (*zmq.Socket, error), max int, life time.Duration) *Pool {

func (*Pool) Close

func (p *Pool) Close()

{{{ func (p *Pool) Close() *

func (*Pool) Debug

func (p *Pool) Debug(format string, v ...interface{})

{{{ func (p *Pool) Debug(format string, v ...interface{}) *

func (*Pool) Get

func (p *Pool) Get() (*PooledSocket, error)

{{{ func (p *Pool) Get() *Socket *

type PoolLogger

type PoolLogger interface {
	Printf(format string, v ...interface{})
}

type PooledSocket

type PooledSocket struct {
	Soc *zmq.Socket
	// contains filtered or unexported fields
}

func (*PooledSocket) Close

func (ps *PooledSocket) Close()

{{{ func (ps *PooledSocket) Close() *

func (*PooledSocket) Do

func (ps *PooledSocket) Do(timeout time.Duration, msg ...interface{}) (reply []string, err error)

{{{ func (ps *PooledSocket) Do(timeout time.Duration, msg ...interface{}) (reply []string, err error) *

type Socket

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

func NewSocket

func NewSocket(zt zmq.Type, hwm int) *Socket

{{{ func NewSocket() *Socket *

func (*Socket) Bind

func (s *Socket) Bind(endpoint string) error

{{{ func (s *Socket) Bind(endpoint string) error *

func (*Socket) Close

func (s *Socket) Close() error

{{{ func (s *Socket) Close() error *

func (*Socket) Connect

func (s *Socket) Connect(endpoint string) error

{{{ func (s *Socket) Connect(endpoint string) error *

func (*Socket) RecvMessage

func (s *Socket) RecvMessage(flags int) (msg []string, err error)
 {{{ func (s *Socket) RecvMessage(flags int) (msg []string, err error) {
	return s.soc.RecvMessage(zmq4.Flag(flags))
 *

func (*Socket) SendMessage

func (s *Socket) SendMessage(parts ...interface{}) (total int, err error)

{{{ func (s *Socket) SendMessage(parts ...interface{}) (total int, err error) { *

Jump to

Keyboard shortcuts

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