Camel - collect statistics on Concurrent Consumers of seda:// route











up vote
1
down vote

favorite












I am trying to collect runtime statistics on concurrent consumers attached to a Camel seda:// route. Each consumer uses the same Camel Processor Bean from a Spring "prototype" Bean, as I want each consumer to operate in it's own thread independently. The Camel documentation states that using seda:// and concurrent consumers will run each consumer in it's own thread. This seems to be working fine, when I run the process I can see the 4 SyncQueueProcessor threads.



To collect stats, I have a separate Spring Bean (Singleton) that I can Autowire to the Camel "prototype" Processor and then I have code in the Processor to track runtime. I'm using the the current thread id to identify each concurrent consumer Processor : I set the routeId in the @Autowired setter method of the ProcessStatistics singleton Bean : I'm thinking the setter method is called ONCE when the prototype is created.



Camel Route :



@Component
public class EnrichDocumentRoute extends RouteBuilder {

private SyncQueueProcessor syncQueueProcessor;

@Value("${data-sync.processor.concurrency: 3}")
private int concurrency;

@Override
public void configure() throws Exception {
from("seda:processQueue?concurrentConsumers=" + concurrency)
.routeId("enrichment")
.log(LoggingLevel.DEBUG, "##### Started Enrichment Process for : ${body.billingDocumentIdentifier}")
.process(this.getSyncQueueProcessor())
.log(LoggingLevel.DEBUG, "##### Finished Enrichment Process for: ${body.billingDocumentIdentifier}")
.end()
;
}

@Autowired
public void setSyncQueueProcessor(SyncQueueProcessor syncQueueProcessor) {
this.syncQueueProcessor = syncQueueProcessor;
}

public SyncQueueProcessor getSyncQueueProcessor() {
counter++;
LOG.info("getSyncQueueProcessor() - Factory sync-consumer [" + counter + "]");
//return this.syncQueueProcessorFactory.getObject("sync-consumer-"+this.counter);
//return new SyncQueueProcessor("sync-consumer-"+this.counter);
//SyncQueueProcessor lnewProcessor = new SyncQueueProcessor();
//lnewProcessor.setRouteId("sync-consumer-"+this.counter);
//return lnewProcessor;
//return new SyncQueueProcessor();
return syncQueueProcessor;
}


Camel Processor "prototype" : SyncQueueProcessor



@Component
@Scope("prototype")
@Qualifier("syncQueueProcessor")
public class SyncQueueProcessor implements Processor {

// BEAN : Spring Singleton Bean To collect statistics
private ProcessStatistics processStatistics;

// POJO : Collects the Time statistics, POJO is added to the
// Spring Singleton bean in the setter method...
private ProcessStatisticsBean processStatisticsBean;

private String routeId;

@Autowired
public void setProcessStatistics(ProcessStatistics setValue) {
this.processStatistics = setValue;
this.processStatisticsBean = new ProcessStatisticsBean ();
getProcessStatisticsBean().setRouteId("sync-consumer-" + Thread.currentThread().getId());
getProcessStatisticsBean().setEndpointId(getRouteId());
this.processStatistics.addItem(this.processStatisticsBean);
}


The issue I have is when I run the process I only see a single sync-consumer-23...I would have expected to see 4 sync-consumer-nn routes in my statistics. For the single sync-processor-nn I do see in the ProcessStatistics that Time statistics are being collected.



But why aren't the other 3 consumers appearing? I'm thinking that the "prototype" Scope would allow the setter method to be run ONCE for each Bean...hence, each is in it's own thread.



Things I tried :
- Setting the routeId at the beginning of the class...made no difference.



tia, adym



UPDATE : Well, I think I answered one question, the reason I only see 1 in the stats bean is because the setter is ONLY called ONCE... After reading this post, How to let Spring initialize "prototype" beans only when it is got through getBean()?, I'm guessing the Camel Route is what casues this...i.e. a Singleton bean (Camel Route) is causing the prototype to be initialized.



Perhaps a better question is, How can I run an initialization of a prototype bean after the thread assignment?



UPDATE : Tried using the ObjectProvider as outlined in this post...same results : Spring Java Config: how do you create a prototype-scoped @Bean with runtime arguments? . Also, other failed attempts (commented out) in the EnrichDocumentRoute.getSyncQueueProcessor()...










share|improve this question




























    up vote
    1
    down vote

    favorite












