This is an automated email from the ASF dual-hosted git repository.

lizhimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git


The following commit(s) were added to refs/heads/master by this push:
     new 3c37fbe7 [ISSUE #1070] [Golang] Add SSL configuration when starting 
the client (#1072)
3c37fbe7 is described below

commit 3c37fbe7a07f02d96fe88db2659be2cc6662c81c
Author: takagi <[email protected]>
AuthorDate: Thu Sep 4 11:39:11 2025 +0800

    [ISSUE #1070] [Golang] Add SSL configuration when starting the client 
(#1072)
    
    Co-authored-by: weilin <[email protected]>
---
 golang/conn.go                         | 14 +++++++++++++-
 golang/example/producer/normal/main.go |  3 +++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/golang/conn.go b/golang/conn.go
index 7b52e02b..0bcd8b5a 100644
--- a/golang/conn.go
+++ b/golang/conn.go
@@ -21,6 +21,7 @@ import (
        "context"
        "errors"
        "fmt"
+       "github.com/apache/rocketmq-clients/golang/v5/pkg/utils"
 
        
"github.com/apache/rocketmq-clients/golang/v5/pkg/grpc/middleware/zaplog"
        validator "github.com/go-playground/validator/v10"
@@ -28,8 +29,13 @@ import (
        "google.golang.org/grpc/credentials"
 )
 
+const (
+       CLIENT_ENABLE_SSL = "rocketmq.client.enableSsl"
+)
+
 var (
        ErrNoAvailableEndpoints = errors.New("rocketmq: no available endpoints")
+       EnableSsl               = true
 )
 
 type ClientConnFunc func(string, ...ConnOption) (ClientConn, error)
@@ -107,8 +113,10 @@ func (c *clientConn) Close() error {
 
 func (c *clientConn) dialSetupOpts(dopts ...grpc.DialOption) (opts 
[]grpc.DialOption, err error) {
        opts = append(opts, dopts...)
-       if c.creds != nil {
+       if c.creds != nil && EnableSsl {
                opts = append(opts, grpc.WithTransportCredentials(c.creds))
+       } else {
+               opts = append(opts, grpc.WithInsecure())
        }
        // TODO get requestID in header
        opts = append(opts, grpc.WithBlock(), grpc.WithChainUnaryInterceptor(
@@ -133,3 +141,7 @@ func (c *clientConn) dial(target string, dopts 
...grpc.DialOption) (*grpc.Client
        }
        return conn, nil
 }
+
+func init() {
+       EnableSsl = utils.GetenvWithDef(CLIENT_ENABLE_SSL, "true") == "true"
+}
diff --git a/golang/example/producer/normal/main.go 
b/golang/example/producer/normal/main.go
index 27cf708e..4fe7ac2e 100644
--- a/golang/example/producer/normal/main.go
+++ b/golang/example/producer/normal/main.go
@@ -49,6 +49,9 @@ func main() {
        },
                rmq_client.WithTopics(Topic),
        )
+       // Disable SSL. You can also use os.Setenv("rocketmq.client.enableSsl", 
"false"),
+       // but this should be configured before the program starts.
+       rmq_client.EnableSsl = false
        if err != nil {
                log.Fatal(err)
        }

Reply via email to