You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by balavino <ba...@gmail.com> on 2015/06/25 15:58:41 UTC
Camel - Binding a bean method with paramete of camel exchange
Hi,
I need to bind and call a bean method with some parameters - 1: a string 2:
a exchange. I see from camel page #http://camel.apache.org/bean-binding.html
that exchange binding as parameter is possible.
I'm using bean expression to do it.
In the code, i need to know the correct way of using (in the bolded line).
I'm here trying to set the throttle value of a camel route via some logic i
have to build in the binding method call.
/configure() method of a camel processor
-----------------------------------------------
@Override
public final void configure() throws Exception {
System.out.println("Exchange from Processor: " + e);
String queueName = toUri.split(":")[2];
String throttleValue =
*"${bean:queueCounter?method=getQueueSize("+queueName+",${"+e+"})}";*
from(fromUri).routeId(routeId)
.routePolicyRef("haRoutePolicy")
.throttle(simple(throttleValue))
.timePeriodMillis(timeInterval)
.setHeader("HostId", simple(hostName))
.process(new MessageProcessor())
.log("Started Polling the Source Directory for Files.")
.to(toUri);
}
Method that i need to bind
-------------------------------
ublic class QueueSizeCounter {
private ActiveMQComponent activemqComponent;
private Session session;
public Long getQueueSize(String queueName, Exchange e) throws
JMSException {
activemqComponent = (ActiveMQComponent) e.getContext()
.getComponent("activemq");
Connection connection1 =
activemqComponent.getConfiguration().getConnectionFactory().createConnection();
connection1.start();
session = connection1.createSession(false,
Session.CLIENT_ACKNOWLEDGE);
Queue replyTo = session.createTemporaryQueue();
MessageConsumer consumer = session.createConsumer(replyTo);
Queue query = session.createQueue("ActiveMQ.Statistics.Destination"
+ queueName );
MessageProducer producer = session.createProducer(query);
Message msg = session.createMessage();
msg.setJMSReplyTo(replyTo);
producer.send(msg);
MapMessage reply = (MapMessage) consumer.receive();
for (Enumeration en = reply.getMapNames();en.hasMoreElements();) {
String name = en.nextElement().toString();
System.out.println(name + "=" + reply.getObject(name));
}
return 1L;
}
}/
--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Binding-a-bean-method-with-paramete-of-camel-exchange-tp5768582.html
Sent from the Camel Development mailing list archive at Nabble.com.