knsq

package
v0.0.0-...-fa4a048 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2013 License: BSD-3-Clause Imports: 12 Imported by: 0

README

Package knsq (“knusk”) is a collection of helper and convenience functions for bitly’s nsq library.

It would be tedious to maintain an overview in this README. For details, please consult the included documentation.

knsq is not considered a separate library of k. The share a version number and release cycle. knsq was created as a subpackage as a means of namespacing and dependency reduction.


Version 0.7.2

Documentation

Overview

package knsq (“knusk”) is a collection of helper and convenience functions for bitly’s nsq library.

See: github.com/bitly/nsq

Index

Constants

View Source
const (
	VERSION = "0.7.2"
)

Variables

This section is empty.

Functions

func AttachEphemeralHandler

func AttachEphemeralHandler(topic, channel, lookupd string, handler nsq.Handler) error

AttachEphemeralHandler create a new nsq.Reader for a topic and attaches the given handler to it. The nsq channel to which the handler gets attached will be ephemeral. Ephemeral channels will not be buffered to disk and may drop messages. Ephemeral channels will also not be persisted after its last client disconnects.

func AttachHandler

func AttachHandler(topic, channel string, lookupd string, handler nsq.Handler) error

AttachHandler creates a new nsq.Reader for a topic and attaches the given handler to it.

func MustReader

func MustReader(topic, channel string) *nsq.Reader

MustReader calls nsq.NewReader and panics if nsq.NewReader returned an error. nsq.NewReader only fails on invalid topic and channel names.

Types

type Client

type Client interface {
	// CreateTopic makes sure a topic exists on the given nsqd.
	CreateTopic(topic string) error
	// Send sends a message on a topic to the specified nsqd.
	Send(topic string, body io.Reader) error
}

func NewTCPClient

func NewTCPClient(addr string) (Client, error)

NewTCPClient creates an implementation of the Client interface using the TCP API of NSQd.

type HandlerFunc

type HandlerFunc func(message *nsq.Message) error

HandlerFunc is a type that makes a single function implement to the nsq.Handler interface which consists of only one function (just like http.HandlerFunc and http.Handler).

func (HandlerFunc) HandleMessage

func (f HandlerFunc) HandleMessage(message *nsq.Message) error

type HttpClient

type HttpClient struct {
	*url.URL
}

HttpClient implements the Client interface using HTTP requests.

func (HttpClient) CreateTopic

func (h HttpClient) CreateTopic(topic string) error

func (HttpClient) Send

func (h HttpClient) Send(topic string, body io.Reader) error

type Lookupd

type Lookupd string

Lookupd represents a running nsqlookupd instance. The underlying string should be the HTTP address in the form of hostname:port.

func (Lookupd) NSQdInstance

func (lookupd Lookupd) NSQdInstance() (Producer, error)

NSQdInstnaces returns a random producer registered with the nsqlookupd.

func (Lookupd) NSQdInstances

func (lookupd Lookupd) NSQdInstances() ([]Producer, error)

NSQdInstnaces returns all producers registered with the nsqlookupd.

type Producer

type Producer struct {
	Hostname         string   `json:"hostname"`
	BroadcastAddress string   `json:"broadcast_address"`
	TcpPort          int      `json:"tcp_port"`
	HttpPort         int      `json:"http_port"`
	Version          string   `json:"version"`
	Topics           []string `json:"topics"`
}

Producer represents a running NSQd instance registered with a nsqlookupd.

func (Producer) HTTPAddr

func (p Producer) HTTPAddr() string

Returns the HTTP address of the producer in the form of hostname:port.

func (Producer) TCPAddr

func (p Producer) TCPAddr() string

Returns the TCP address of the producer in the form of hostname:port.

Jump to

Keyboard shortcuts

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