Code Monkey home page Code Monkey logo

watermill-jetstream's People

Contributors

alexcuse avatar m110 avatar ma-hartma avatar sacro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

watermill-jetstream's Issues

Core NATS Support

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.

Altering subject in marshaler defaultNatsMsg

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.

func defaultNatsMsg(topic string, uuid string, data []byte, hdr nats.Header) *nats.Msg {
return &nats.Msg{
Subject: PublishSubject(topic, uuid),
Data: data,
Header: hdr,
}
}

Add docs to README

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.