queue

package
v0.0.0-...-92ec744 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2015 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UUID

func UUID() string

UUID generates a random UUID

Types

type Connection

type Connection interface {
	// Publish pushes new messages to the queue.
	Publish(string, string, uint) error
	// Subscribe pulls messages from the queue and processes them using the processor function.
	Subscribe(Processor)
}

Connection is an interface that defines how messages are published are received from a queue.

func NewNatsConn

func NewNatsConn(d db.Connection, conn *nats.EncodedConn) Connection

NewNatsConn initializes the connection to Gnatsd. It assumes that the client has been initialized by the application context.

func NewPoolConn

func NewPoolConn(d db.Connection) Connection

NewPoolConn initializes the channel connection

type Message

type Message struct {
	Depth   uint   // depth level where the url was found
	JobUUID string // unique identifiler for the job that trigerred this message
	URL     string // url to crawl
}

Message is the structure that the crawler sends and receives in the queue.

func NewMessage

func NewMessage(jobUUID, url string, d uint) *Message

NewMessage creates new messages to crawl an url.

type NatsConn

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

NatsConn implements the queue.Connection interface using Gnatsd as a queue.

func (*NatsConn) Publish

func (q *NatsConn) Publish(jobUUID, url string, depth uint) error

Publish enqueues new messages in the queue for a given job.

func (*NatsConn) Subscribe

func (q *NatsConn) Subscribe(processor Processor)

Subscribe subscribes the job group to a specific topic to process messages.

type PoolConn

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

PoolConn implements queue.Connection using a channel as a backend. This interface is only suitable for testing. It offers no guarantees about the elements pushed and pulled from the queue.

func (*PoolConn) Publish

func (p *PoolConn) Publish(jobUUID, url string, depth uint) error

Publish sends messages to the channel for a specific job

func (*PoolConn) Subscribe

func (p *PoolConn) Subscribe(processor Processor)

Subscribe receives messages from the channel to process them

type Processor

type Processor func(Connection, db.Connection, *Message)

Processor defines a function interface to process messages.

Jump to

Keyboard shortcuts

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