Skip to content

Commit 23ff4fd

Browse files
committed
fix(api): improve queue registration by using regex to extract queue names from processor outputs
1 parent 67738f0 commit 23ff4fd

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

core/dbio/api/api.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -272,31 +272,41 @@ func (ac *APIConnection) ReadDataflow(endpointName string, sCfg APIStreamConfig)
272272

273273
// register queues being used by endpoint
274274
{
275-
for _, processor := range endpoint.Response.Processors {
276-
if strings.HasPrefix(processor.Output, "queue.") {
277-
queueName := strings.TrimPrefix(processor.Output, "queue.")
275+
// Regex pattern to match queue references like "queue.name"
276+
queuePattern := regexp.MustCompile(`queue\.([a-zA-Z0-9_]+)`)
277+
foundQueues := make(map[string]bool) // Track unique queues
278278

279-
if !g.In(queueName, ac.Spec.Queues...) {
280-
return nil, g.Error("did not declare queue %s in queues list", queueName)
279+
// Extract queues from processor outputs
280+
for _, processor := range endpoint.Response.Processors {
281+
matches := queuePattern.FindAllStringSubmatch(processor.Output, -1)
282+
for _, match := range matches {
283+
if len(match) > 1 {
284+
queueName := match[1]
285+
foundQueues[queueName] = true
281286
}
287+
}
288+
}
282289

283-
_, err = ac.RegisterQueue(queueName)
284-
if err != nil {
285-
return nil, g.Error(err, "could not register processor output queue: %s", queueName)
290+
// Extract queues from iterate over expression
291+
if overStr := cast.ToString(endpoint.Iterate.Over); overStr != "" {
292+
matches := queuePattern.FindAllStringSubmatch(overStr, -1)
293+
for _, match := range matches {
294+
if len(match) > 1 {
295+
queueName := match[1]
296+
foundQueues[queueName] = true
286297
}
287298
}
288299
}
289300

290-
if overStr := cast.ToString(endpoint.Iterate.Over); strings.HasPrefix(overStr, "queue.") {
291-
queueName := strings.TrimPrefix(overStr, "queue.")
292-
301+
// Validate and register all found queues
302+
for queueName := range foundQueues {
293303
if !g.In(queueName, ac.Spec.Queues...) {
294304
return nil, g.Error("did not declare queue %s in queues list", queueName)
295305
}
296306

297307
_, err = ac.RegisterQueue(queueName)
298308
if err != nil {
299-
return nil, g.Error(err, "could not register iterate over queue: %s", queueName)
309+
return nil, g.Error(err, "could not register queue: %s", queueName)
300310
}
301311
}
302312
}

0 commit comments

Comments
 (0)