mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
server side send response at least once per second
This commit is contained in:
parent
984b6c54cf
commit
875f562779
|
@ -7,6 +7,7 @@ import (
|
||||||
"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"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
|
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -99,20 +100,37 @@ func (broker *MessageQueueBroker) Publish(stream mq_pb.SeaweedMessaging_PublishS
|
||||||
|
|
||||||
ackCounter := 0
|
ackCounter := 0
|
||||||
var ackSequence int64
|
var ackSequence int64
|
||||||
|
var isStopping int32
|
||||||
respChan := make(chan *mq_pb.PublishResponse, 128)
|
respChan := make(chan *mq_pb.PublishResponse, 128)
|
||||||
defer close(respChan)
|
defer func() {
|
||||||
|
atomic.StoreInt32(&isStopping, 1)
|
||||||
|
response := &mq_pb.PublishResponse{
|
||||||
|
Error: "end of stream",
|
||||||
|
}
|
||||||
|
respChan <- response
|
||||||
|
close(respChan)
|
||||||
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
|
ticker := time.NewTicker(1 * time.Second)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case resp := <-respChan:
|
case resp := <-respChan:
|
||||||
if err := stream.Send(resp); err != nil {
|
if resp != nil {
|
||||||
glog.Errorf("Error sending setup response: %v", err)
|
if err := stream.Send(resp); err != nil {
|
||||||
|
glog.Errorf("Error sending setup response: %v", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
case <-time.After(1 * time.Second):
|
case <-ticker.C:
|
||||||
response := &mq_pb.PublishResponse{
|
if atomic.LoadInt32(&isStopping) == 0 {
|
||||||
AckSequence: ackSequence,
|
response := &mq_pb.PublishResponse{
|
||||||
|
AckSequence: ackSequence,
|
||||||
|
}
|
||||||
|
respChan <- response
|
||||||
|
} else {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
respChan <- response
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in a new issue