MF-1091 - Use channels. as broker prefix (#1098)
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
This commit is contained in:
parent
1d78233fe6
commit
8325c1caf6
|
@ -28,9 +28,10 @@ type Nats interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
prefix = "channel"
|
chansPrefix = "channels"
|
||||||
|
|
||||||
// SubjectAllChannels define the subject to subscribe to all channels messages
|
// SubjectAllChannels define the subject to subscribe to all channels messages
|
||||||
SubjectAllChannels = "channel.>"
|
SubjectAllChannels = "channels.>"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -64,7 +65,7 @@ func (b broker) Publish(_ context.Context, _ string, msg Message) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
subject := fmt.Sprintf("%s.%s", prefix, msg.Channel)
|
subject := fmt.Sprintf("%s.%s", chansPrefix, msg.Channel)
|
||||||
if msg.Subtopic != "" {
|
if msg.Subtopic != "" {
|
||||||
subject = fmt.Sprintf("%s.%s", subject, 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b broker) Subscribe(subject string, consumer func(msg *nats.Msg)) (*nats.Subscription, error) {
|
func (b broker) Subscribe(subject string, f func(msg *nats.Msg)) (*nats.Subscription, error) {
|
||||||
ps := fmt.Sprintf("%s.%s", prefix, subject)
|
ps := fmt.Sprintf("%s.%s", chansPrefix, subject)
|
||||||
sub, err := b.conn.Subscribe(ps, consumer)
|
sub, err := b.conn.Subscribe(ps, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(errNatsSub, err)
|
return nil, errors.Wrap(errNatsSub, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# If you want to listen on all subjects, just pass one element ["channel.>"], otherwise
|
# If you want to listen on all subjects, just pass one element ["channels.>"], otherwise
|
||||||
# pass the list of subjects (e.g ["channel.<channel_id>", "channel.<channel_id>.sub.topic.x", ...]).
|
# pass the list of subjects (e.g ["channels.<channel_id>", "channels.<channel_id>.sub.topic.x", ...]).
|
||||||
[subjects]
|
[subjects]
|
||||||
filter = ["channel.>"]
|
filter = ["channels.>"]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# If you want to listen on all subjects, just pass one element ["channel.>"], otherwise
|
# If you want to listen on all subjects, just pass one element ["channels.>"], otherwise
|
||||||
# pass the list of subjects (e.g ["channel.<channel_id>", "channel.<channel_id>.sub.topic.x", ...]).
|
# pass the list of subjects (e.g ["channels.<channel_id>", "channels.<channel_id>.sub.topic.x", ...]).
|
||||||
[subjects]
|
[subjects]
|
||||||
filter = ["channel.>"]
|
filter = ["channels.>"]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# If you want to listen on all subjects, just pass one element ["channel.>"], otherwise
|
# If you want to listen on all subjects, just pass one element ["channels.>"], otherwise
|
||||||
# pass the list of subjects (e.g ["channel.<channel_id>", "channel.<channel_id>.sub.topic.x", ...]).
|
# pass the list of subjects (e.g ["channels.<channel_id>", "channels.<channel_id>.sub.topic.x", ...]).
|
||||||
[subjects]
|
[subjects]
|
||||||
filter = ["channel.>"]
|
filter = ["channels.>"]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# If you want to listen on all subjects, just pass one element ["channel.>"], otherwise
|
# If you want to listen on all subjects, just pass one element ["channels.>"], otherwise
|
||||||
# pass the list of subjects (e.g ["channel.<channel_id>", "channel.<channel_id>.sub.topic.x", ...]).
|
# pass the list of subjects (e.g ["channels.<channel_id>", "channels.<channel_id>.sub.topic.x", ...]).
|
||||||
[subjects]
|
[subjects]
|
||||||
filter = ["channel.>"]
|
filter = ["channels.>"]
|
||||||
|
|
Loading…
Reference in New Issue