-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpubsub.go
76 lines (63 loc) · 2.28 KB
/
pubsub.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package baleen
import (
"errors"
"github.com/ThreeDotsLabs/watermill"
"github.com/ThreeDotsLabs/watermill/message"
"github.com/rotationalio/baleen/config"
esdk "github.com/rotationalio/go-ensign"
"github.com/rotationalio/watermill-ensign/pkg/ensign"
)
// Names of available topics
const (
TopicSubscriptions = "subscriptions"
TopicFeeds = "feeds"
TopicDocuments = "documents"
)
func CreatePublisher(conf config.PublisherConfig, logger watermill.LoggerAdapter) (message.Publisher, error) {
if conf.Ensign.Enabled {
return CreateEnsignPublisher(conf.Ensign, logger)
}
if conf.Kafka.Enabled {
return CreateKafkaPublisher(conf.Kafka, logger)
}
return nil, errors.New("invalid configuration: no publisher enabled")
}
func CreateEnsignPublisher(conf config.EnsignConfig, logger watermill.LoggerAdapter) (message.Publisher, error) {
// TODO: move the ensign config to the watermill-ensign library to avoid multi-import
opts := ensign.PublisherConfig{
EnsignConfig: &esdk.Options{
Endpoint: conf.Endpoint,
ClientID: conf.ClientID,
ClientSecret: conf.ClientSecret,
Insecure: conf.Insecure,
},
}
return ensign.NewPublisher(opts, logger)
}
func CreateKafkaPublisher(conf config.KafkaConfig, logger watermill.LoggerAdapter) (message.Publisher, error) {
return nil, errors.New("not implemented yet")
}
func CreateSubscriber(conf config.SubscriberConfig, logger watermill.LoggerAdapter) (message.Subscriber, error) {
if conf.Ensign.Enabled {
return CreateEnsignSubscriber(conf.Ensign, logger)
}
if conf.Kafka.Enabled {
return CreateKafkaSubscriber(conf.Kafka, logger)
}
return nil, errors.New("invalid configuration: no subscriber enabled")
}
func CreateEnsignSubscriber(conf config.EnsignConfig, logger watermill.LoggerAdapter) (message.Subscriber, error) {
// TODO: move the ensign config to the watermill-ensign library to avoid multi-import
opts := ensign.SubscriberConfig{
EnsignConfig: &esdk.Options{
Endpoint: conf.Endpoint,
ClientID: conf.ClientID,
ClientSecret: conf.ClientSecret,
Insecure: conf.Insecure,
},
}
return ensign.NewSubscriber(opts, logger)
}
func CreateKafkaSubscriber(conf config.KafkaConfig, logger watermill.LoggerAdapter) (message.Subscriber, error) {
return nil, errors.New("not implemented yet")
}