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()...
java concurrency spring-camel
add a comment |
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()...
java concurrency spring-camel
add a comment |
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()...
java concurrency spring-camel
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
java concurrency spring-camel
edited Nov 9 at 18:10
asked Nov 9 at 16:16
lincolnadym
369514
369514
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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