Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why not to reuse nats connection in makePublisher or makeSubscriber #4

Closed
kuaner opened this issue Jul 29, 2017 · 3 comments · Fixed by #7
Closed

why not to reuse nats connection in makePublisher or makeSubscriber #4

kuaner opened this issue Jul 29, 2017 · 3 comments · Fixed by #7

Comments

@kuaner
Copy link

kuaner commented Jul 29, 2017

func (t *Transport) newConnection() (*nats.Conn, error) {
	return nats.Connect(t.NatsAddr)
}
func (t *Transport) makeSubscriber(name string) (chan []byte, error) {
	ch := make(chan []byte)

	c, err := t.newConnection()
	if err != nil {
		return nil, err
	}

func (t *Transport) makePublisher(name string) (chan []byte, error) {
	ch := make(chan []byte)
	c, err := t.newConnection()
	if err != nil {
		return nil, err
	}
@matryer
Copy link
Owner

matryer commented Jul 29, 2017

@piotrrojek check this out

@kuaner
Copy link
Author

kuaner commented Jul 29, 2017

and remember to replace "github.com/nats-io/nats" to "github.com/nats-io/go-nats"

@piotrrojek
Copy link
Collaborator

I wrote this adapter over a year ago and haven't touched it since, so I don't remember the details right now... I'll dig into it, but definitely seems like a good idea to reuse connections. Thanks for the feedback!

HeavyHorst added a commit to HeavyHorst/vice that referenced this issue Jul 30, 2017
  - fixed some race conditions (fixes matryer#6)
  - clean up the publisher goroutines on stop
  - reuse the nats connection (fixes matryer#4)
  - allow it to configure the underlying nats connection to make it
possible to connect to secure nats clusters etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants