Updated grpc servers to support new Manager API

This commit is contained in:
2025-09-05 07:07:33 +00:00
parent 582759bb3b
commit 40fda456eb
4 changed files with 70 additions and 29 deletions

View File

@@ -17,25 +17,39 @@ func NewGRPCStreamingServer(m *manager.Manager) *GRPCStreamingServer {
return &GRPCStreamingServer{manager: m}
}
// ConnectStream attaches a client to an existing session and streams outbound messages.
// This is server-streaming only; inbound use is optional and ignored here.
func (s *GRPCStreamingServer) ConnectStream(req *pb.ConnectStreamRequest, stream pb.DataServiceStreaming_ConnectStreamServer) error {
streamUUID, err := uuid.Parse(req.StreamUuid)
if req == nil {
return fmt.Errorf("nil request")
}
sessionID, err := uuid.Parse(req.StreamUuid)
if err != nil {
return fmt.Errorf("invalid UUID: %w", err)
}
ch, err := s.manager.ConnectClientStream(streamUUID)
if err != nil {
return fmt.Errorf("failed to connect: %w", err)
// Defaults; tune or map from req if your proto carries options.
opts := manager.ChannelOpts{
InBufSize: 256,
OutBufSize: 1024,
DropOutbound: true, // do not let slow clients stall producers
DropInbound: true, // irrelevant here (we don't send inbound), safe default
}
_, out, err := s.manager.GetChannels(sessionID, opts)
if err != nil {
return fmt.Errorf("attach channels: %w", err)
}
defer func() { _ = s.manager.DetachClient(sessionID) }()
ctx := stream.Context()
for {
select {
case <-stream.Context().Done():
s.manager.DisconnectClientStream(streamUUID)
case <-ctx.Done():
return nil
case msg, ok := <-ch:
case msg, ok := <-out:
if !ok {
return nil
return nil // session closed
}
if err := stream.Send(&pb.Message{
Identifier: &pb.Identifier{Key: msg.Identifier.Key()},