foreman

package module
v0.0.0-...-34ce9ce Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2014 License: MIT Imports: 9 Imported by: 0

README

Foreman

A thin layer on top of the go nsq client to coordinate multiple handlers.

Do it like this:

// Your type that needs to implement nsq.Handler
type WidgetHandler struct {}

// Responsible for constructing a nsq.Handler. You can use topic, channel and worker id if you want.
func NewWidgetHandler(topic string, channel string, id int) nsq.Handler {
  return &WidgetHandler{}
}

// The same HandleMessage that any nsq.Handler needs to implement
func (h *WidgetHandler) HandleMessage(m *nsq.Message) (err error) {
  err = errors.New("i dont know how to make widgets")
  return
}

func main() {
  // Create a new instance with a given lookupd http address
  f := foreman.New("127.0.0.1:4161")

  // Handle topic "widgets" using channel "myapp" using 10 instances of WidgetHandler.
  // Check it for errors.
  err := f.AddHandler("widgets", "myapp", 10, NewWidgetHandler)

  // You can add more handlers here. Maybe you want to process each widget twice.
  err := f.AddHandler("widgets", "myapp2", 10, NewWidgetHandler)

  // Connects to lookupd and starts processing messages.
  // Blocks, listens for signals and handles clean shutdown of all nsq readers.
  // Returns nil when all nsq readers have stopped or err if something happens during startup.
  // Check it for errors.
  err = f.Run()
}

LICENSE

MIT, see LICENSE for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Foreman

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

func New

func New(addr string) *Foreman

func (*Foreman) AddHandler

func (f *Foreman) AddHandler(topic string, channel string, count int, config *nsq.Config, handler nsq.Handler) (r *nsq.Consumer, err error)

func (*Foreman) Run

func (f *Foreman) Run() (err error)

Jump to

Keyboard shortcuts

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