2023-08-29 00:02:12 +08:00
|
|
|
package pub_client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-12-12 04:05:54 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/mq/pub_balancer"
|
2023-08-29 00:02:12 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (p *TopicPublisher) Publish(key, value []byte) error {
|
2023-12-12 04:05:54 +08:00
|
|
|
hashKey := util.HashToInt32(key) % pub_balancer.MaxPartitionCount
|
2023-08-29 00:02:12 +08:00
|
|
|
if hashKey < 0 {
|
|
|
|
hashKey = -hashKey
|
|
|
|
}
|
2023-09-05 12:43:30 +08:00
|
|
|
publishClient, found := p.partition2Broker.Floor(hashKey, hashKey)
|
2023-08-29 00:02:12 +08:00
|
|
|
if !found {
|
|
|
|
return fmt.Errorf("no broker found for key %d", hashKey)
|
|
|
|
}
|
2023-09-05 12:43:30 +08:00
|
|
|
p.Lock()
|
|
|
|
defer p.Unlock()
|
|
|
|
// dead lock here
|
|
|
|
//google.golang.org/grpc/internal/transport.(*writeQuota).get(flowcontrol.go:59)
|
|
|
|
//google.golang.org/grpc/internal/transport.(*http2Client).Write(http2_client.go:1047)
|
|
|
|
//google.golang.org/grpc.(*csAttempt).sendMsg(stream.go:1040)
|
|
|
|
//google.golang.org/grpc.(*clientStream).SendMsg.func2(stream.go:892)
|
|
|
|
//google.golang.org/grpc.(*clientStream).withRetry(stream.go:752)
|
|
|
|
//google.golang.org/grpc.(*clientStream).SendMsg(stream.go:894)
|
|
|
|
//github.com/seaweedfs/seaweedfs/weed/pb/mq_pb.(*seaweedMessagingPublishClient).Send(mq_grpc.pb.go:141)
|
|
|
|
//github.com/seaweedfs/seaweedfs/weed/mq/client/pub_client.(*TopicPublisher).Publish(publish.go:19)
|
2024-01-06 07:14:25 +08:00
|
|
|
if err := publishClient.Send(&mq_pb.PublishMessageRequest{
|
|
|
|
Message: &mq_pb.PublishMessageRequest_Data{
|
2023-08-29 00:02:12 +08:00
|
|
|
Data: &mq_pb.DataMessage{
|
|
|
|
Key: key,
|
|
|
|
Value: value,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}); err != nil {
|
|
|
|
return fmt.Errorf("send publish request: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|