disqchan

package
v0.0.0-...-b59da3b Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2015 License: BSD-2-Clause Imports: 7 Imported by: 0

README

DisqChan - distributed channels over Disque

This is an example project with a higher level abstraction over go-disque.

This library provides a disque-based networked channels, on which you can send and receive objects between machines. Messages are encoded as JSON and deserialized when received.

Example Usage:

Sending messages:

func ExampleSend() {

	sc := disqchan.NewChan("mychan", false, "127.0.0.1:7711")
	defer sc.Stop()

	ch := sc.SendChan()
	for i := 0; i < 100; i++ {
		ch <- fmt.Sprintf("Message %d", i)
	}

}

Receiving Messages:

func ExampleRecv() {

	c := NewChan("mychan", false, "127.0.0.1:7711")

	rch := c.RecvChan()

	i := 0
	for v := range rch {

		fmt.Println("Received: ", v)
		i++
		if i == 10 {
			fmt.Println("finished")
			break
		}
	}
}

Documentation

Overview

Package disqchan is an abstraction of Disque messages over Go channels.

The idea is that you create Chan objects on multiple machines. Each of them has to have the same name across machines, and can be used to send and/or receive messages.

Messages can be any object. Messages are serialized as JSON, so the usual rules of JSON marshalling apply

Index

Constants

This section is empty.

Variables

View Source
var (
	// The timeout on GETJOB requests
	GetTimeout = time.Second
)

Functions

This section is empty.

Types

type Chan

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

Chan represents a cross machine "channel" over disque

func NewChan

func NewChan(name string, async bool, addrs ...string) *Chan

NewChan creates a new disque channel objec with a given name, over a disque cluster with the given addrs. If async is true, messages are sent using disque async replication (see disque docs for details)

func (Chan) Name

func (c Chan) Name() string

Name returns the name of the chan

func (*Chan) RecvChan

func (c *Chan) RecvChan() <-chan interface{}

RecvChan returns a channel from which received messages can be received.

Before it is called, this Chan is not receiving from the queue

func (*Chan) SendChan

func (c *Chan) SendChan() chan<- interface{}

SendChan returns a channel to which objects can be sent

func (*Chan) Stop

func (c *Chan) Stop()

Stop stop the chan's internal send/receive loops

Jump to

Keyboard shortcuts

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