当前位置: 首页>>代码示例>>Java>>正文


Java DefaultCamelContext.addComponent方法代码示例

本文整理汇总了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();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:LoanBrokerQueueTest.java

示例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));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:QuickfixjComponentTest.java

示例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);

}
 
开发者ID:HydAu,项目名称:Camel,代码行数:70,代码来源:JmsReconnectTest.java

示例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");
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:70,代码来源:TradeExecutorExample.java


注:本文中的org.apache.camel.impl.DefaultCamelContext.addComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。