@@ -45,20 +45,18 @@ type GRPCBroker struct {
45
45
pbv1.UnimplementedCloudEventServiceServer
46
46
grpcServer * grpc.Server
47
47
services map [types.CloudEventsDataType ]server.Service
48
- bindAddress string
49
48
subscribers map [string ]* subscriber // registered subscribers
50
49
mu sync.RWMutex
51
50
}
52
51
53
- // NewGRPCBroker creates a new gRPC broker with the given configuration.
54
- func NewGRPCBroker (srv * grpc.Server , addr string ) server.AgentEventServer {
55
- klog .Infof ("Serving gRPC broker without TLS at %s" , addr )
52
+ // NewGRPCBroker creates a new gRPC broker with the given gRPC server.
53
+ func NewGRPCBroker (srv * grpc.Server ) server.AgentEventServer {
56
54
broker := & GRPCBroker {
57
55
grpcServer : srv ,
58
- bindAddress : addr ,
59
56
subscribers : make (map [string ]* subscriber ),
60
57
services : make (map [types.CloudEventsDataType ]server.Service ),
61
58
}
59
+ pbv1 .RegisterCloudEventServiceServer (broker .grpcServer , broker )
62
60
return broker
63
61
}
64
62
@@ -67,15 +65,14 @@ func (bkr *GRPCBroker) RegisterService(t types.CloudEventsDataType, service serv
67
65
service .RegisterHandler (bkr )
68
66
}
69
67
70
- // Start starts the gRPC broker
71
- func (bkr * GRPCBroker ) Start (ctx context.Context ) {
68
+ // Start starts the gRPC broker at the given address
69
+ func (bkr * GRPCBroker ) Start (ctx context.Context , addr string ) {
72
70
logger := klog .FromContext (ctx )
73
- logger .Info ("Starting gRPC broker" )
74
- lis , err := net .Listen ("tcp" , bkr . bindAddress )
71
+ logger .Info ("Starting gRPC broker at %s" , addr )
72
+ lis , err := net .Listen ("tcp" , addr )
75
73
if err != nil {
76
74
utilruntime .Must (fmt .Errorf ("failed to listen: %v" , err ))
77
75
}
78
- pbv1 .RegisterCloudEventServiceServer (bkr .grpcServer , bkr )
79
76
go func () {
80
77
if err := bkr .grpcServer .Serve (lis ); err != nil {
81
78
utilruntime .Must (fmt .Errorf ("failed to serve gRPC broker: %v" , err ))
@@ -87,7 +84,7 @@ func (bkr *GRPCBroker) Start(ctx context.Context) {
87
84
klog .Infof ("Shutting down gRPC broker" )
88
85
}
89
86
90
- // Publish in stub implementation for maestro agent publish resource status back to maestro server .
87
+ // Publish in stub implementation for agent publish resource status.
91
88
func (bkr * GRPCBroker ) Publish (ctx context.Context , pubReq * pbv1.PublishRequest ) (* emptypb.Empty , error ) {
92
89
logger := klog .FromContext (ctx )
93
90
// WARNING: don't use "evt, err := pb.FromProto(pubReq.Event)" to convert protobuf to cloudevent
@@ -101,7 +98,7 @@ func (bkr *GRPCBroker) Publish(ctx context.Context, pubReq *pbv1.PublishRequest)
101
98
return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("failed to parse cloud event type %s, %v" , evt .Type (), err ))
102
99
}
103
100
104
- logger .V ( 4 ). Info ("receive the event with grpc broker" , "event" , evt )
101
+ logger .Info ("receive the event with grpc broker" , "event" , evt )
105
102
106
103
// handler resync request
107
104
if eventType .Action == types .ResyncRequestAction {
@@ -145,7 +142,7 @@ func (bkr *GRPCBroker) register(
145
142
errChan : errChan ,
146
143
}
147
144
148
- klog .V ( 4 ). Infof ("register a subscriber %s (cluster name = %s)" , id , clusterName )
145
+ klog .Infof ("register a subscriber %s (cluster name = %s)" , id , clusterName )
149
146
150
147
return id , errChan
151
148
}
@@ -160,9 +157,9 @@ func (bkr *GRPCBroker) unregister(id string) {
160
157
delete (bkr .subscribers , id )
161
158
}
162
159
163
- // Subscribe in stub implementation for maestro agent subscribe resource spec from maestro server .
160
+ // Subscribe in stub implementation for agent subscribe resource spec.
164
161
// Note: It's unnecessary to send a status resync request to agent subscribers.
165
- // The work agent will continuously attempt to send status updates to the gRPC broker.
162
+ // The agent will continuously attempt to send status updates to the gRPC broker.
166
163
// If the broker is down or disconnected, the agent will resend the status once the broker is back up or reconnected.
167
164
func (bkr * GRPCBroker ) Subscribe (subReq * pbv1.SubscriptionRequest , subServer pbv1.CloudEventService_SubscribeServer ) error {
168
165
if len (subReq .ClusterName ) == 0 {
@@ -182,7 +179,7 @@ func (bkr *GRPCBroker) Subscribe(subReq *pbv1.SubscriptionRequest, subServer pbv
182
179
}
183
180
184
181
// send the cloudevent to the subscriber
185
- klog .V ( 4 ). Infof ("sending the event to spec subscribers, %s" , evt )
182
+ klog .Infof ("sending the event to spec subscribers, %s" , evt )
186
183
if err := subServer .Send (pbEvt ); err != nil {
187
184
klog .Errorf ("failed to send grpc event, %v" , err )
188
185
// Return the error without wrapping, as it includes the gRPC error code and message for further handling.
0 commit comments