You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/07/21 13:50:17 UTC

[GitHub] [rocketmq-clients] guyinyou opened a new pull request, #71: Some progress on golang

guyinyou opened a new pull request, #71:
URL: https://github.com/apache/rocketmq-clients/pull/71

   1. update proto
   2. complete telemetry(Occasional errors are reported when upload settings)
   3. support transaction message
   4. producer is basically done, except for metric


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq-clients] guyinyou closed pull request #71: Some progress on golang

Posted by GitBox <gi...@apache.org>.
guyinyou closed pull request #71: Some progress on golang
URL: https://github.com/apache/rocketmq-clients/pull/71


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq-clients] pherzheyu commented on a diff in pull request #71: Some progress on golang

Posted by GitBox <gi...@apache.org>.
pherzheyu commented on code in PR #71:
URL: https://github.com/apache/rocketmq-clients/pull/71#discussion_r927217458


##########
golang/producer.go:
##########
@@ -22,34 +22,51 @@ import (
 	"errors"
 	"fmt"
 	"log"
+	"math"
 	"sync"
 	"time"
 
 	v2 "github.com/apache/rocketmq-clients/golang/protocol/v2"
 	"github.com/apache/rocketmq-clients/golang/utils"
+	"github.com/valyala/fastrand"
+	"google.golang.org/protobuf/types/known/durationpb"
 )
 
 type Producer interface {
 	Send(context.Context, *Message) ([]*SendReceipt, error)
+	SendWithTransaction(context.Context, *Message, Transaction) ([]*SendReceipt, error)
 	SendAsync(context.Context, *Message, func(context.Context, []*SendReceipt, error))
+	BeginTransaction() Transaction
 	GracefulStop() error
+	isClient

Review Comment:
   非常不建议interface中定义非导出方法



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq-clients] pherzheyu commented on a diff in pull request #71: Some progress on golang

Posted by GitBox <gi...@apache.org>.
pherzheyu commented on code in PR #71:
URL: https://github.com/apache/rocketmq-clients/pull/71#discussion_r927218297


##########
golang/producer.go:
##########
@@ -157,40 +213,40 @@ func (p *producer) send1(ctx context.Context, topic string, messageType v2.Messa
 	var res []*SendReceipt
 	for i := 0; i < len(resp.GetEntries()); i++ {
 		res = append(res, &SendReceipt{
-			MessageID: resp.GetEntries()[i].GetMessageId(),
+			MessageID:     resp.GetEntries()[i].GetMessageId(),
+			TransactionId: resp.GetEntries()[i].GetTransactionId(),
+			Offset:        resp.GetEntries()[i].GetOffset(),
+			Endpoints:     endpoints,
 		})
 	}
 	if attempt > 1 {
 		log.Printf("Resend message successfully, topic=%s, maxAttempts=%d, attempt=%d, endpoints=%s, clientId=%s",
 			topic, maxAttempts, attempt, endpoints.String(), p.cli.clientID)
 	}
 	return res, nil
-	// sendRequest := b.getSendMessageRequest(msg)
-
-	// b, err := p.ns.GetBroker(ctx, msg.Topic)
-	// if err != nil {
-	// 	return nil, err
-	// }
-	// return b.Send(ctx, msg)
-
-	// return nil, nil
 }
 
 // TODO refer to java sdk.
-func (p *producer) send0(ctx context.Context, msgs []*Message, txEnabled bool) ([]*SendReceipt, error) {

Review Comment:
   send0可读性感觉不太好,最好是所见即所得,golang中没有重载,可以使用选项模式



##########
golang/message.go:
##########
@@ -17,41 +17,317 @@
 
 package golang
 
-import "time"
+import (
+	"crypto/md5"
+	"crypto/sha1"
+	"encoding/hex"
+	"hash/crc32"
+	"log"
+	"strconv"
+	"time"
+
+	v2 "github.com/apache/rocketmq-clients/golang/protocol/v2"
+	"github.com/apache/rocketmq-clients/golang/utils"
+	"google.golang.org/protobuf/types/known/timestamppb"
+)
+
+type UnifiedMessage struct {
+	msg    *Message
+	pubMsg *PublishingMessage
+}
+
+func (uMsg *UnifiedMessage) GetMessage() *Message {
+	if uMsg.pubMsg != nil {
+		return uMsg.pubMsg.msg
+	}
+	return uMsg.msg
+}
 
 type Message struct {
-	Topic      string
-	Body       []byte
-	Tag        string
-	Keys       []string
-	Properties map[string]string
+	Topic        string
+	Body         []byte
+	Tag          *string
+	messageGroup *string
+	keys         []string
+	properties   map[string]string
 
-	deliveryTimestamp time.Time
-	messageGroup      string
+	deliveryTimestamp  *time.Time
+	parentTraceContext *string
 }
 
-type MessageExt struct {
+type SendReceipt struct {
 	MessageID     string
-	ReceiptHandle string
-	Message
+	TransactionId string
+	Offset        int64
+	Endpoints     *v2.Endpoints
 }
 
-type SendReceipt struct {
-	MessageID string
+func (msg *Message) GetTopic() string {

Review Comment:
   字段大些,已经是可导出了,不用在增加额外的set、get



##########
golang/client_manager.go:
##########
@@ -162,31 +164,58 @@ func (cm *clientManagerImpl) startUp() {
 }
 func (cm *clientManagerImpl) clearIdleRpcClients() {
 	log.Println("clearIdleRpcClients")

Review Comment:
   TODO:可以借助conn的logger



##########
golang/client_manager.go:
##########
@@ -162,31 +164,58 @@ func (cm *clientManagerImpl) startUp() {
 }
 func (cm *clientManagerImpl) clearIdleRpcClients() {

Review Comment:
   clientManagerImpl太java了,命名上能否更符合golang规范呢



##########
golang/client.go:
##########
@@ -39,6 +36,8 @@ import (
 	"github.com/google/uuid"
 	"github.com/lithammer/shortuuid/v4"
 	"google.golang.org/grpc/metadata"
+
+	"github.com/apache/rocketmq-clients/golang/utils"

Review Comment:
   能否放在pkg目录下,使得pkg含义更具像化



##########
golang/client.go:
##########
@@ -48,6 +47,104 @@ type Client interface {
 	GracefulStop() error
 }
 
+type isClient interface {

Review Comment:
   不可导出interface能不用最好不用,考虑代码可读性和可扩展



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org