Christina Lin
Now we are going to actually calculate the actual cost for the shares, create a Java bean by right click on the org.blogdemo.example under src/main/java. Select "New", "Class".
And enter "MyBean" as the name of your class.
package org.blogdemo.example;
import java.util.HashMap;
public class MyBean {
HashMap<String, Double> stockprice = new HashMap<String, Double>();
public MyBean(){stockpriceSetup();}
public TradeOrder calculateCost(TradeOrder order){
order.setCost(stockprice.get(order.getStockId())*order.getShares());
System.out.println("Helloe! :["+order.getCost()+"]");
return order;
}
private void stockpriceSetup(){
stockprice.put("ABC", 10.55);
stockprice.put("XYZ", 33.70);
stockprice.put("KUJ", 100.20);
stockprice.put("SOU", 3.50);
}
}
Register your bean by adding it to your camel context
<bean id="costAdvisor" class="org.blogdemo.example.MyBean" />
Reference the bean that does calculation in your route by removing the links between data transformation and choice
DO NOT SAVE YET !!!!
Link the new bean node in between ref:transOrder and choice nodes.
SAVE.
Log
Log
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL"
value="vm://localhost?broker.persistent=false"/>
<property name="userName" value="admin"/>
<property name="password" value="admin"/>
</bean>
Replace the File endpoint with AMQ Endpoint
file://donejson to activemq:queue:vip
Modify A-MQ dependency in POM.xml
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>5.11.0.redhat-620133</version>
</dependency>
Remove the existing
file:donejson node
See Appendix in Camel Ride 2 or 3 for testing xml files