gomq

package module
v0.0.0-...-5f90c44 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2013 License: BSD-2-Clause Imports: 20 Imported by: 0

README

====
GOMQ
====

GOMQ, a fast and lightweight distributed Task Queue using ØMQ and some
cryptography.

Documentation
=============

    http://godoc.org/github.com/yann2192/gomq

TODO
====
    * Documentation
    * Tests
    * More examples

Example
=======

Daemon
------
::

    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
------
::

    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
============
    * gozmq (https://github.com/alecthomas/gozmq)
    * pbkdf2 (https://code.google.com/p/go.crypto/pbkdf2)

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

View Source
const (
	// Export ØMQ socket type.
	PULL = zmq.PULL
	PUSH = zmq.PUSH
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Args

type Args interface{}

Type to describe the argument of a GOMQ task.

type GOMQ

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

GOMQ structure.

func NewGOMQ

func NewGOMQ(uuid string) *GOMQ

Creates and initializes a new GOMQ instance identified by the given uuid.

func (*GOMQ) AddJob

func (self *GOMQ) AddJob(job string, action Pfunc)

Defines a new job identified by the string job.

func (*GOMQ) AddTask

func (self *GOMQ) AddTask()

Registers a task. Wait() wait all registered tasks.

func (*GOMQ) Close

func (self *GOMQ) Close()

Closes all opens connections.

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

func (self *GOMQ) FreeTask()

Unregisters a task.

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

func (self *GOMQ) SendJob(connection_name, job string, params Args) error

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

func (self *GOMQ) SetMasterKey(key []byte)

Defines the master key using for encryption.

func (*GOMQ) Wait

func (self *GOMQ) Wait()

Waits for all registered tasks.

type Pfunc

type Pfunc func(Args)

Type to describe a GOMQ task.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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