    I am trying to collect runtime statistics on concurrent consumers attached to a Camel seda:// route. Each consumer uses the same Camel Processor Bean from a Spring "prototype" Bean, as I want each consumer to operate in it's own thread independently. The Camel documentation states that using seda:// and concurrent consumers will run each consumer in it's own thread. This seems to be working fine, when I run the process I can see the 4 SyncQueueProcessor threads.



    To collect stats, I have a separate Spring Bean (Singleton) that I can Autowire to the Camel "prototype" Processor and then I have code in the Processor to track runtime. I'm using the the current thread id to identify each concurrent consumer Processor : I set the routeId in the @Autowired setter method of the ProcessStatistics singleton Bean : I'm thinking the setter method is called ONCE when the prototype is created.



    Camel Route :



    @Component
    public class EnrichDocumentRoute extends RouteBuilder {

    private SyncQueueProcessor syncQueueProcessor;

    @Value("${data-sync.processor.concurrency: 3}")
    private int concurrency;

    @Override
    public void configure() throws Exception {
    from("seda:processQueue?concurrentConsumers=" + concurrency)
    .routeId("enrichment")
    .log(LoggingLevel.DEBUG, "##### Started Enrichment Process for : ${body.billingDocumentIdentifier}")
    .process(this.getSyncQueueProcessor())
    .log(LoggingLevel.DEBUG, "##### Finished Enrichment Process for: ${body.billingDocumentIdentifier}")
    .end()
    ;
    }

    @Autowired
    public void setSyncQueueProcessor(SyncQueueProcessor syncQueueProcessor) {
    this.syncQueueProcessor = syncQueueProcessor;
    }

    public SyncQueueProcessor getSyncQueueProcessor() {
    counter++;
    LOG.info("getSyncQueueProcessor() - Factory sync-consumer [" + counter + "]");
    //return this.syncQueueProcessorFactory.getObject("sync-consumer-"+this.counter);
    //return new SyncQueueProcessor("sync-consumer-"+this.counter);
    //SyncQueueProcessor lnewProcessor = new SyncQueueProcessor();
    //lnewProcessor.setRouteId("sync-consumer-"+this.counter);
    //return lnewProcessor;
    //return new SyncQueueProcessor();
    return syncQueueProcessor;
    }


    Camel Processor "prototype" : SyncQueueProcessor



    @Component
    @Scope("prototype")
    @Qualifier("syncQueueProcessor")
    public class SyncQueueProcessor implements Processor {

    // BEAN : Spring Singleton Bean To collect statistics
    private ProcessStatistics processStatistics;

    // POJO : Collects the Time statistics, POJO is added to the
    // Spring Singleton bean in the setter method...
    private ProcessStatisticsBean processStatisticsBean;

    private String routeId;

    @Autowired
    public void setProcessStatistics(ProcessStatistics setValue) {
    this.processStatistics = setValue;
    this.processStatisticsBean = new ProcessStatisticsBean ();
    getProcessStatisticsBean().setRouteId("sync-consumer-" + Thread.currentThread().getId());
    getProcessStatisticsBean().setEndpointId(getRouteId());
    this.processStatistics.addItem(this.processStatisticsBean);
    }


    The issue I have is when I run the process I only see a single sync-consumer-23...I would have expected to see 4 sync-consumer-nn routes in my statistics. For the single sync-processor-nn I do see in the ProcessStatistics that Time statistics are being collected.



    But why aren't the other 3 consumers appearing? I'm thinking that the "prototype" Scope would allow the setter method to be run ONCE for each Bean...hence, each is in it's own thread.



    Things I tried :
    - Setting the routeId at the beginning of the class...made no difference.



    tia, adym



    UPDATE : Well, I think I answered one question, the reason I only see 1 in the stats bean is because the setter is ONLY called ONCE... After reading this post, How to let Spring initialize "prototype" beans only when it is got through getBean()?, I'm guessing the Camel Route is what casues this...i.e. a Singleton bean (Camel Route) is causing the prototype to be initialized.



    Perhaps a better question is, How can I run an initialization of a prototype bean after the thread assignment?



    UPDATE : Tried using the ObjectProvider as outlined in this post...same results : Spring Java Config: how do you create a prototype-scoped @Bean with runtime arguments? . Also, other failed attempts (commented out) in the EnrichDocumentRoute.getSyncQueueProcessor()...










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am trying to collect runtime statistics on concurrent consumers attached to a Camel seda:// route. Each consumer uses the same Camel Processor Bean from a Spring "prototype" Bean, as I want each consumer to operate in it's own thread independently. The Camel documentation states that using seda:// and concurrent consumers will run each consumer in it's own thread. This seems to be working fine, when I run the process I can see the 4 SyncQueueProcessor threads.



