Documentation ¶
Overview ¶
A fast and lightweight distributed Task Queue using ØMQ.
GOMQ provides an easy, fast, and secure way to send orders on various network schemas to execute tasks efficiently on remote hosts.
GOMQ contains defined task identified by a string. It can bind like a daemon or connect to other daemons (or both). GOMQ uses only encrypted connections using AES. All incoming or outcoming connections are ØMQ connections so a connection must only send (using gomq.PUSH) or receive (using gomq.PULL). A connection can be connected to multiple hosts.
Daemon example:
package main import ( "gomq" "log" "time" ) var _GOMQ *gomq.GOMQ func a(b gomq.Args) { _GOMQ.AddTask() defer _GOMQ.FreeTask() log.Println(">", b.(string), "<") time.Sleep(time.Second) } func Server() { _GOMQ = gomq.NewGOMQ("daemon") _GOMQ.SetMasterKey([]byte("test")) _GOMQ.AddJob("test", a) err := _GOMQ.Loop("tcp://127.0.0.1:6666", gomq.PULL) if err != nil { log.Println(err) } _GOMQ.Close() _GOMQ.Wait() } func main() { Server() }
Client example:
package main import ( "gomq" "log" ) func Client() { h := gomq.NewGOMQ("client") h.SetMasterKey([]byte("test")) h.CreateConnection("todaemon", "tcp://127.0.0.1:6666", gomq.PUSH) err := h.SendJob("todaemon", "test", "HelloWorld!") if err != nil { log.Println("Client:SendJob", err) } h.Close() } func main() { Client() }
Requirements:
Index ¶
- Constants
- type Args
- type GOMQ
- func (self *GOMQ) AddJob(job string, action Pfunc)
- func (self *GOMQ) AddTask()
- func (self *GOMQ) Close()
- func (self *GOMQ) CreateConnection(name, host string, sock_type zmq.SocketType)
- func (self *GOMQ) FreeTask()
- func (self *GOMQ) Loop(host string, sock_type zmq.SocketType) error
- func (self *GOMQ) SendJob(connection_name, job string, params Args) error
- func (self *GOMQ) SetMasterKey(key []byte)
- func (self *GOMQ) Wait()
- type Pfunc
Constants ¶
const ( // Export ØMQ socket type. PULL = zmq.PULL PUSH = zmq.PUSH )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GOMQ ¶
type GOMQ struct {
// contains filtered or unexported fields
}
GOMQ structure.
func (*GOMQ) AddTask ¶
func (self *GOMQ) AddTask()
Registers a task. Wait() wait all registered tasks.
func (*GOMQ) CreateConnection ¶
func (self *GOMQ) CreateConnection(name, host string, sock_type zmq.SocketType)
Creates a new connection with the host and identified by the given name.
func (*GOMQ) Loop ¶
func (self *GOMQ) Loop(host string, sock_type zmq.SocketType) error
This loop will listen to all incoming connections on the given host. It will receive incoming jobs, and launch them.
func (*GOMQ) SendJob ¶
Sends a job on the connection identified by connection_name to execute the task identified by the string job which will take params as argument.
func (*GOMQ) SetMasterKey ¶
Defines the master key using for encryption.