apache / rocketmq-clients

RocketMQ Clients - Collection of Client Bindings for Apache RocketMQ
https://rocketmq.apache.org/
Apache License 2.0
321 stars 206 forks source link

Question :GolangSDK create grpc conn failed #357

Closed zymaozZ closed 1 year ago

zymaozZ commented 1 year ago

I just copied code from

example/producer/normal/main.go

and then update const variables.

But always get error like this

image

Anyone knows waht can I do? I have confused about it for almost three weeks ...

code:

package main

import (
    "context"
    "fmt"
    rmq_client "github.com/apache/rocketmq-clients/golang"
    "github.com/apache/rocketmq-clients/golang/credentials"
    "log"
    "os"
    "strconv"
    "time"
)

const (
    Topic     = "TestTopic"
    Endpoint  = "ip:port"
    AccessKey = "AccessKey"
    SecretKey = "SecretKey"
)

func main() {
    os.Setenv("mq.consoleAppender.enabled", "true")
    os.Setenv(rmq_client.CLIENT_LOG_LEVEL, "error")
    rmq_client.ResetLogger()
    // new producer instance
    producer, err := rmq_client.NewProducer(&rmq_client.Config{
        Endpoint: Endpoint,
        Credentials: &credentials.SessionCredentials{
            AccessKey:    AccessKey,
            AccessSecret: SecretKey,
        },
    },
        rmq_client.WithTopics(Topic),
    )
    if err != nil {
        log.Fatal(err)
    }
    // start producer
    err = producer.Start()
    if err != nil {
        log.Fatal(err)
    }
    // gracefule stop producer
    defer producer.GracefulStop()

    for i := 0; i < 10; i++ {
        // new a message
        msg := &rmq_client.Message{
            Topic: Topic,
            Body:  []byte("this is a message : " + strconv.Itoa(i)),
        }
        // set keys and tag
        msg.SetKeys("a", "b")
        msg.SetTag("ab")
        // send message in sync
        resp, err := producer.Send(context.TODO(), msg)
        if err != nil {
            log.Fatal(err)
        }
        for i := 0; i < len(resp); i++ {
            fmt.Printf("%#v\n", resp[i])
        }
        // wait a moment
        time.Sleep(time.Second * 1)
    }
}
xdkxlk commented 1 year ago

Could you please use the go get -u github.com/apache/rocketmq-clients/golang to update to latest version and try again?

zymaozZ commented 1 year ago

Could you please use the go get -u github.com/apache/rocketmq-clients/golang to update to latest version and try again?

Thanks for reply.But I have updated the latest version and used code in examples/producer/normal, and still get the same error info. image

Is there any configurations or dependencies I should check again?

s5s-TMD commented 1 year ago

grpc default endPoint is localhost:8081

Could you please use the go get -u github.com/apache/rocketmq-clients/golang to update to latest version and try again?

Thanks for reply.But I have updated the latest version and used code in examples/producer/normal, and still get the same error info. image

Is there any configurations or dependencies I should check again?

grpc default endPoint is localhost:8081, pay attention to port

zymaozZ commented 1 year ago

The 8081 port is not in use

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 30 days with no activity. It will be closed in 3 days if no further activity occurs.

zymaozZ commented 1 year ago

If you start broker with "--enable-proxy", then you should specify the "endpoint" parameter to "locaohost:8081" or "127.0.0.1:8081"