Providers Reference
Configuration reference for all herald providers.
Kafka
import "github.com/zoobz-io/herald/kafka"
Constructor
func New(topic string, opts ...Option) *Provider
Options
| Option | Description |
|---|
WithWriter(w Writer) | Set Kafka writer for publishing |
WithReader(r Reader) | Set Kafka reader for subscribing |
Interfaces
type Writer interface {
WriteMessages(ctx context.Context, msgs ...kafka.Message) error
Close() error
}
type Reader interface {
FetchMessage(ctx context.Context) (kafka.Message, error)
CommitMessages(ctx context.Context, msgs ...kafka.Message) error
Close() error
}
NATS
import "github.com/zoobz-io/herald/nats"
Constructor
func New(subject string, opts ...Option) *Provider
Options
| Option | Description |
|---|
WithConn(c *nats.Conn) | Set NATS connection |
Note: NATS core does not support headers. Metadata is ignored.
JetStream
import "github.com/zoobz-io/herald/jetstream"
Constructor
func New(subject string, opts ...Option) *Provider
Options
| Option | Description |
|---|
WithJetStream(js jetstream.JetStream) | Set JetStream context |
WithConsumer(c jetstream.Consumer) | Set consumer for subscribing |
WithStream(name string) | Set stream name for publishing |
Google Pub/Sub
import "github.com/zoobz-io/herald/pubsub"
Constructor
func New(opts ...Option) *Provider
Unlike other providers, Pub/Sub requires no identifier in the constructor. Topic and subscription are configured via options.
Options
| Option | Description |
|---|
WithTopic(t *pubsub.Topic) | Set topic for publishing |
WithSubscription(s *pubsub.Subscription) | Set subscription for consuming |
Redis Streams
import "github.com/zoobz-io/herald/redis"
Constructor
func New(stream string, opts ...Option) *Provider
Options
| Option | Description |
|---|
WithClient(c *redis.Client) | Set Redis client |
WithGroup(name string) | Set consumer group name |
WithConsumer(name string) | Set consumer name within group |
WithMaxLen(n int64) | Set stream max length |
AWS SQS
import "github.com/zoobz-io/herald/sqs"
Constructor
func New(queueURL string, opts ...Option) *Provider
Options
| Option | Description |
|---|
WithClient(c *sqs.Client) | Set SQS client |
WithWaitTimeSeconds(n int32) | Long polling wait time |
WithMaxMessages(n int32) | Max messages per receive |
WithVisibilityTimeout(n int32) | Visibility timeout seconds |
RabbitMQ/AMQP
import "github.com/zoobz-io/herald/amqp"
Constructor
func New(exchange string, opts ...Option) *Provider
Options
| Option | Description |
|---|
WithChannel(ch *amqp.Channel) | Set AMQP channel |
WithQueue(name string) | Set queue name for consuming |
WithRoutingKey(key string) | Set routing key for publishing |
WithConsumerTag(tag string) | Set consumer tag |
AWS SNS
import "github.com/zoobz-io/herald/sns"
Constructor
func New(topicARN string, opts ...Option) *Provider
Options
| Option | Description |
|---|
WithClient(c *sns.Client) | Set SNS client |
Note: SNS is publish-only. Subscribe returns closed channel.
BoltDB
import "github.com/zoobz-io/herald/bolt"
Constructor
func New(bucket string, opts ...Option) *Provider
Options
| Option | Description |
|---|
WithDB(db *bbolt.DB) | Set BoltDB database |
WithPollInterval(d time.Duration) | Polling interval (default 100ms) |
WithBatchSize(n int) | Messages per poll (default 10) |
Note: BoltDB does not support metadata. Metadata is ignored.
Firestore
import "github.com/zoobz-io/herald/firestore"
Constructor
func New(collection string, opts ...Option) *Provider
Options
| Option | Description |
|---|
WithClient(c *firestore.Client) | Set Firestore client |
WithPollInterval(d time.Duration) | Polling interval |
WithBatchSize(n int) | Documents per poll |
io
import "github.com/zoobz-io/herald/io"
Constructor
func New(opts ...Option) *Provider
Options
| Option | Description |
|---|
WithWriter(w io.Writer) | Set writer for publishing |
WithReader(r io.Reader) | Set reader for subscribing |
WithDelimiter(b byte) | Message delimiter (default newline) |
Useful for testing with bytes.Buffer or os.Stdout.
Feature Matrix
| Provider | Publish | Subscribe | Metadata | Ack/Nack |
|---|
| Kafka | ✓ | ✓ | ✓ | ✓ |
| NATS | ✓ | ✓ | ✗ | ✗ |
| JetStream | ✓ | ✓ | ✓ | ✓ |
| Pub/Sub | ✓ | ✓ | ✓ | ✓ |
| Redis | ✓ | ✓ | ✓ | ✓ |
| SQS | ✓ | ✓ | ✓ | ✓ |
| AMQP | ✓ | ✓ | ✓ | ✓ |
| SNS | ✓ | ✗ | ✓ | N/A |
| BoltDB | ✓ | ✓ | ✗ | ✓ |
| Firestore | ✓ | ✓ | ✓ | ✓ |
| io | ✓ | ✓ | ✗ | ✗ |