Skip to content

Commit

Permalink
Rename topics to patterns for subscriptions
Browse files Browse the repository at this point in the history
Signed-off-by: Chaitanya Munukutla <[email protected]>
  • Loading branch information
c16a committed Apr 6, 2024
1 parent 12423f2 commit 051f9a5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ A tiny Websocket-based event broker.
- [ ] Offline messages
- [ ] Clustering
- [x] QoS (0, 1)
- [x] Topc Patterns
- [x] Topics & Patterns

### Topic patterns
Topic patterns are heavily inspired by [NATS's subject-based messaging](https://docs.nats.io/nats-concepts/subjects).
### Topics & patterns
Topics and patterns are heavily inspired by [NATS's subject-based messaging](https://docs.nats.io/nats-concepts/subjects).

## Why does this exist?
Because.
4 changes: 2 additions & 2 deletions broker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ func (client *ConnectedClient) GetSubscription(topic string) *Subscription {
return nil
}

func (client *ConnectedClient) SubscribeToTopic(topic string, group string) {
func (client *ConnectedClient) SubscribeToPattern(pattern string, group string) {
client.mutex.Lock()
defer client.mutex.Unlock()

subscription := &Subscription{active: true, pattern: topic}
subscription := &Subscription{active: true, pattern: pattern}
if len(group) > 0 {
subscription.group = group
}
Expand Down
6 changes: 3 additions & 3 deletions events/sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package events
const Sub = "sub"

type SubEvent struct {
Kind string `json:"kind"`
Group string `json:"group"`
Topic string `json:"topic"`
Kind string `json:"kind"`
Group string `json:"group"`
Pattern string `json:"pattern"`
}
4 changes: 2 additions & 2 deletions handlers/sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ func handleSubscribe(message []byte, client *broker.ConnectedClient) error {
if err != nil {
return err
}
client.SubscribeToTopic(event.Topic, event.Group)
client.SubscribeToPattern(event.Pattern, event.Group)
subackEvent := &events.SubAckEvent{
Kind: events.SubAck,
Success: true,
Topic: event.Topic,
Topic: event.Pattern,
}
return client.WriteInterface(subackEvent)
}
6 changes: 3 additions & 3 deletions handlers/sub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ func TestHandleSubscribe(t *testing.T) {
client := broker.NewConnectedClient(&TestingWebSocketConnection{}, "client-1")

event := &events.SubEvent{
Kind: events.Sub,
Group: "g1",
Topic: "t1",
Kind: events.Sub,
Group: "g1",
Pattern: "t1",
}
message, err := json.Marshal(event)
if err != nil {
Expand Down

0 comments on commit 051f9a5

Please sign in to comment.