You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB

  1. package agent
  2. import (
  3. "fmt"
  4. "github.com/seaweedfs/seaweedfs/weed/pb/mq_agent_pb"
  5. "golang.org/x/exp/slog"
  6. "time"
  7. )
  8. func (a *MessageQueueAgent) PublishRecordRequest(stream mq_agent_pb.SeaweedMessagingAgent_PublishRecordServer) error {
  9. m, err := stream.Recv()
  10. if err != nil {
  11. return err
  12. }
  13. a.publishersLock.RLock()
  14. publisherEntry, found := a.publishers[SessionId(m.SessionId)]
  15. a.publishersLock.RUnlock()
  16. if !found {
  17. return fmt.Errorf("session id %d not found", m.SessionId)
  18. }
  19. defer func() {
  20. if finishErr := publisherEntry.publisher.FinishPublish(); finishErr != nil {
  21. slog.Warn("failed to finish publish", "error", finishErr)
  22. }
  23. publisherEntry.lastActiveTsNs = time.Now().UnixNano()
  24. }()
  25. publisherEntry.lastActiveTsNs = 0
  26. if m.Value != nil {
  27. if err := publisherEntry.publisher.PublishRecord(m.Key, m.Value); err != nil {
  28. return err
  29. }
  30. }
  31. for {
  32. m, err := stream.Recv()
  33. if err != nil {
  34. return err
  35. }
  36. if m.Value == nil {
  37. continue
  38. }
  39. if err := publisherEntry.publisher.PublishRecord(m.Key, m.Value); err != nil {
  40. return err
  41. }
  42. }
  43. }