本文整理匯總了Java中org.apache.camel.CamelContext.start方法的典型用法代碼示例。如果您正苦於以下問題:Java CamelContext.start方法的具體用法?Java CamelContext.start怎麽用?Java CamelContext.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.camel.CamelContext
的用法示例。
在下文中一共展示了CamelContext.start方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: shouldMetadata
import org.apache.camel.CamelContext; //導入方法依賴的package包/類
@Test
public void shouldMetadata() throws Exception {
final CamelContext context = new DefaultCamelContext();
context.addComponent("petstore", new PetstoreComponent(PAYLOAD));
try {
context.start();
final PetstoreAdapter adapter = new PetstoreAdapter(PAYLOAD, PROPERTIES, INPUT, OUTPUT);
final ActionDefinitionEndpoint endpoint = new ActionDefinitionEndpoint(context, "petstore", adapter);
final SyndesisMetadata<?> metadata = endpoint.definition("dog-food", Collections.emptyMap());
assertThat(metadata.properties).isSameAs(PROPERTIES);
assertThat(metadata.inputSchema).isSameAs(INPUT);
assertThat(metadata.outputSchema).isSameAs(OUTPUT);
} finally {
context.stop();
}
}
示例2: camelConnectorTest
import org.apache.camel.CamelContext; //導入方法依賴的package包/類
@Test
public void camelConnectorTest() throws Exception {
BasicDataSource ds = new BasicDataSource();
ds.setUsername(properties.getProperty("sql-stored-start-connector.user"));
ds.setPassword(properties.getProperty("sql-stored-start-connector.password"));
ds.setUrl( properties.getProperty("sql-stored-start-connector.url"));
SimpleRegistry registry = new SimpleRegistry();
registry.put("dataSource", ds);
CamelContext context = new DefaultCamelContext(registry);
CountDownLatch latch = new CountDownLatch(1);
final Result result = new Result();
try {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("sql-stored-start-connector:DEMO_OUT( OUT INTEGER c)")
.process(new Processor() {
@Override
public void process(Exchange exchange)
throws Exception {
String jsonBean = (String) exchange.getIn().getBody();
result.setResult(jsonBean);
latch.countDown();
}
}).to("stream:out");
}
});
context.start();
latch.await(5l,TimeUnit.SECONDS);
Assert.assertEquals("{\"c\":60}", result.getJsonBean());
} finally {
context.stop();
}
}
示例3: testCamelProducerOverridenAction
import org.apache.camel.CamelContext; //導入方法依賴的package包/類
@Test
public void testCamelProducerOverridenAction() throws Exception {
SimpleRegistry registry = new SimpleRegistry();
Engine engine = DefaultEngine.builder().knowledgeBase("camelkb", "examples/camel/camel_producer_overridden_action.py").build();
registry.put("spongeEngine", engine);
CamelContext camel = new DefaultCamelContext(registry);
camel.addRoutes(new RouteBuilder() {
@Override
public void configure() {
// @formatter:off
from("direct:start").routeId("spongeProducer")
.to("sponge:spongeEngine");
// @formatter:on
}
});
camel.start();
try {
ProducerTemplate producerTemplate = camel.createProducerTemplate();
producerTemplate.sendBody("direct:start", "Send me to the Sponge");
await().pollDelay(2, TimeUnit.SECONDS).atMost(60, TimeUnit.SECONDS)
.until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage_camelEvent").get());
assertFalse(engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage_spongeProducer").get());
assertFalse(engine.isError());
} finally {
camel.stop();
}
}
示例4: testCamelProducer
import org.apache.camel.CamelContext; //導入方法依賴的package包/類
@Test
public void testCamelProducer() throws Exception {
SimpleRegistry registry = new SimpleRegistry();
Engine engine = DefaultEngine.builder().knowledgeBase("camelkb", "examples/camel/camel_producer.py").build();
registry.put("spongeEngine", engine);
CamelContext camel = new DefaultCamelContext(registry);
camel.addRoutes(new RouteBuilder() {
@Override
public void configure() {
// @formatter:off
from("direct:start").routeId("spongeProducer")
.to("sponge:spongeEngine");
// @formatter:on
}
});
camel.start();
try {
ProducerTemplate producerTemplate = camel.createProducerTemplate();
producerTemplate.sendBody("direct:start", "Send me to the Sponge");
await().atMost(10, TimeUnit.SECONDS)
.until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "sentCamelMessage").get());
} finally {
camel.stop();
}
}
示例5: testCamelConsumer
import org.apache.camel.CamelContext; //導入方法依賴的package包/類
@Test
public void testCamelConsumer() throws Exception {
SimpleRegistry registry = new SimpleRegistry();
Engine engine = DefaultEngine.builder().knowledgeBase("camelkb", "examples/camel/camel_consumer.py").build();
registry.put("spongeEngine", engine);
CamelContext camel = new DefaultCamelContext(registry);
camel.addRoutes(new RouteBuilder() {
@Override
public void configure() {
// @formatter:off
from("sponge:spongeEngine").routeId("spongeConsumer")
.log("${body}")
.process(exchange -> engine.getOperations().getVariable(AtomicBoolean.class, "receivedCamelMessage").set(true))
.to("stream:out");
// @formatter:on
}
});
camel.start();
try {
engine.getOperations().event("spongeEvent").set("message", "Send me to Camel").send();
await().atMost(60, TimeUnit.SECONDS)
.until(() -> engine.getOperations().getVariable(AtomicBoolean.class, "receivedCamelMessage").get());
assertFalse(engine.isError());
} finally {
camel.stop();
}
}
示例6: main
import org.apache.camel.CamelContext; //導入方法依賴的package包/類
/**
* Application entry point
* @param args application arguments
* @throws Exception
*/
public static void main(String... args) throws Exception {
JndiRegistry reg = new JndiRegistry(new JndiContext());
reg.bind("sslContextParameters",sslParameters());
CamelContext ctx = new DefaultCamelContext(reg);
ctx.addRoutes(new WebsocketRouteNoSSL());
ctx.setUseMDCLogging(true);
ctx.setTracing(true);
ctx.start();
}
示例7: main
import org.apache.camel.CamelContext; //導入方法依賴的package包/類
/**
* Application entry point
* @param args application arguments
* @throws Exception
*/
public static void main(String... args) throws Exception {
JndiRegistry reg = new JndiRegistry(new JndiContext());
reg.bind("sslContextParameters",sslParameters());
CamelContext ctx = new DefaultCamelContext(reg);
ctx.addRoutes(new WebsocketRouteNoSSL());
ctx.setUseMDCLogging(true);
ctx.setTracing(true);
ctx.start();
}
示例8: camelConnectorTest
import org.apache.camel.CamelContext; //導入方法依賴的package包/類
@Test
public void camelConnectorTest() throws Exception {
Statement stmt = connection.createStatement();
String createTable = "CREATE TABLE NAME (id INTEGER PRIMARY KEY, firstName VARCHAR(255), " +
"lastName VARCHAR(255))";
stmt.executeUpdate(createTable);
stmt.executeUpdate("INSERT INTO NAME VALUES (1, 'Joe', 'Jackson')");
stmt.executeUpdate("INSERT INTO NAME VALUES (2, 'Roger', 'Waters')");
int numberOfRecords = 2;
CamelContext context = new DefaultCamelContext();
SqlStartConnectorComponent component = new SqlStartConnectorComponent();
component.addOption("user", properties.getProperty("sql-connector.user"));
component.addOption("password", properties.getProperty("sql-connector.password"));
component.addOption("url", properties.getProperty("sql-connector.url"));
// bind the component to the camel context
context.addComponent("sql-start-connector", component);
CountDownLatch latch = new CountDownLatch(numberOfRecords);
final Result result = new Result();
try {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("sql-start-connector:SELECT * FROM NAME ORDER BY id?schedulerPeriod=31000")
.process(new Processor() {
@Override
public void process(Exchange exchange)
throws Exception {
result.add(exchange.getIn().getBody(String.class));
latch.countDown();
}
}).to("stream:out");
}
});
context.start();
latch.await(30l,TimeUnit.SECONDS);
Assert.assertEquals(numberOfRecords, result.getJsonBeans().size());
Collection<Object> values = new ArrayList<>();
for (String jsonBean: result.getJsonBeans()) {
values.addAll(JSONBeanUtil.parsePropertiesFromJSONBean(jsonBean).values());
}
Assert.assertTrue(values.contains("1"));
Assert.assertTrue(values.contains("2"));
} finally {
context.stop();
}
}
示例9: camelConnectorTest
import org.apache.camel.CamelContext; //導入方法依賴的package包/類
@Test
public void camelConnectorTest() throws Exception {
Statement stmt = connection.createStatement();
String createTable = "CREATE TABLE NAME (id INTEGER PRIMARY KEY, firstName VARCHAR(255), " +
"lastName VARCHAR(255))";
stmt.executeUpdate(createTable);
stmt.executeUpdate("INSERT INTO NAME VALUES (1, 'Joe', 'Jackson')");
stmt.executeUpdate("INSERT INTO NAME VALUES (2, 'Roger', 'Waters')");
CamelContext context = new DefaultCamelContext();
SqlConnectorComponent component = new SqlConnectorComponent();
component.addOption("user", properties.getProperty("sql-connector.user"));
component.addOption("password", properties.getProperty("sql-connector.password"));
component.addOption("url", properties.getProperty("sql-connector.url"));
// bind the component to the camel context
context.addComponent("sql-connector", component);
CountDownLatch latch = new CountDownLatch(1);
final Result result = new Result();
try {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer://myTimer?period=2000")
.to("sql-connector:SELECT * FROM NAME ORDER BY id")
.process(new Processor() {
@Override
public void process(Exchange exchange)
throws Exception {
result.setJsonBean(exchange.getIn().getBody(String.class));
latch.countDown();
}
}).to("stream:out");
}
});
context.start();
latch.await(30l,TimeUnit.SECONDS);
Properties props = JSONBeanUtil.parsePropertiesFromJSONBean(result.getJsonBean());
Assert.assertTrue(props.getProperty("ID").equals("1") || props.getProperty("ID").equals("2"));
} finally {
context.stop();
}
}
示例10: camelConnectorInputParamTest
import org.apache.camel.CamelContext; //導入方法依賴的package包/類
@Test
public void camelConnectorInputParamTest() throws Exception {
Statement stmt = connection.createStatement();
String createTable = "CREATE TABLE ALLTYPES (charType CHAR, varcharType VARCHAR(255), " +
"numericType NUMERIC, decimalType DECIMAL, smallType SMALLINT," +
"dateType DATE, timeType TIME )";
stmt.executeUpdate(createTable);
CamelContext context = new DefaultCamelContext();
SqlConnectorComponent component = new SqlConnectorComponent();
component.addOption("user", properties.getProperty("sql-connector.user"));
component.addOption("password", properties.getProperty("sql-connector.password"));
component.addOption("url", properties.getProperty("sql-connector.url"));
// bind the component to the camel context
context.addComponent("sql-connector", component);
CountDownLatch latch = new CountDownLatch(1);
final Result result = new Result();
Map<String,Object> values = new HashMap<>();
values.put("CHARVALUE", SqlSampleValue.charValue);
values.put("VARCHARVALUE", SqlSampleValue.stringValue);
values.put("NUMERICVALUE", SqlSampleValue.decimalValue);
values.put("DECIMALVALUE", SqlSampleValue.decimalValue);
values.put("SMALLINTVALUE", SqlSampleValue.integerValue);
String jsonBody = JSONBeanUtil.toJSONBean(values);
final String insertStatement = "INSERT INTO ALLTYPES "
+ "(charType, varcharType, numericType, decimalType, smallType) VALUES "
+ "(:#CHARVALUE, :#VARCHARVALUE, :#NUMERICVALUE, :#DECIMALVALUE, :#SMALLINTVALUE)";
SqlStatementParser parser = new SqlStatementParser(connection, schema, insertStatement);
parser.parse();
try {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer://myTimer?period=2000")
.setBody().constant(jsonBody)
.to("sql-connector:" + insertStatement)
.process(new Processor() {
@Override
public void process(Exchange exchange)
throws Exception {
result.setJsonBean(exchange.getIn().getBody(String.class));
latch.countDown();
}
}).to("stream:out");
}
});
context.start();
latch.await(5l,TimeUnit.SECONDS);
Properties props = JSONBeanUtil.parsePropertiesFromJSONBean(result.getJsonBean());
Assert.assertEquals(values.size(),props.size());
} finally {
context.stop();
}
}
示例11: ping
import org.apache.camel.CamelContext; //導入方法依賴的package包/類
public void ping() throws Exception {
// need to create Camel
CamelContext camel = new DefaultCamelContext();
camel.start();
// get the connector to use
Component sqlstored = camel.getComponent("sql-stored-connector");
// the connector must support ping check if its verifiable
Optional<SqlStoredConnectorVerifierExtension> vce = sqlstored.getExtension(SqlStoredConnectorVerifierExtension.class);
if (vce.isPresent()) {
ComponentVerifierExtension verifier = vce.get();
Map<String, Object> parameters = loadParameters();
ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.PARAMETERS, parameters);
System.out.println("=============================================");
System.out.println("");
System.out.println("Parameters check result: " + result.getStatus());
if (result.getStatus().equals(Result.Status.ERROR)) {
System.out.println(result.getErrors());
}
System.out.println("");
System.out.println("=============================================");
ComponentVerifierExtension.Result result2 = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters);
System.out.println("=============================================");
System.out.println("");
System.out.println("Ping check result: " + result2.getStatus());
if (result2.getStatus().equals(Result.Status.ERROR)) {
System.out.println(result2.getErrors());
}
System.out.println("");
System.out.println("=============================================");
} else {
System.out.println("Component does not support ping check");
}
camel.stop();
}
示例12: camelConnectorTest
import org.apache.camel.CamelContext; //導入方法依賴的package包/類
@Test
public void camelConnectorTest() throws Exception {
BasicDataSource ds = new BasicDataSource();
ds.setUsername(properties.getProperty("sql-stored-connector.user"));
ds.setPassword(properties.getProperty("sql-stored-connector.password"));
ds.setUrl( properties.getProperty("sql-stored-connector.url"));
SimpleRegistry registry = new SimpleRegistry();
registry.put("dataSource", ds);
CamelContext context = new DefaultCamelContext(registry);
String jsonBody = "{\"a\":20,\"b\":30}";
CountDownLatch latch = new CountDownLatch(1);
final Result result = new Result();
try {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer://myTimer?period=2000")
.setBody().constant(jsonBody)
.to("sql-stored-connector:DEMO_ADD( INTEGER ${body[a]}, INTEGER ${body[b]}, OUT INTEGER c)")
.process(new Processor() {
@Override
public void process(Exchange exchange)
throws Exception {
String jsonBean = (String) exchange.getIn().getBody();
result.setResult(jsonBean);
latch.countDown();
}
});
}
});
context.start();
latch.await(5l,TimeUnit.SECONDS);
Assert.assertEquals("{\"c\":50}", result.getJsonBean());
} finally {
context.stop();
}
}