liftbridge-io / go-liftbridge

Go client for Liftbridge. https://github.com/liftbridge-io/liftbridge
Apache License 2.0
67 stars 18 forks source link

Subscriber issue w.r.t Golang client except 9292 none of the other ports are working. #65

Open akshay071990 opened 4 years ago

akshay071990 commented 4 years ago

Hi Tyler,

In the below golang code:

package main

import (
    "context"
    "fmt"

    lift "github.com/liftbridge-io/go-liftbridge"
)

func main() {
    addr := "localhost:30276"
    client, err := lift.Connect([]string{addr})
    if err != nil {
        panic(err)
    }
    defer client.Close()

    ctx := context.Background()
    if err := client.Subscribe(ctx, "testpod-stream", func(msg *lift.Message, err error) {
        if err != nil {
            panic(err)
        }
        fmt.Println(msg.Timestamp(), msg.Offset(), string(msg.Key()), string(msg.Value()))
    }, lift.StartAtEarliestReceived()); err != nil {
        panic(err)
    }

    <-ctx.Done()
}

I am getting the error: pc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp 0.0.0.0:9292: connect: connection refused"

So as you can see from my source code the port used is 30276 (Which is the node port of my liftbridge microservice) but the subscriber is trying to connect 9292. (The publisher example is working perfectly fine, just subscriber is giving this issue). Also this issue is not seen in JAVA subscriber client. So is this a bug or do i need to make any other configurations? Can you pls help me!

Thanks Akshay

tylertreat commented 4 years ago

Can you share your Liftbridge configuration? Also, are you running a single node or multiple Liftbridge nodes?

akshay071990 commented 4 years ago

Hi Tyler,

i am using single node k8s cluster deployed in my mac. Currently liftbridge has only one replicaset so there is only one leader and no followers. Using the Helmchart which is adapted from ("https://github.com/pozetroninc/liftbridge-helm-chart/issues/3") the only change here i made is replica count is set to 1.

Also this issue is also seen if liftbridge is deployed as a binary with some other port say 9293, for that as well golang subscriber gives error as :

pc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp 0.0.0.0:9292: connect: connection refused"

for binary the configuration used is:

listen: localhost:9293
host: localhost
data.dir: /tmp/liftbridge/server-5
activity.stream.enabled: true

nats.servers:
  - nats://localhost:4222

streams:
  retention.max:
    age: 24h
    messages: 100
  compact.enabled: true

# Specify cluster settings.
clustering:
  server.id: server-5
  raft.bootstrap.seed: true
  replica.max.lag.time: 40s

if the port is changed to 9292 it works perfectly fine.

Thanks AKshay

tylertreat commented 4 years ago

The client is attempting to connect to port 9292 because this is the default port. Since port is not explicitly set in the config, the server is falling back to the default. host and port are used to specify the address that is advertised to the client, while listen is what the server binds to. Therefore, there are two ways you can fix this. You can either do the following:

# Explicitly specify the port to advertise
port: 9293

Or you can remove the host setting from the config. In this case, the value of listen will be returned to clients.

See more on these configs here.