-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmessage_queue_service.go
43 lines (38 loc) · 1.12 KB
/
message_queue_service.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
package messagequeue
import (
"context"
"fmt"
common_mq_config "github.com/caraml-dev/xp/common/messagequeue"
"github.com/caraml-dev/xp/treatment-service/models"
)
type MessageQueueService interface {
SubscribeToManagementService(ctx context.Context) error
DeleteSubscriptions(ctx context.Context) error
}
func NewMessageQueueService(
ctx context.Context,
storage *models.LocalStorage,
mqConfig common_mq_config.MessageQueueConfig,
projectIds []uint32,
googleApplicationCredentialsEnvVar string,
) (MessageQueueService, error) {
var mq MessageQueueService
var err error
switch mqConfig.Kind {
case common_mq_config.NoopMQ:
mq, err = NewNoopMQService()
case common_mq_config.PubSubMQ:
pubsubConfig := PubsubSubscriberConfig{
Project: mqConfig.PubSubConfig.Project,
UpdateTopicName: mqConfig.PubSubConfig.TopicName,
ProjectIds: projectIds,
}
mq, err = NewPubsubMQService(ctx, storage, pubsubConfig, googleApplicationCredentialsEnvVar)
default:
return nil, fmt.Errorf("invalid message queue config (%s) was provided", mqConfig.Kind)
}
if err != nil {
return nil, err
}
return mq, nil
}