majordomo

package module
v0.0.0-...-7da2c5e Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2018 License: MIT Imports: 9 Imported by: 0

README

majordomo-go

Majordomo Project for Go

Majordomo pattern: http://zguide.zeromq.org/page:all#Service-Oriented-Reliable-Queuing-Majordomo-Pattern

This project is copy of "https://github.com/pebbe/zmq4/blob/master/examples/mdbroker.go", only to support []byte type messages.

Examples

Start Broker
package main

import (
  "fmt"
  md "github.com/iamdobi/majordomo-go"
)

func main() {
  fmt.Println("vim-go")

  md.StartBroker(5555, true)
}

Start Worker
package main

import (
  "github.com/iamdobi/majordomo-go/mdapi"
  "log"
)

func main() {
  verbose := true
  session, _ := mdapi.NewMdwrk("tcp://localhost:5555", "echo", verbose)

  var err error
  var request, reply [][]byte
  for {
    request, err = session.Recv(reply)
    if err != nil {
      break //  Worker was interrupted
    }
    reply = request //  Echo is complex... :-)
    log.Printf("[worker] reply=%v\n", reply)
  }
  log.Println(err)
}
Start Client
package main

import (
  "github.com/iamdobi/majordomo-go/mdapi"
  "log"
)

func main() {
  verbose := true
  session, _ := mdapi.NewMdcli("tcp://localhost:5555", verbose)

  count := 0
  for ; count < 10; count++ {
    reply, err := session.Send("echo", []byte("Hello world"))
    if err != nil {
      log.Println(err)
      break //  Interrupt or failure
    } else {
      log.Printf("[client] reply=%v\n", string(reply[0]))
    }
  }
  log.Printf("%d requests/replies processed\n", count)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broker

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

Broker The broker class defines a single broker instance:

func NewBroker

func NewBroker(verbose bool, setters ...Option) (broker *Broker, err error)

NewBroker Here are the constructor and destructor for the broker:

func StartBroker

func StartBroker(port int, verbose bool, setters ...Option) *Broker

StartBroker Finally here is the main task. We create a new broker instance and then processes messages on the broker socket:

func (*Broker) Bind

func (broker *Broker) Bind(endpoint string) (err error)

Bind The bind method binds the broker instance to an endpoint. We can call this multiple times. Note that MDP uses a single socket for both clients and workers:

func (*Broker) ClientMsg

func (broker *Broker) ClientMsg(senderb []byte, msg [][]byte)

ClientMsg Process a request coming from a client. We implement MMI requests directly here (at present, we implement only the mmi.service request):

func (*Broker) Close

func (broker *Broker) Close() (err error)

Close ...

func (*Broker) Purge

func (broker *Broker) Purge()

Purge The purge method deletes any idle workers that haven't pinged us in a while. We hold workers from oldest to most recent, so we can stop scanning whenever we find a live worker. This means we'll mainly stop at the first worker, which is essential when we have large numbers of workers (since we call this method in our critical path):

func (*Broker) ServiceRequire

func (broker *Broker) ServiceRequire(service_frame string) (service *Service)

ServiceRequire Lazy constructor that locates a service by name, or creates a new service if there is no service already with that name.

func (*Broker) WorkerLen

func (broker *Broker) WorkerLen() int

func (*Broker) WorkerMsg

func (broker *Broker) WorkerMsg(senderb []byte, msg [][]byte)

WorkerMsg The WorkerMsg method processes one READY, REPLY, HEARTBEAT or DISCONNECT message sent to the broker by a worker:

func (*Broker) WorkerRequire

func (broker *Broker) WorkerRequire(identity string) (worker *Worker)

WorkerRequire Lazy constructor that locates a worker by identity, or creates a new worker if there is no worker already with that identity.

type Option

type Option func(*Options)

func HeartbeatInterval

func HeartbeatInterval(heartbeatInterval time.Duration) Option

func HeartbeatLiveness

func HeartbeatLiveness(heartbeatLiveness int) Option

func WorkerAckInterval

func WorkerAckInterval(workerAckInterval time.Duration) Option

type Options

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

Options broker options

type Service

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

Service The service class defines a single service instance:

func (*Service) Dispatch

func (service *Service) Dispatch(msg [][]byte)

Dispatch The dispatch method sends requests to waiting workers:

type Worker

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

Worker The worker class defines a single worker, idle or active:

func (*Worker) Delete

func (worker *Worker) Delete(disconnect bool)

Delete The delete method deletes the current worker.

func (*Worker) Send

func (worker *Worker) Send(command, option string, msg [][]byte) (err error)

Send The send method formats and sends a command to a worker. The caller may also provide a command option, and a message payload:

func (*Worker) Waiting

func (worker *Worker) Waiting()

Waiting This worker is now waiting for work

Directories

Path Synopsis
Majordomo Protocol Client and Worker API.
Majordomo Protocol Client and Worker API.

Jump to

Keyboard shortcuts

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