      To collect stats, I have a separate Spring Bean (Singleton) that I can Autowire to the Camel "prototype" Processor and then I have code in the Processor to track runtime. I'm using the the current thread id to identify each concurrent consumer Processor : I set the routeId in the @Autowired setter method of the ProcessStatistics singleton Bean : I'm thinking the setter method is called ONCE when the prototype is created.



      Camel Route :



      @Component
      public class EnrichDocumentRoute extends RouteBuilder {

      private SyncQueueProcessor syncQueueProcessor;

      @Value("${data-sync.processor.concurrency: 3}")
      private int concurrency;

      @Override
      public void configure() throws Exception {
      from("seda:processQueue?concurrentConsumers=" + concurrency)
      .routeId("enrichment")
      .log(LoggingLevel.DEBUG, "##### Started Enrichment Process for : ${body.billingDocumentIdentifier}")
      .process(this.getSyncQueueProcessor())
      .log(LoggingLevel.DEBUG, "##### Finished Enrichment Process for: ${body.billingDocumentIdentifier}")
      .end()
      ;
      }

      @Autowired
      public void setSyncQueueProcessor(SyncQueueProcessor syncQueueProcessor) {
      this.syncQueueProcessor = syncQueueProcessor;
      }

      public SyncQueueProcessor getSyncQueueProcessor() {
      counter++;
      LOG.info("getSyncQueueProcessor() - Factory sync-consumer [" + counter + "]");
      //return this.syncQueueProcessorFactory.getObject("sync-consumer-"+this.counter);
      //return new SyncQueueProcessor("sync-consumer-"+this.counter);
      //SyncQueueProcessor lnewProcessor = new SyncQueueProcessor();
      //lnewProcessor.setRouteId("sync-consumer-"+this.counter);
      //return lnewProcessor;
      //return new SyncQueueProcessor();
      return syncQueueProcessor;
      }


      Camel Processor "prototype" : SyncQueueProcessor



      @Component
      @Scope("prototype")
      @Qualifier("syncQueueProcessor")
      public class SyncQueueProcessor implements Processor {

      // BEAN : Spring Singleton Bean To collect statistics
      private ProcessStatistics processStatistics;

      // POJO : Collects the Time statistics, POJO is added to the
      // Spring Singleton bean in the setter method...
      private ProcessStatisticsBean processStatisticsBean;

      private String routeId;

      @Autowired
      public void setProcessStatistics(ProcessStatistics setValue) {
      this.processStatistics = setValue;
      this.processStatisticsBean = new ProcessStatisticsBean ();
      getProcessStatisticsBean().setRouteId("sync-consumer-" + Thread.currentThread().getId());
      getProcessStatisticsBean().setEndpointId(getRouteId());
      this.processStatistics.addItem(this.processStatisticsBean);
      }


      The issue I have is when I run the process I only see a single sync-consumer-23...I would have expected to see 4 sync-consumer-nn routes in my statistics. For the single sync-processor-nn I do see in the ProcessStatistics that Time statistics are being collected.



      But why aren't the other 3 consumers appearing? I'm thinking that the "prototype" Scope would allow the setter method to be run ONCE for each Bean...hence, each is in it's own thread.



      Things I tried :
      - Setting the routeId at the beginning of the class...made no difference.



      tia, adym



      UPDATE : Well, I think I answered one question, the reason I only see 1 in the stats bean is because the setter is ONLY called ONCE... After reading this post, How to let Spring initialize "prototype" beans only when it is got through getBean()?, I'm guessing the Camel Route is what casues this...i.e. a Singleton bean (Camel Route) is causing the prototype to be initialized.



      Perhaps a better question is, How can I run an initialization of a prototype bean after the thread assignment?



      UPDATE : Tried using the ObjectProvider as outlined in this post...same results : Spring Java Config: how do you create a prototype-scoped @Bean with runtime arguments? . Also, other failed attempts (commented out) in the EnrichDocumentRoute.getSyncQueueProcessor()...










      share|improve this question















      I am trying to collect runtime statistics on concurrent consumers attached to a Camel seda:// route. Each consumer uses the same Camel Processor Bean from a Spring "prototype" Bean, as I want each consumer to operate in it's own thread independently. The Camel documentation states that using seda:// and concurrent consumers will run each consumer in it's own thread. This seems to be working fine, when I run the process I can see the 4 SyncQueueProcessor threads.



