|
@ -7,10 +7,10 @@ import ( |
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/topic" |
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/topic" |
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb" |
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb" |
|
|
"google.golang.org/grpc/peer" |
|
|
"google.golang.org/grpc/peer" |
|
|
|
|
|
"io" |
|
|
"math/rand" |
|
|
"math/rand" |
|
|
"net" |
|
|
"net" |
|
|
"sync/atomic" |
|
|
"sync/atomic" |
|
|
"time" |
|
|
|
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// PUB
|
|
|
// PUB
|
|
@ -75,14 +75,17 @@ func (b *MessageQueueBroker) PublishMessage(stream mq_pb.SeaweedMessaging_Publis |
|
|
respChan := make(chan *mq_pb.PublishMessageResponse, 128) |
|
|
respChan := make(chan *mq_pb.PublishMessageResponse, 128) |
|
|
defer func() { |
|
|
defer func() { |
|
|
atomic.StoreInt32(&isStopping, 1) |
|
|
atomic.StoreInt32(&isStopping, 1) |
|
|
|
|
|
respChan <- &mq_pb.PublishMessageResponse{ |
|
|
|
|
|
AckSequence: ackSequence, |
|
|
|
|
|
} |
|
|
close(respChan) |
|
|
close(respChan) |
|
|
localTopicPartition.Publishers.RemovePublisher(clientName) |
|
|
localTopicPartition.Publishers.RemovePublisher(clientName) |
|
|
if localTopicPartition.MaybeShutdownLocalPartition() { |
|
|
if localTopicPartition.MaybeShutdownLocalPartition() { |
|
|
b.localTopicManager.RemoveTopicPartition(t, p) |
|
|
b.localTopicManager.RemoveTopicPartition(t, p) |
|
|
} |
|
|
} |
|
|
|
|
|
glog.V(0).Infof("topic %v partition %v published %d messges.", initMessage.Topic, initMessage.Partition, ackSequence) |
|
|
}() |
|
|
}() |
|
|
go func() { |
|
|
go func() { |
|
|
ticker := time.NewTicker(1 * time.Second) |
|
|
|
|
|
for { |
|
|
for { |
|
|
select { |
|
|
select { |
|
|
case resp := <-respChan: |
|
|
case resp := <-respChan: |
|
@ -93,15 +96,6 @@ func (b *MessageQueueBroker) PublishMessage(stream mq_pb.SeaweedMessaging_Publis |
|
|
} else { |
|
|
} else { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
case <-ticker.C: |
|
|
|
|
|
if atomic.LoadInt32(&isStopping) == 0 { |
|
|
|
|
|
response := &mq_pb.PublishMessageResponse{ |
|
|
|
|
|
AckSequence: ackSequence, |
|
|
|
|
|
} |
|
|
|
|
|
respChan <- response |
|
|
|
|
|
} else { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
case <-localTopicPartition.StopPublishersCh: |
|
|
case <-localTopicPartition.StopPublishersCh: |
|
|
respChan <- &mq_pb.PublishMessageResponse{ |
|
|
respChan <- &mq_pb.PublishMessageResponse{ |
|
|
AckSequence: ackSequence, |
|
|
AckSequence: ackSequence, |
|
@ -116,6 +110,10 @@ func (b *MessageQueueBroker) PublishMessage(stream mq_pb.SeaweedMessaging_Publis |
|
|
// receive a message
|
|
|
// receive a message
|
|
|
req, err := stream.Recv() |
|
|
req, err := stream.Recv() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
|
|
|
if err == io.EOF { |
|
|
|
|
|
break |
|
|
|
|
|
} |
|
|
|
|
|
glog.V(0).Infof("topic %v partition %v publish stream error: %v", initMessage.Topic, initMessage.Partition, err) |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|