lerenn / asyncapi-codegen

An AsyncAPI Golang Code generator that generates all Go code from the broker to the application/user. Just plug your application to your favorite message broker!
Apache License 2.0
76 stars 21 forks source link

feat(brokers/nats-jetstream): allow passing an existing nats connection #235

Closed aksdb closed 2 weeks ago

aksdb commented 2 weeks ago

This PR allows to pass an existing connection, so we don't have to open multiple connections from the same service.

Remark: If a breaking API change is considered, I would even go so far as to remove the URL parameter completely and also remove the WithConnectionOpts. IMO the nats connection should always be handled on the outside to allow proper separation of concerns.

This would also solve edge cases like calling WithConnectionOpts multiple times, which would, at the moment, create multiple connections of which only the last one is closed.

stefanmeschke commented 2 weeks ago

@lerenn Our services are going to use this library a lot for multiple async docs. Therefore we are in the need to reuse the NATS connection so that we don't open multiple connections from the same service for different subscriber and/or publisher. Can you please have a look at this PR?

Thanks in advance! 🙏

lerenn commented 2 weeks ago

Hello @aksdb and @stefanmeschke ! Looks good to me ! Thanks for contributing ☺️

I'll merge it right away :)

lerenn commented 2 weeks ago

Just fixed the lint, other jobs where good so I'll merge it :)

stefanmeschke commented 2 weeks ago

Hello @aksdb and @stefanmeschke ! Looks good to me !

Thanks for contributing ☺️

I'll merge it right away :)

Awesome! Thank you! 🙏