threedotslabs / watermill-jetstream Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
I'm working on another integration where I want to be able to use core NATS for certain sets of publishers to try and improve throughput. Something I noticed is that you can pretty trivially form an interface for the methods we need (note the removal of options from the signatures):
type Connection interface {
Subscribe(string, nats.MsgHandler) (*nats.Subscription, error)
PublishMsg(*nats.Msg) error
Drain() error
}
*nats.Conn already implements this, which gives you core NATS support. You can then trivially bind over this for jetstream:
// connection mimics the core NATS publish/subscribe API
// so that NATS and jetstream can use the same client orchestration.
type connection struct {
conn *nats.Conn
js nats.JetStream
}
func (j connection) Subscribe(s string, handler nats.MsgHandler) (*nats.Subscription, error) {
subOpts := make([]nats.SubOpt, 0)
//TODO: populate options from config
return j.js.Subscribe(s, handler, subOpts...)
}
func (j connection) PublishMsg(msg *nats.Msg) (err error) {
pubOpts := make([]nats.PubOpt, 0)
//TODO: populate options from config
_, err = j.js.PublishMsg(msg, pubOpts...)
return
}
func (j connection) Drain() error {
return j.conn.Drain()
}
I am not sure how valuable this would be in watermill, but I think it would be pretty easy. Most of the work would likely be to define the new core NATS configurations and setup appropriate tests.
What is the reason behind altering the publisher's subject naming during marshaling? This makes subscribing to the same subject very complicated. I had to remove this modification in my code to be able to publish and subscribe to the same topic successfully.
Changing it would be a breaking change, but there would be a way to just release the change as a feature without breaking changes. However, the reason behind having it is still unknown to me. If you agree to the change and still keep this behavior, for now, I'd be happy to create a PR.
watermill-jetstream/pkg/jetstream/marshaler.go
Lines 31 to 37 in 380cf67
Maybe we could provide in a _example
directory in this repo for simplicity but thinking about this one:
I think some documentation for users for getting started easier would be nice.
I'd like to offer to extend the README and the docs on the website accordingly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.