chrislu
10 months ago
11 changed files with 1350 additions and 304 deletions
-
34weed/mq/broker/broker_grpc_pub.go
-
78weed/mq/broker/broker_grpc_pub_follow.go
-
192weed/mq/broker/broker_grpc_sub.go
-
3weed/mq/broker/broker_topic_partition_read_write.go
-
18weed/mq/topic/local_partition.go
-
1weed/mq/topic/local_topic.go
-
39weed/pb/mq.proto
-
1178weed/pb/mq_pb/mq.pb.go
-
103weed/pb/mq_pb/mq_grpc.pb.go
-
1weed/util/log_buffer/log_buffer.go
-
7weed/util/log_buffer/log_read.go
@ -0,0 +1,78 @@ |
|||
package broker |
|||
|
|||
import ( |
|||
"context" |
|||
"fmt" |
|||
"github.com/seaweedfs/seaweedfs/weed/glog" |
|||
"github.com/seaweedfs/seaweedfs/weed/pb" |
|||
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb" |
|||
"io" |
|||
"math/rand" |
|||
"time" |
|||
) |
|||
|
|||
func (b *MessageQueueBroker) PublishFollowMe(c context.Context, request *mq_pb.PublishFollowMeRequest) (*mq_pb.PublishFollowMeResponse, error){ |
|||
glog.V(0).Infof("PublishFollowMe %v", request) |
|||
go b.withBrokerClient(true, pb.ServerAddress(request.BrokerSelf), func(client mq_pb.SeaweedMessagingClient) error { |
|||
followerId := rand.Int31() |
|||
subscribeClient, err := client.FollowInMemoryMessages(context.Background(), &mq_pb.FollowInMemoryMessagesRequest{ |
|||
Message: &mq_pb.FollowInMemoryMessagesRequest_Init{ |
|||
Init: &mq_pb.FollowInMemoryMessagesRequest_InitMessage{ |
|||
ConsumerGroup: string(b.option.BrokerAddress()), |
|||
ConsumerId: fmt.Sprintf("followMe-%d", followerId), |
|||
FollowerId: followerId, |
|||
Topic: request.Topic, |
|||
PartitionOffset: &mq_pb.PartitionOffset{ |
|||
Partition: request.Partition, |
|||
StartTsNs: 0, |
|||
StartType: mq_pb.PartitionOffsetStartType_EARLIEST_IN_MEMORY, |
|||
}, |
|||
}, |
|||
}, |
|||
}) |
|||
if err != nil { |
|||
glog.Errorf("FollowInMemoryMessages error: %v", err) |
|||
return err |
|||
} |
|||
|
|||
b.doFollowInMemoryMessage(context.Background(), subscribeClient) |
|||
|
|||
return nil |
|||
}) |
|||
return &mq_pb.PublishFollowMeResponse{}, nil |
|||
} |
|||
|
|||
func (b *MessageQueueBroker) doFollowInMemoryMessage(c context.Context, client mq_pb.SeaweedMessaging_FollowInMemoryMessagesClient) { |
|||
for { |
|||
resp, err := client.Recv() |
|||
if err != nil { |
|||
if err != io.EOF { |
|||
glog.V(0).Infof("doFollowInMemoryMessage error: %v", err) |
|||
} |
|||
return |
|||
} |
|||
if resp == nil { |
|||
glog.V(0).Infof("doFollowInMemoryMessage nil response") |
|||
return |
|||
} |
|||
if resp.Message != nil { |
|||
// process ctrl message or data message
|
|||
switch m:= resp.Message.(type) { |
|||
case *mq_pb.FollowInMemoryMessagesResponse_Data: |
|||
// process data message
|
|||
print("d") |
|||
case *mq_pb.FollowInMemoryMessagesResponse_Ctrl: |
|||
// process ctrl message
|
|||
if m.Ctrl.FlushedSequence > 0 { |
|||
flushTime := time.Unix(0, m.Ctrl.FlushedSequence) |
|||
glog.V(0).Infof("doFollowInMemoryMessage flushTime: %v", flushTime) |
|||
} |
|||
if m.Ctrl.FollowerChangedToId != 0 { |
|||
// follower changed
|
|||
glog.V(0).Infof("doFollowInMemoryMessage follower changed to %d", m.Ctrl.FollowerChangedToId) |
|||
return |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
1178
weed/pb/mq_pb/mq.pb.go
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue