Skip to content
This repository has been archived by the owner on May 10, 2020. It is now read-only.
/ subly Public archive

lightweight subscription layer with conventions

License

Notifications You must be signed in to change notification settings

workshop-depot/subly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

subly

A lightweight subscription layer with conventions for NATS

Package subly helps with subscribing methods on a struct type as callbacks for NATS, with some naming conventions. A sample usage would look like (from):

s := NewSubscriber(ctx, econn)
s.Subscribe(&timeService{econn})

Assuming we have a service like:

type someService struct{}

func (*someService) SubActionMessage(p *person) {
    /**/
}

func (*someService) RepActionMessageQueue(subject, reply string, p *person) {
    /**/
}

then SubActionMessage would get subscribed to subject someservice.subaction and RepActionMessageQueue would get subscribed to subject someservice.repaction. Subject naming convension is . all lower case, with words message and queue removed from the end.

If a method name ends in Message, it will subscribe to subject as a normall subscriber (just receiving). If a method name ends in MessageQueue, it will subscribe to subject as a member of a queue and the queue name will be _.

Message methods are expected to have one of four signatures.

type person struct {
	Name string `json:"name,omitempty"`
	Age  uint   `json:"age,omitempty"`
}

handler := func(m *Msg)
handler := func(p *person)
handler := func(subject string, o *obj)
handler := func(subject, reply string, o *obj)

Which are NATS's conventions for callbacks.

And the callback methods will unsubscribe from subject when context got canceled.

status

alpha - tHinkering, in it's early stages of real world usage/feedback

About

lightweight subscription layer with conventions

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages