MF-1091 - Use channels. as broker prefix (#1098)

Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
This commit is contained in:
Manuel Imperiale 2020-04-06 12:30:26 +02:00 committed by GitHub
parent 1d78233fe6
commit 8325c1caf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 18 deletions

View File

@ -28,9 +28,10 @@ type Nats interface {
}
const (
prefix = "channel"
chansPrefix = "channels"
// SubjectAllChannels define the subject to subscribe to all channels messages
SubjectAllChannels = "channel.>"
SubjectAllChannels = "channels.>"
)
var (
@ -64,7 +65,7 @@ func (b broker) Publish(_ context.Context, _ string, msg Message) error {
return err
}
subject := fmt.Sprintf("%s.%s", prefix, msg.Channel)
subject := fmt.Sprintf("%s.%s", chansPrefix, msg.Channel)
if msg.Subtopic != "" {
subject = fmt.Sprintf("%s.%s", subject, msg.Subtopic)
}
@ -75,9 +76,9 @@ func (b broker) Publish(_ context.Context, _ string, msg Message) error {
return nil
}
func (b broker) Subscribe(subject string, consumer func(msg *nats.Msg)) (*nats.Subscription, error) {
ps := fmt.Sprintf("%s.%s", prefix, subject)
sub, err := b.conn.Subscribe(ps, consumer)
func (b broker) Subscribe(subject string, f func(msg *nats.Msg)) (*nats.Subscription, error) {
ps := fmt.Sprintf("%s.%s", chansPrefix, subject)
sub, err := b.conn.Subscribe(ps, f)
if err != nil {
return nil, errors.Wrap(errNatsSub, err)
}

View File

@ -1,4 +1,4 @@
# If you want to listen on all subjects, just pass one element ["channel.>"], otherwise
# pass the list of subjects (e.g ["channel.<channel_id>", "channel.<channel_id>.sub.topic.x", ...]).
# If you want to listen on all subjects, just pass one element ["channels.>"], otherwise
# pass the list of subjects (e.g ["channels.<channel_id>", "channels.<channel_id>.sub.topic.x", ...]).
[subjects]
filter = ["channel.>"]
filter = ["channels.>"]

View File

@ -1,4 +1,4 @@
# If you want to listen on all subjects, just pass one element ["channel.>"], otherwise
# pass the list of subjects (e.g ["channel.<channel_id>", "channel.<channel_id>.sub.topic.x", ...]).
# If you want to listen on all subjects, just pass one element ["channels.>"], otherwise
# pass the list of subjects (e.g ["channels.<channel_id>", "channels.<channel_id>.sub.topic.x", ...]).
[subjects]
filter = ["channel.>"]
filter = ["channels.>"]

View File

@ -1,4 +1,4 @@
# If you want to listen on all subjects, just pass one element ["channel.>"], otherwise
# pass the list of subjects (e.g ["channel.<channel_id>", "channel.<channel_id>.sub.topic.x", ...]).
# If you want to listen on all subjects, just pass one element ["channels.>"], otherwise
# pass the list of subjects (e.g ["channels.<channel_id>", "channels.<channel_id>.sub.topic.x", ...]).
[subjects]
filter = ["channel.>"]
filter = ["channels.>"]

View File

@ -1,4 +1,4 @@
# If you want to listen on all subjects, just pass one element ["channel.>"], otherwise
# pass the list of subjects (e.g ["channel.<channel_id>", "channel.<channel_id>.sub.topic.x", ...]).
# If you want to listen on all subjects, just pass one element ["channels.>"], otherwise
# pass the list of subjects (e.g ["channels.<channel_id>", "channels.<channel_id>.sub.topic.x", ...]).
[subjects]
filter = ["channel.>"]
filter = ["channels.>"]