matryer / vice

Go channels at horizontal scale (powered by message queues)
https://medium.com/@matryer/introducing-vice-go-channels-across-many-machines-bcac1147d7e2
Apache License 2.0
1.54k stars 79 forks source link

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

Closed kuaner closed 7 years ago

kuaner commented 7 years ago
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 commented 7 years ago

@piotrrojek check this out

kuaner commented 7 years ago

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

piotrrojek commented 7 years ago

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!