Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Consumer ¶
type Consumer interface { // Unicast mode Dequeue(subject, group string, timeout time.Duration, msg proto.Message) (*message.Meta, error) // Broadcast mode Subscribe(subject, group string) (Subscriber, error) io.Closer }
func NewConsumer ¶
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) }
Output:
type Publisher ¶
type Publisher interface { // Unicast mode Enqueue(subject string, msg *message.Message) error // Broadcast mode Publish(subject string, msg *message.Message) error io.Closer }
func NewPublisher ¶
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) } }
Output:
Directories ¶
Path | Synopsis |
---|---|
Package message is a generated protocol buffer package.
|
Package message is a generated protocol buffer package. |
Click to show internal directories.
Click to hide internal directories.