Browse Source

send init message with session id

mq
chrislu 7 days ago
parent
commit
30e67abd31
  1. BIN
      docker/agent_pub_record
  2. 5
      weed/mq/client/agent_client/agent_publish.go
  3. 8
      weed/mq/client/agent_client/publish_session.go
  4. 20
      weed/mq/client/agent_client/subscribe_session.go

BIN
docker/agent_pub_record

5
weed/mq/client/agent_client/agent_publish.go

@ -7,8 +7,7 @@ import (
func (a *PublishSession) PublishMessageRecord(key []byte, record *schema_pb.RecordValue) error { func (a *PublishSession) PublishMessageRecord(key []byte, record *schema_pb.RecordValue) error {
return a.stream.Send(&mq_agent_pb.PublishRecordRequest{ return a.stream.Send(&mq_agent_pb.PublishRecordRequest{
SessionId: a.sessionId,
Key: key,
Value: record,
Key: key,
Value: record,
}) })
} }

8
weed/mq/client/agent_client/publish_session.go

@ -15,7 +15,6 @@ type PublishSession struct {
partitionCount int partitionCount int
publisherName string publisherName string
stream grpc.BidiStreamingClient[mq_agent_pb.PublishRecordRequest, mq_agent_pb.PublishRecordResponse] stream grpc.BidiStreamingClient[mq_agent_pb.PublishRecordRequest, mq_agent_pb.PublishRecordResponse]
sessionId int64
} }
func NewPublishSession(agentAddress string, topicSchema *schema.Schema, partitionCount int, publisherName string) (*PublishSession, error) { func NewPublishSession(agentAddress string, topicSchema *schema.Schema, partitionCount int, publisherName string) (*PublishSession, error) {
@ -48,12 +47,17 @@ func NewPublishSession(agentAddress string, topicSchema *schema.Schema, partitio
return nil, fmt.Errorf("publish record: %v", err) return nil, fmt.Errorf("publish record: %v", err)
} }
if err = stream.Send(&mq_agent_pb.PublishRecordRequest{
SessionId: resp.SessionId,
}); err != nil {
return nil, fmt.Errorf("send session id: %v", err)
}
return &PublishSession{ return &PublishSession{
schema: topicSchema, schema: topicSchema,
partitionCount: partitionCount, partitionCount: partitionCount,
publisherName: publisherName, publisherName: publisherName,
stream: stream, stream: stream,
sessionId: resp.SessionId,
}, nil }, nil
} }

20
weed/mq/client/agent_client/subscribe_session.go

@ -4,10 +4,10 @@ import (
"context" "context"
"fmt" "fmt"
"github.com/seaweedfs/seaweedfs/weed/mq/topic" "github.com/seaweedfs/seaweedfs/weed/mq/topic"
"github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/pb/mq_agent_pb" "github.com/seaweedfs/seaweedfs/weed/pb/mq_agent_pb"
"github.com/seaweedfs/seaweedfs/weed/pb/schema_pb" "github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
) )
type SubscribeOption struct { type SubscribeOption struct {
@ -20,14 +20,13 @@ type SubscribeOption struct {
} }
type SubscribeSession struct { type SubscribeSession struct {
Option *SubscribeOption
stream grpc.BidiStreamingClient[mq_agent_pb.SubscribeRecordRequest, mq_agent_pb.SubscribeRecordResponse]
sessionId int64
Option *SubscribeOption
stream grpc.BidiStreamingClient[mq_agent_pb.SubscribeRecordRequest, mq_agent_pb.SubscribeRecordResponse]
} }
func NewSubscribeSession(agentAddress string, option *SubscribeOption) (*SubscribeSession, error) { func NewSubscribeSession(agentAddress string, option *SubscribeOption) (*SubscribeSession, error) {
// call local agent grpc server to create a new session // call local agent grpc server to create a new session
clientConn, err := pb.GrpcDial(context.Background(), agentAddress, true, grpc.WithInsecure())
clientConn, err := grpc.NewClient(agentAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil { if err != nil {
return nil, fmt.Errorf("dial agent server %s: %v", agentAddress, err) return nil, fmt.Errorf("dial agent server %s: %v", agentAddress, err)
} }
@ -55,10 +54,15 @@ func NewSubscribeSession(agentAddress string, option *SubscribeOption) (*Subscri
return nil, fmt.Errorf("subscribe record: %v", err) return nil, fmt.Errorf("subscribe record: %v", err)
} }
if err = stream.Send(&mq_agent_pb.SubscribeRecordRequest{
SessionId: resp.SessionId,
}); err != nil {
return nil, fmt.Errorf("send session id: %v", err)
}
return &SubscribeSession{ return &SubscribeSession{
Option: option,
stream: stream,
sessionId: resp.SessionId,
Option: option,
stream: stream,
}, nil }, nil
} }

Loading…
Cancel
Save