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.

43 lines
914 B

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