rabbitmq

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 4 Imported by: 0

README

RabbitMQ

Streamer

package main

import (
	"context"
	"log"

	"github.com/spy16/pkg/rabbitmq"
	"github.com/streadway/amqp"
)

func main() {
	rs := &rabbitmq.Streamer{
		Workers:  10,
		Addr:     "localhost:5672",
		Consumer: "pkg-consumer",
		AutoAck:  false,
		Queue:    "events",
		Process: func(d amqp.Delivery) {
			log.Printf("message: %s", string(d.Body))
			_ = d.Ack(false)
		},
	}

	if err := rs.Run(context.Background()); err != nil {
		log.Fatalf("streamer exited: %v", err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Streamer

type Streamer struct {
	Addr     string                `json:"addr"`
	Queue    string                `json:"queue"`
	Consumer string                `json:"consumer"`
	Workers  int                   `json:"workers"`
	AutoAck  bool                  `json:"auto_ack"`
	Process  func(d amqp.Delivery) `json:"-"`
}

Streamer implements a RabbitMQ streamer. Messages are streamed to the Process function. Process is responsible for Ack/Nack.

func (*Streamer) Run

func (st *Streamer) Run(ctx context.Context) error

Jump to

Keyboard shortcuts

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