本文整理匯總了Java中org.apache.camel.impl.DefaultCamelContext.addComponent方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultCamelContext.addComponent方法的具體用法?Java DefaultCamelContext.addComponent怎麽用?Java DefaultCamelContext.addComponent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.camel.impl.DefaultCamelContext
的用法示例。
在下文中一共展示了DefaultCamelContext.addComponent方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: startServices
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
@Before
public void startServices() throws Exception {
deleteDirectory("activemq-data");
camelContext = new DefaultCamelContext();
broker = new JmsBroker("vm://localhost");
broker.start();
// Set up the ActiveMQ JMS Components
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost");
// Note we can explicitly name the component
camelContext.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
camelContext.addRoutes(new LoanBrokerRoute());
template = camelContext.createProducerTemplate();
camelContext.start();
}
示例2: setUpComponent
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
private void setUpComponent(boolean injectQfjPlugins) throws IOException, MalformedURLException, NoSuchMethodException {
camelContext = new DefaultCamelContext();
component = new QuickfixjComponent();
component.setCamelContext(camelContext);
camelContext.addComponent("quickfix", component);
if (injectQfjPlugins) {
engineMessageFactory = new DefaultMessageFactory();
engineMessageStoreFactory = new MemoryStoreFactory();
engineLogFactory = new ScreenLogFactory();
component.setMessageFactory(engineMessageFactory);
component.setMessageStoreFactory(engineMessageStoreFactory);
component.setLogFactory(engineLogFactory);
}
assertThat(component.getEngines().size(), is(0));
Method converterMethod = QuickfixjConverters.class.getMethod("toSessionID", new Class<?>[] {String.class});
camelContext.getTypeConverterRegistry().addTypeConverter(SessionID.class, String.class, new StaticMethodTypeConverter(converterMethod, false));
}
示例3: testRequestReply
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
/**
* This test is disabled as the problem can currently not be reproduced using ActiveMQ.
* TODO Find a way to recreate the problem with ActiveMQ and fully automate the test
* @throws Exception
*/
@Ignore
@Test
public void testRequestReply() throws Exception {
BrokerService broker = new BrokerService();
broker.addConnector("tcp://localhost:61616");
broker.setPersistent(false);
broker.setTimeBeforePurgeTempDestinations(1000);
broker.start();
DefaultCamelContext context = new DefaultCamelContext();
JmsComponent jmsComponent = new JmsComponent();
/**
*
*/
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connectionFactory.setBrokerURL("failover://(tcp://localhost:61616)?maxReconnectAttempts=1");
/**
* When using Tibco EMS the problem can be recreated. As the broker is
* external it has to be stopped and started by hand.
*/
// TibjmsConnectionFactory connectionFactory = new TibjmsConnectionFactory();
// connectionFactory.setReconnAttemptCount(1);
jmsComponent.setConnectionFactory(connectionFactory);
jmsComponent.setRequestTimeout(1000);
jmsComponent.setReceiveTimeout(1000);
context.addComponent("jms", jmsComponent);
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("jms:testqueue").bean(new EchoServiceImpl());
from("direct:test").to("jms:testqueue");
}
});
CamelBeanPostProcessor processor = new CamelBeanPostProcessor();
processor.setCamelContext(context);
processor.postProcessBeforeInitialization(this, "this");
context.start();
String ret = proxy.echo("test");
Assert.assertEquals("test", ret);
broker.stop();
/**
* Wait long enough for the jms client to do a full reconnect. In the
* Tibco EMS case this means that a Temporary Destination created before
* is invalid now
*/
Thread.sleep(5000);
System.in.read();
broker.start(true);
/**
* Before the fix to this issue this call will throw a spring UncategorizedJmsException
* which contains an InvalidJmsDestination
*/
String ret2 = proxy.echo("test");
Assert.assertEquals("test", ret2);
}
示例4: sendMessage
import org.apache.camel.impl.DefaultCamelContext; //導入方法依賴的package包/類
public void sendMessage() throws Exception {
DefaultCamelContext context = new DefaultCamelContext();
context.addComponent("trade-executor", new TradeExecutorComponent());
final CountDownLatch logonLatch = new CountDownLatch(2);
final CountDownLatch executionReportLatch = new CountDownLatch(2);
RouteBuilder routes = new RouteBuilder() {
@Override
public void configure() throws Exception {
// Release latch when session logon events are received
from("quickfix:examples/inprocess.cfg").
filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.SessionLogon)).
bean(new CountDownLatchDecrementer("logon", logonLatch));
from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:MARKET->TRADER").
filter(header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived)).
to("trade-executor:market");
from("trade-executor:market").to("quickfix:examples/inprocess.cfg");
// Logger app messages as JSON
from("quickfix:examples/inprocess.cfg").
filter(PredicateBuilder.or(
header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived),
header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageSent))).
bean(new QuickfixjMessageJsonPrinter());
// Release latch when trader receives execution report
from("quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET").
filter(PredicateBuilder.and(
header(QuickfixjEndpoint.EVENT_CATEGORY_KEY).isEqualTo(QuickfixjEventCategory.AppMessageReceived),
header(QuickfixjEndpoint.MESSAGE_TYPE_KEY).isEqualTo(MsgType.EXECUTION_REPORT))).
bean(new CountDownLatchDecrementer("execution report", executionReportLatch));
}
};
context.addRoutes(routes);
LOG.info("Starting Camel context");
context.start();
// This is not strictly necessary, but it prevents the need for session
// synchronization due to app messages being sent before being logged on
if (!logonLatch.await(5, TimeUnit.SECONDS)) {
throw new IllegalStateException("Logon did not complete");
}
String gatewayUri = "quickfix:examples/inprocess.cfg?sessionID=FIX.4.2:TRADER->MARKET";
Endpoint gatewayEndpoint = context.getEndpoint(gatewayUri);
Producer producer = gatewayEndpoint.createProducer();
LOG.info("Sending order");
NewOrderSingle order = createNewOrderMessage();
Exchange exchange = producer.createExchange(ExchangePattern.InOnly);
exchange.getIn().setBody(order);
producer.process(exchange);
if (!executionReportLatch.await(5, TimeUnit.SECONDS)) {
throw new IllegalStateException("Did not receive execution reports");
}
LOG.info("Message received, shutting down Camel context");
context.stop();
LOG.info("Order execution example complete");
}