Skip to content

FX-HAO/subscriber

Repository files navigation

subscriber

GoDoc Build Status Go Report Card Test Coverage

Subscriber is a simple implementation of the subscribers in Pub/Sub pattern. It's easy to use and provide you most of the basic functionality you need.

Usage

import (
	"github.com/sirupsen/logrus"
	"github.com/streadway/amqp"
)

logger := logrus.New()
subMgr := NewSubscriberManager(logger)
subMgr.Register(
    "TestAMQPSubscriber",
    &Setup{
        URL: "amqp://root:root@rabbitmq:5672/test.amqp.exchange1/test.amqp.queue1?route=foo&route=bar&ack=false&type=direct",
        ActionFunc: func(args ...interface{}) {
            delivery := args[0].(amqp.Delivery)
            delivery.Ack(false)
        },
    },
)
subMgr.Register(
    "TestRedisSubscriber",
    &Setup{
        URL: "redis://:password@redis:6379/?channel=foo&channel=bar",
        ActionFunc: func(args ...interface{}) {
            message := args[0].(*redis.Message).Payload
            fmt.Println(message)
        },
    },
)
subMgr.Run()

// Stop the subscribers
subMgr.GracefulStop()

Roadmap

  • Add support for AMQP
  • Add support for Redis

About

Pub/Sub in golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages