caelum0x 77324a7b50 feat(ration): split gateway into auth/tenant-registry/card-issuance/webhook-ingestion
Phase 2 service decomposition per docs/SCALE-EXPANSION.md section 1: extracts
internal/{airwallex,bridge,card,tenant,httpserver} out of the monolithic
gateway into four independently deployable gRPC services (each own go.mod,
Dockerfile, and tests), with gateway now a thin BFF that fans out through new
cardissuanceclient/webhookeventsclient gRPC clients. gateway.proto's external
surface is unchanged — agent/tui/cli still talk to gateway exactly as before.

Verified: all 10 go.work modules build and `go test ./...` passes across
every one, including the new gateway client packages against the live split
services (via `make build && make test`).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-19 12:25:41 +03:00

50 lines
1.3 KiB
Go

// Package grpcserver implements webhook_ingestion.proto's
// WebhookIngestion service: StreamEvents subscribes a caller (in
// practice, services/gateway merging this into its own activity feed)
// to internal/eventbus's Bus.
package grpcserver
import (
webhookingestionpb "github.com/caelum0x/ration/pkg/pb/webhookingestion"
"github.com/caelum0x/ration/services/webhook-ingestion/internal/eventbus"
)
// Server implements webhookingestionpb.WebhookIngestionServer.
type Server struct {
webhookingestionpb.UnimplementedWebhookIngestionServer
bus *eventbus.Bus
}
// New constructs a Server backed by bus.
func New(bus *eventbus.Bus) *Server {
return &Server{bus: bus}
}
// StreamEvents implements webhookingestionpb.WebhookIngestionServer.
func (s *Server) StreamEvents(req *webhookingestionpb.StreamEventsRequest, stream webhookingestionpb.WebhookIngestion_StreamEventsServer) error {
ch, unsubscribe := s.bus.Subscribe(req.GetTenantId())
defer unsubscribe()
ctx := stream.Context()
for {
select {
case <-ctx.Done():
return ctx.Err()
case e, ok := <-ch:
if !ok {
return nil
}
if err := stream.Send(&webhookingestionpb.NormalizedEvent{
Id: e.ID,
TenantId: e.TenantID,
Kind: e.Kind,
Summary: e.Summary,
AtUnix: e.AtUnix,
}); err != nil {
return err
}
}
}
}