amqp

package
v0.0.0-...-b425644 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: Apache-2.0 Imports: 1 Imported by: 0

README

AMQP Wrapper

This is a simple more golang (use defaults where possible) style wrapper for github.com/streadway/amqp

Bind to an exchange (auto-creates the necessary queue)

package main

import (
    "log"
    "github.com/dynport/dgtk/amqp"
)

func main() {
    connection := &amqp.Connection{
        Address: "amqp://127.0.0.1:5672",
    }
    defer connection.Close()
    queue := &amqp.Queue{
        Name:       "store_metrix",
        AutoDelete: true,
    }
    exchange := &amqp.Exchange{
        Name: "metrix",
    }
    binding := &amqp.Binding{
        Queue:    queue,
        Exchange: exchange,
    }
    e := connection.BindingBind(binding)
    if e != nil {
        return e
    }
    consumer := amqp.Consumer{
        Queue:      queue,
        Connection: connection,
    }
    c, e := consumer.Consume()
    if e != nil {
        log.Fatal(e)
    }
    for del := range c {
      log.Printf("%v", string(del.Body))
    }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Binding

type Binding struct {
	*Queue
	*Exchange
	Pattern string
	NoWait  bool
	Args    amqp.Table
}

type Connection

type Connection struct {
	Address string
	// contains filtered or unexported fields
}

func (*Connection) BindingBind

func (con *Connection) BindingBind(binding *Binding) error

func (*Connection) Channel

func (con *Connection) Channel() (c *amqp.Channel, e error)

func (*Connection) Close

func (con *Connection) Close()

func (*Connection) Connection

func (con *Connection) Connection() (c *amqp.Connection, e error)

func (*Connection) QueueDeclare

func (con *Connection) QueueDeclare(q *Queue) (e error)

type Consumer

type Consumer struct {
	*Connection
	*Queue
	Name      string
	AutoAck   bool
	Exclusive bool
	NoLocal   bool
	NoWait    bool
	Args      amqp.Table
}

func (*Consumer) Consume

func (consumer *Consumer) Consume() (c <-chan amqp.Delivery, e error)

type Exchange

type Exchange struct {
	Name string
}

type Queue

type Queue struct {
	Name       string
	Durable    bool
	AutoDelete bool
	Exclusive  bool
	NoWait     bool
	Args       amqp.Table
}

Jump to

Keyboard shortcuts

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