/
publishers.go
53 lines (41 loc) · 1.16 KB
/
publishers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package messagequeue
import (
"context"
"errors"
)
type (
// Publisher produces events onto a queue.
Publisher interface {
Stop()
Publish(ctx context.Context, data any) error
}
// PublisherProvider is a function that provides a Publisher for a given topic.
PublisherProvider interface {
Close()
ProvidePublisher(topic string) (Publisher, error)
}
)
var (
// ErrEmptyTopicName is returned when a topic name is empty.
ErrEmptyTopicName = errors.New("empty topic name")
)
type noopPublisher struct{}
// Publish does nothing.
func (n *noopPublisher) Publish(_ context.Context, _ any) error { return nil }
// Stop does nothing.
func (n *noopPublisher) Stop() {}
// NewNoopPublisher is a noop Publisher.
func NewNoopPublisher() Publisher {
return &noopPublisher{}
}
type noopPublisherProvider struct{}
// ProvidePublisher does nothing.
func (n *noopPublisherProvider) ProvidePublisher(_ string) (Publisher, error) {
return NewNoopPublisher(), nil
}
// Close does nothing.
func (n *noopPublisherProvider) Close() {}
// NewNoopPublisherProvider is a noop PublisherProvider.
func NewNoopPublisherProvider() PublisherProvider {
return &noopPublisherProvider{}
}