queue

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2018 License: BSD-3-Clause Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Description

Queue Lib for glib, internal support Redis Only.

Install

go get github.com/carltd/glib/queue

Usage

Publisher
import (
    "github.com/carltd/glib/queue/message"
    
    "github.com/carltd/glib/queue"
    _ "github.com/carltd/glib/queue/queue_redis"
)

pub, _ := queue.NewPublisher("redis", "redis://127.0.0.1:6379")
pub.Publish("subject", &message.Message{
    Body: util.MustMessageBody(nil, /* point to your protobuffer struct */ ),
})
pub.Close()
Consumer
import (
    "github.com/carltd/glib/queue/message"
    
    "github.com/carltd/glib/queue"
    _ "github.com/carltd/glib/queue/queue_redis"
)

con, _ := queue.NewConsumer("redis", "redis://127.0.0.1:6379")
sub,_ := con.Subscribe("subject", "cluster-group")
msg, _ := sub.NextMessage(time.Second)
// logic for msg
con.Close()

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Drivers

func Drivers() []string

Drivers returns a sorted list of the names of the registered drivers.

func Register

func Register(name string, d driver)

Register makes a queue driver available by the provided name. If Register is called twice with the same name or if driver is nil, it panics.

Types

type Conn

type Conn interface {
	Ping() error

	io.Closer
	// contains filtered or unexported methods
}

type Consumer

type Consumer interface {
	io.Closer
	// contains filtered or unexported methods
}

func NewConsumer

func NewConsumer(driverName, queueAddrs string) (Consumer, error)
Example
package main

import (
	"log"
	"strings"
	"time"

	"github.com/carltd/glib/queue"
	"github.com/carltd/glib/queue/util"

	_ "github.com/carltd/glib/queue/queue_redis"
)

func main() {
	c, err := queue.NewConsumer("redis", "redis://:123456@localhost")
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()

	sub, err := c.Subscribe("subject", "appName")
	if err != nil {
		log.Fatal(err)
	}

	msg, err := sub.NextMessage(time.Second)
	if err != nil {
		if !strings.Contains(err.Error(), "timeout") {
			log.Fatal(err)
		}
		// retry?
	}

	// t is the message's publish time
	t, _ := util.TimestampFromMessageID(msg.MessageId)
	_ = t

	_ = msg
	// msg.MessageId
	// msg.Priority
	// msg.Options    some options for the msg
	// msg.Body
	// ptypes.UnmarshalAny(msg.Body, &YourProtoBufferStructPoint)
}

type Publisher

type Publisher interface {
	io.Closer
	// contains filtered or unexported methods
}

func NewPublisher

func NewPublisher(driverName, queueAddrs string) (Publisher, error)
Example
package main

import (
	"log"

	"github.com/carltd/glib/queue"
	"github.com/carltd/glib/queue/message"

	_ "github.com/carltd/glib/queue/queue_redis"
)

func main() {
	pub, err := queue.NewPublisher("redis", "redis://:123456@localhost")
	if err != nil {
		log.Fatal(err)
	}
	defer pub.Close()

	err = pub.Publish("subject", &message.Message{})
	if err != nil {
		log.Fatal(err)
	}
}

type Subscriber

type Subscriber interface {
	NextMessage(timeout time.Duration) (*message.Message, error)
	io.Closer
}

Directories

Path Synopsis
Package message is a generated protocol buffer package.
Package message is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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