-
Notifications
You must be signed in to change notification settings - Fork 663
/
brokers_nats.go
41 lines (31 loc) · 929 Bytes
/
brokers_nats.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
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0
//go:build !rabbitmq
// +build !rabbitmq
package brokers
import (
"context"
"log"
"log/slog"
"github.com/absmach/magistrala/pkg/messaging"
"github.com/absmach/magistrala/pkg/messaging/nats"
)
// SubjectAllChannels represents subject to subscribe for all the channels.
const SubjectAllChannels = "channels.>"
func init() {
log.Println("The binary was build using Nats as the message broker")
}
func NewPublisher(ctx context.Context, url string, opts ...messaging.Option) (messaging.Publisher, error) {
pb, err := nats.NewPublisher(ctx, url, opts...)
if err != nil {
return nil, err
}
return pb, nil
}
func NewPubSub(ctx context.Context, url string, logger *slog.Logger, opts ...messaging.Option) (messaging.PubSub, error) {
pb, err := nats.NewPubSub(ctx, url, logger, opts...)
if err != nil {
return nil, err
}
return pb, nil
}