public class RotaHttpPollingNegociacoes {
public static void main(String[] args) throws Exception {
SimpleRegistry registro = new SimpleRegistry();
registro.put("mysql", criaDataSource());
CamelContext context = new DefaultCamelContext(registro);
final XStream xstream = new XStream();
xstream.alias("negociacao", Negociacao.class);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer://negociacoes?fixedRate=true&delay=1s&period=360s").
to("http4://argentumws-spring.herokuapp.com/negociacoes").
convertBodyTo(String.class).
unmarshal(new XStreamDataFormat(xstream)).
split(body()).
process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Negociacao negociacao = exchange.getIn().getBody(Negociacao.class);
exchange.setProperty("preco", negociacao.getPreco());
exchange.setProperty("quantidade", negociacao.getQuantidade());
String data = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss").format(negociacao.getData().getTime());
exchange.setProperty("data", data);
}
}).
setBody(simple("insert into negociacao(preco, quantidade, data) values (${property.preco}, ${property.quantidade}, '${property.data}')")).
log("${body}").
delay(1000).
to("jdbc:mysql");
}
});
context.start();
Thread.sleep(20000);
context.stop();
}
private static MysqlConnectionPoolDataSource criaDataSource() {
MysqlConnectionPoolDataSource mysqlDs = new MysqlConnectionPoolDataSource();
mysqlDs.setDatabaseName("camel");
mysqlDs.setServerName("localhost");
mysqlDs.setPort(3306);
mysqlDs.setUser("root");
mysqlDs.setPassword("");
return mysqlDs;
}
}
com o seguinte erro
Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1 at: >>> Split[simple{${body}} -> [process[Processor@0x7e22550a], SetBody[simple{Simple: insert into negociacao(preco, quantidade, data) values (${property.preco}, ${property.quantidade}, '${property.data}')}], Log[${body}], Delay[{1000} -> [To[jdbc:mysql]]]]] <<< in route: Route(route1)[[From[timer://negociacoes?fixedRate=true&delay... because of Failed to resolve endpoint: jdbc://mysql due to: No component found with scheme: jdbc
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1072)
at org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:196)
at org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:944)
at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:3245)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:2968)
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:172)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2799)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2795)
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2818)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2795)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2764)
at br.com.caelum.camel.RotaHttpPollingNegociacoes.main(RotaHttpPollingNegociacoes.java:53)
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: jdbc://mysql due to: No component found with scheme: jdbc
at org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:593)
at org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:79)
at
no meu pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.23</version>
</dependency>