You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Sean K <sk...@gmail.com> on 2012/08/08 23:14:21 UTC

pollInterval for custom Component

I am new to Apache Camel.   So please excuse the novice question.

I am building a testing framework to see how much a single router can
put message into the queue.

I have a basic camel-context.xml where the router is injected.

  <bean id="myRouter" class="com.foofoo.camel.jms.MyProducer">
  </bean>


	<camelContext xmlns="http://camel.apache.org/schema/spring">
		<routeBuilder ref="myRouter"/>
	</camelContext>



And in the router, I am using the Class Component URI combination.
(based on this doc:
https://cwiki.apache.org/confluence/display/CAMEL/Components )

@Component
public class MyProducer extends RouteBuilder{
	private String endpoint =
"class:com.foofoo.camel.jms.SimulateProducer?method=getMessage";
	@Override
	public void configure() throws Exception {
		this.from(endpoint).
		process(new Processor() {
			public void process(Exchange exchange) throws Exception {
				System.out.println("We just downloaded: "
						+ exchange.getIn().getHeader("CamelFileName"));
			}
		}).to("jms:queue:incomingOrders");

	}


public class SimulateProducer {
	 private final static Logger LOGGER =
Logger.getLogger(SimulateProducer.class .getName());

	public String getMessage() {
		StringBuilder msg = new StringBuilder();
		Date currentTime = new Date(System.currentTimeMillis());
		msg.append(currentTime.toString());
		LOGGER.debug(msg.toString());
		return msg.toString();
	}
}


However, I notice that just like when I used an endpoint like http:,
it was doing the http get quite frequently.

I think I saw how I can control the pollInterval for HttpComponents,
but how do I control it on a POJO Component?

Re: pollInterval for custom Component

Posted by Henryk Konsek <he...@gmail.com>.
Hi Sean,

> I think I saw how I can control the pollInterval for HttpComponents,
> but how do I control it on a POJO Component?

You can create custom Pooling consumer by extending the
ScheduledPollConsumer [1] class. In such case you can override poll()
method in your custom consumer to provide the batch of messages that
should be periodically passed to the route. You can configure at the
endpoint configuration level, how often ScheduledPollConsumer-based
class should fetch the data.

> I am building a testing framework to see how much a single router can
> put message into the queue.

Actually I would prefer to implement your scenario by creating
JMeter[2] load test sending the messages to the endpoint exposed at
the route. I would not use custom component for that purpose.

Regards.

[1] http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/impl/ScheduledPollConsumer.html
[2] http://jmeter.apache.org

-- 
Henryk Konsek
http://henryk-konsek.blogspot.com