      To collect stats, I have a separate Spring Bean (Singleton) that I can Autowire to the Camel "prototype" Processor and then I have code in the Processor to track runtime. I'm using the the current thread id to identify each concurrent consumer Processor : I set the routeId in the @Autowired setter method of the ProcessStatistics singleton Bean : I'm thinking the setter method is called ONCE when the prototype is created.



      Camel Route :



      @Component
      public class EnrichDocumentRoute extends RouteBuilder {

      private SyncQueueProcessor syncQueueProcessor;

      @Value("${data-sync.processor.concurrency: 3}")
      private int concurrency;

      @Override
      public void configure() throws Exception {
      from("seda:processQueue?concurrentConsumers=" + concurrency)
      .routeId("enrichment")
      .log(LoggingLevel.DEBUG, "##### Started Enrichment Process for : ${body.billingDocumentIdentifier}")
      .process(this.getSyncQueueProcessor())
      .log(LoggingLevel.DEBUG, "##### Finished Enrichment Process for: ${body.billingDocumentIdentifier}")
      .end()
      ;
      }

      @Autowired
      public void setSyncQueueProcessor(SyncQueueProcessor syncQueueProcessor) {
      this.syncQueueProcessor = syncQueueProcessor;
      }

      public SyncQueueProcessor getSyncQueueProcessor() {
      counter++;
      LOG.info("getSyncQueueProcessor() - Factory sync-consumer [" + counter + "]");
      //return this.syncQueueProcessorFactory.getObject("sync-consumer-"+this.counter);
      //return new SyncQueueProcessor("sync-consumer-"+this.counter);
      //SyncQueueProcessor lnewProcessor = new SyncQueueProcessor();
      //lnewProcessor.setRouteId("sync-consumer-"+this.counter);
      //return lnewProcessor;
      //return new SyncQueueProcessor();
      return syncQueueProcessor;
      }


      Camel Processor "prototype" : SyncQueueProcessor



      @Component
      @Scope("prototype")
      @Qualifier("syncQueueProcessor")
      public class SyncQueueProcessor implements Processor {

      // BEAN : Spring Singleton Bean To collect statistics
      private ProcessStatistics processStatistics;

      // POJO : Collects the Time statistics, POJO is added to the
      // Spring Singleton bean in the setter method...
      private ProcessStatisticsBean processStatisticsBean;

      private String routeId;

      @Autowired
      public void setProcessStatistics(ProcessStatistics setValue) {
      this.processStatistics = setValue;
      this.processStatisticsBean = new ProcessStatisticsBean ();
      getProcessStatisticsBean().setRouteId("sync-consumer-" + Thread.currentThread().getId());
      getProcessStatisticsBean().setEndpointId(getRouteId());
      this.processStatistics.addItem(this.processStatisticsBean);
      }


      The issue I have is when I run the process I only see a single sync-consumer-23...I would have expected to see 4 sync-consumer-nn routes in my statistics. For the single sync-processor-nn I do see in the ProcessStatistics that Time statistics are being collected.



      But why aren't the other 3 consumers appearing? I'm thinking that the "prototype" Scope would allow the setter method to be run ONCE for each Bean...hence, each is in it's own thread.



      Things I tried :
      - Setting the routeId at the beginning of the class...made no difference.



      tia, adym



      UPDATE : Well, I think I answered one question, the reason I only see 1 in the stats bean is because the setter is ONLY called ONCE... After reading this post, How to let Spring initialize "prototype" beans only when it is got through getBean()?, I'm guessing the Camel Route is what casues this...i.e. a Singleton bean (Camel Route) is causing the prototype to be initialized.



      Perhaps a better question is, How can I run an initialization of a prototype bean after the thread assignment?



      UPDATE : Tried using the ObjectProvider as outlined in this post...same results : Spring Java Config: how do you create a prototype-scoped @Bean with runtime arguments? . Also, other failed attempts (commented out) in the EnrichDocumentRoute.getSyncQueueProcessor()...







      java concurrency spring-camel






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 18:10

























      asked Nov 9 at 16:16









      lincolnadym

      369514




      369514





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229462%2fcamel-collect-statistics-on-concurrent-consumers-of-seda-route%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229462%2fcamel-collect-statistics-on-concurrent-consumers-of-seda-route%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Schultheiß

          Liste der Kulturdenkmale in Wilsdruff

          Android Play Services Check