seaweedfs/weed/mq/client/pub_client/publish.go
chrislu 7003ce7425 publisher is able to fully send data and receive acks
still needs to close the pipes cleanly
2024-03-20 12:25:40 -07:00

27 lines
631 B
Go

package pub_client
import (
"fmt"
"github.com/seaweedfs/seaweedfs/weed/mq/pub_balancer"
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
"github.com/seaweedfs/seaweedfs/weed/util"
"time"
)
func (p *TopicPublisher) Publish(key, value []byte) error {
hashKey := util.HashToInt32(key) % pub_balancer.MaxPartitionCount
if hashKey < 0 {
hashKey = -hashKey
}
inputBuffer, found := p.partition2Buffer.Floor(hashKey+1, hashKey+1)
if !found {
return fmt.Errorf("no input buffer found for key %d", hashKey)
}
return inputBuffer.Enqueue(&mq_pb.DataMessage{
Key: key,
Value: value,
TsNs: time.Now().UnixNano(),
})
}