@@ -404,33 +404,36 @@ func (svc *Service) SetDefaultFunctionsPipeline(transforms ...interfaces.AppFunc
404404 return nil
405405}
406406
407- // AddFunctionsPipelineForTopics adds a functions pipeline for the specified for the specified id and topics
408- func (svc * Service ) AddFunctionsPipelineForTopics (id string , topics []string , transforms ... interfaces.AppFunction ) error {
409- if len (transforms ) == 0 {
410- return errors .New ("no transforms provided to pipeline" )
411- }
407+ // getFullTopics adds the base topic prefix to all the topics in a list
408+ func getFullTopics (topics []string , baseTopicPrefix string ) ([]string , error ) {
409+ var fullTopics []string
412410
413411 if len (topics ) == 0 {
414- return errors .New ("topics for pipeline can not be empty" )
412+ return nil , errors .New ("topics for pipeline can not be empty" )
415413 }
416414
417- for _ , t := range topics {
418- if strings .TrimSpace (t ) == "" {
419- return errors .New ("blank topic not allowed" )
415+ for _ , topic := range topics {
416+ if strings .TrimSpace (topic ) == "" {
417+ return nil , errors .New ("blank topic not allowed" )
420418 }
419+ fullTopics = append (fullTopics , coreCommon .BuildTopic (baseTopicPrefix , topic ))
421420 }
421+ return fullTopics , nil
422+ }
422423
423- // Must add the base topic to all the input topics
424- var fullTopics []string
425- for _ , topic := range topics {
426- fullTopics = append ( fullTopics , coreCommon . BuildTopic ( svc . config . MessageBus . GetBaseTopicPrefix (), topic ) )
424+ // AddFunctionsPipelineForTopics adds a functions pipeline for the specified for the specified id and topics
425+ func ( svc * Service ) AddFunctionsPipelineForTopics ( id string , topics []string , transforms ... interfaces. AppFunction ) error {
426+ if len ( transforms ) == 0 {
427+ return errors . New ( "no transforms provided to pipeline" )
427428 }
428-
429- err := svc .runtime .AddFunctionsPipeline (id , fullTopics , transforms )
429+ fullTopics , err := getFullTopics (topics , svc .config .MessageBus .GetBaseTopicPrefix ())
430+ if err != nil {
431+ return err
432+ }
433+ err = svc .runtime .AddFunctionsPipeline (id , fullTopics , transforms )
430434 if err != nil {
431435 return err
432436 }
433-
434437 svc .lc .Debugf ("Pipeline '%s' added for topics '%v' with %d transform(s)" , id , fullTopics , len (transforms ))
435438 return nil
436439}
@@ -440,6 +443,16 @@ func (svc *Service) RemoveAllFunctionPipelines() {
440443 svc .runtime .RemoveAllFunctionPipelines ()
441444}
442445
446+ // SetFunctionsPipelineTopics updates the list of topics for the specified functions pipeline
447+ func (svc * Service ) SetFunctionsPipelineTopics (id string , topics []string ) error {
448+ fullTopics , err := getFullTopics (topics , svc .config .MessageBus .GetBaseTopicPrefix ())
449+ if err != nil {
450+ return err
451+ }
452+ svc .runtime .SetFunctionsPipelineTopics (id , fullTopics )
453+ return nil
454+ }
455+
443456// RequestTimeout returns the Request Timeout duration that was parsed from the Service.RequestTimeout configuration
444457func (svc * Service ) RequestTimeout () time.Duration {
445458 return svc .requestTimeout
0 commit comments