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


Java Endpoint.createConsumer方法代码示例

本文整理汇总了Java中org.apache.camel.Endpoint.createConsumer方法的典型用法代码示例。如果您正苦于以下问题:Java Endpoint.createConsumer方法的具体用法?Java Endpoint.createConsumer怎么用?Java Endpoint.createConsumer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.camel.Endpoint的用法示例。


在下文中一共展示了Endpoint.createConsumer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCreateDirectory

import org.apache.camel.Endpoint; //导入方法依赖的package包/类
public void testCreateDirectory() throws Exception {
    deleteDirectory("target/file/foo");

    Endpoint endpoint = context.getEndpoint("file://target/file/foo");
    Consumer consumer = endpoint.createConsumer(new Processor() {
        public void process(Exchange exchange) throws Exception {
            // noop
        }
    });

    consumer.start();
    consumer.stop();

    // the directory should now exists
    File dir = new File("target/file/foo");
    assertTrue("Directory should be created", dir.exists());
    assertTrue("Directory should be a directory", dir.isDirectory());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:FileConsumerAutoCreateDirectoryTest.java

示例2: testCreateAbsoluteDirectory

import org.apache.camel.Endpoint; //导入方法依赖的package包/类
public void testCreateAbsoluteDirectory() throws Exception {
    deleteDirectory("target/file/foo");
    // use current dir as base as absolute path
    String base = new File("").getAbsolutePath() + "/target/file/foo";

    Endpoint endpoint = context.getEndpoint("file://" + base);
    Consumer consumer = endpoint.createConsumer(new Processor() {
        public void process(Exchange exchange) throws Exception {
            // noop
        }
    });

    consumer.start();
    consumer.stop();

    // the directory should now exists
    File dir = new File(base);
    assertTrue("Directory should be created", dir.exists());
    assertTrue("Directory should be a directory", dir.isDirectory());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:FileConsumerAutoCreateDirectoryTest.java

示例3: testDoNotCreateDirectory

import org.apache.camel.Endpoint; //导入方法依赖的package包/类
public void testDoNotCreateDirectory() throws Exception {
    deleteDirectory("target/file/foo");

    Endpoint endpoint = context.getEndpoint("file://target/file/foo?autoCreate=false");
    Consumer consumer = endpoint.createConsumer(new Processor() {
        public void process(Exchange exchange) throws Exception {
            // noop
        }
    });

    consumer.start();
    consumer.stop();

    // the directory should NOT exists
    File dir = new File("target/file/foo");
    assertFalse("Directory should NOT be created", dir.exists());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:FileConsumerAutoCreateDirectoryTest.java

示例4: testAutoCreateDirectoryWithDot

import org.apache.camel.Endpoint; //导入方法依赖的package包/类
public void testAutoCreateDirectoryWithDot() throws Exception {
    deleteDirectory("target/file/foo.bar");

    Endpoint endpoint = context.getEndpoint("file://target/file/foo.bar?autoCreate=true");
    Consumer consumer = endpoint.createConsumer(new Processor() {
        public void process(Exchange exchange) throws Exception {
            // noop
        }
    });

    consumer.start();
    consumer.stop();

    // the directory should exist
    File dir = new File("target/file/foo.bar");
    assertTrue("Directory should be created", dir.exists());
    assertTrue("Directory should be a directory", dir.isDirectory());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:FileConsumerAutoCreateDirectoryTest.java

示例5: testStartingDirectoryMustExistDirectory

import org.apache.camel.Endpoint; //导入方法依赖的package包/类
public void testStartingDirectoryMustExistDirectory() throws Exception {
    deleteDirectory("target/file/foo");

    Endpoint endpoint = context.getEndpoint("file://target/file/foo?autoCreate=false&startingDirectoryMustExist=true");
    try {
        endpoint.createConsumer(new Processor() {
            public void process(Exchange exchange) throws Exception {
                // noop
            }
        });
        fail("Should have thrown an exception");
    } catch (FileNotFoundException e) {
        assertTrue(e.getMessage().startsWith("Starting directory does not exist"));
    }

    // the directory should NOT exists
    File dir = new File("target/file/foo");
    assertFalse("Directory should NOT be created", dir.exists());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:FileConsumerAutoCreateDirectoryTest.java

示例6: testJmsHttpJms

import org.apache.camel.Endpoint; //导入方法依赖的package包/类
@Test
public void testJmsHttpJms() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.expectedBodiesReceived("Bye World");

    template.sendBody("jms:in", "Hello World");

    Endpoint endpoint = context.getEndpoint("jms:out");
    endpoint.createConsumer(new Processor() {
        public void process(Exchange exchange) throws Exception {
            assertEquals("Bye World", exchange.getIn().getBody(String.class));
        }
    });

    mock.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:JmsHttpJmsTest.java

示例7: afterPropertiesSet

import org.apache.camel.Endpoint; //导入方法依赖的package包/类
public void afterPropertiesSet() throws Exception {
    // lets bind the URI to a pojo
    notNull(uri, "uri");
    // Always resolve the camel context by using the camelContextID
    if (ObjectHelper.isNotEmpty(camelContextId)) {
        camelContext = CamelContextResolverHelper.getCamelContextWithId(applicationContext, camelContextId);
    }
    notNull(camelContext, "camelContext");
    if (serviceRef != null && getService() == null && applicationContext != null) {
        setService(applicationContext.getBean(serviceRef));
    }

    Endpoint endpoint = CamelContextHelper.getMandatoryEndpoint(camelContext, uri);
    notNull(getService(), "service");
    Object proxy = getProxyForService();

    try {
        // need to start endpoint before we create consumer
        ServiceHelper.startService(endpoint);
        consumer = endpoint.createConsumer(new BeanProcessor(proxy, camelContext));
        // add and start consumer
        camelContext.addService(consumer, true, true);
    } catch (Exception e) {
        throw new FailedToCreateConsumerException(endpoint, e);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:CamelServiceExporter.java

示例8: EndpointSubscription

import org.apache.camel.Endpoint; //导入方法依赖的package包/类
public EndpointSubscription(ExecutorService workerPool, Endpoint endpoint, final Observer<? super T> observer,
                            final Func1<Exchange, T> func) {
    this.workerPool = workerPool;
    this.endpoint = endpoint;
    this.observer = observer;

    // lets create the consumer
    Processor processor = new ProcessorToObserver<T>(func, observer);
    // must ensure the consumer is being executed in an unit of work so synchronization callbacks etc is invoked
    CamelInternalProcessor internal = new CamelInternalProcessor(processor);
    internal.addAdvice(new CamelInternalProcessor.UnitOfWorkProcessorAdvice(null));
    try {
        // need to start endpoint before we create producer
        ServiceHelper.startService(endpoint);
        this.consumer = endpoint.createConsumer(internal);
        // add as service so we ensure it gets stopped when CamelContext stops
        endpoint.getCamelContext().addService(consumer, true, true);
    } catch (Exception e) {
        observer.onError(e);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:EndpointSubscription.java

示例9: testFile

import org.apache.camel.Endpoint; //导入方法依赖的package包/类
@Test
public void testFile() throws Exception {
    context.start();

    try {
        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedBodiesReceived("Hello");

        // can not use route builder as we need to have the file created in the setup before route builder starts
        Endpoint endpoint = context.getEndpoint("stream:file?fileName=target/stream/streamfile.txt&delay=100");
        Consumer consumer = endpoint.createConsumer(new Processor() {
            public void process(Exchange exchange) throws Exception {
                template.send("mock:result", exchange);
            }
        });
        consumer.start();

        assertMockEndpointsSatisfied();

        consumer.stop();
    } finally {
        fos.close();
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:StreamFileTest.java

示例10: subscribeMethod

import org.apache.camel.Endpoint; //导入方法依赖的package包/类
public void subscribeMethod(Method method, Object bean, String beanName, String endpointUri, String endpointName, String endpointProperty) {
    // lets bind this method to a listener
    String injectionPointName = method.getName();
    Endpoint endpoint = getEndpointInjection(bean, endpointUri, endpointName, endpointProperty, injectionPointName, true);
    if (endpoint != null) {
        try {
            Processor processor = createConsumerProcessor(bean, method, endpoint);
            Consumer consumer = endpoint.createConsumer(processor);
            LOG.debug("Created processor: {} for consumer: {}", processor, consumer);
            startService(consumer, endpoint.getCamelContext(), bean, beanName);
        } catch (Exception e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:CamelPostProcessorHelper.java

示例11: bindToRegistry

import org.apache.camel.Endpoint; //导入方法依赖的package包/类
private void bindToRegistry(JndiRegistry jndi) throws Exception {
    Component comp = new DirectComponent();
    comp.setCamelContext(context);

    Endpoint slow = comp.createEndpoint("direct:somename");
    Consumer consumer = slow.createConsumer(new Processor() {
        public void process(Exchange exchange) throws Exception {
            template.send("mock:result", exchange);
        }
    });
    consumer.start();

    // bind our endpoint to the registry for ref to lookup
    jndi.bind("foo", slow);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:16,代码来源:RefComponentTest.java

示例12: testNewFileConsumer

import org.apache.camel.Endpoint; //导入方法依赖的package包/类
public void testNewFileConsumer() throws Exception {
    FileComponent comp = new FileComponent();
    comp.setCamelContext(context);

    // create a file to consume
    createDirectory("target/consumefile");
    FileOutputStream fos = new FileOutputStream(new File("target/consumefile/hello.txt"));
    try {
        fos.write("Hello World".getBytes());
    } finally {
        fos.close();
    }

    Endpoint endpoint = comp.createEndpoint("file://target/consumefile", "target/consumefile", new HashMap<String, Object>());
    Consumer consumer = endpoint.createConsumer(new Processor() {
        public void process(Exchange exchange) throws Exception {
            assertNotNull(exchange);
            String body = exchange.getIn().getBody(String.class);
            assertEquals("Hello World", body);
            latch.countDown();
        }
    });
    consumer.start();
    latch.await();

    consumer.stop();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:28,代码来源:NewFileConsumeTest.java

示例13: shouldCreateGetConsumer

import org.apache.camel.Endpoint; //导入方法依赖的package包/类
@Test
public void shouldCreateGetConsumer() throws Exception {
    // Given
    Endpoint dropboxEndpoint = context.getEndpoint("dropbox://get?accessToken={{accessToken}}&clientIdentifier={{clientIdentifier}}&remotePath=/path");

    // When
    Consumer consumer = dropboxEndpoint.createConsumer(null);

    // Then
    Assert.assertTrue(consumer instanceof DropboxScheduledPollGetConsumer);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:DropboxConsumerTest.java

示例14: componentStop

import org.apache.camel.Endpoint; //导入方法依赖的package包/类
@Test
public void componentStop() throws Exception {
    setUpComponent();

    settings.setString(sessionID, SessionFactory.SETTING_CONNECTION_TYPE, SessionFactory.INITIATOR_CONNECTION_TYPE);
    settings.setLong(sessionID, Initiator.SETTING_SOCKET_CONNECT_PORT, 1234);

    writeSettings();

    Endpoint endpoint = component.createEndpoint(getEndpointUri(settingsFile.getName(), null));
    
    final CountDownLatch latch = new CountDownLatch(1);
    
    Consumer consumer = endpoint.createConsumer(new Processor() {
        @Override
        public void process(Exchange exchange) throws Exception {
            QuickfixjEventCategory eventCategory = 
                (QuickfixjEventCategory) exchange.getIn().getHeader(QuickfixjEndpoint.EVENT_CATEGORY_KEY);
            if (eventCategory == QuickfixjEventCategory.SessionCreated) {
                latch.countDown();
            }
        }
    });
    ServiceHelper.startService(consumer);

    // Endpoint automatically starts the consumer
    assertThat(((StatefulService)consumer).isStarted(), is(true));

    // will start the component
    camelContext.start();

    assertTrue("Session not created", latch.await(5000, TimeUnit.MILLISECONDS));
    
    component.stop();
    
    assertThat(component.getEngines().get(settingsFile.getName()).isStarted(), is(false));
    // it should still be initialized (ready to start again)
    assertThat(component.getEngines().get(settingsFile.getName()).isInitialized(), is(true));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:40,代码来源:QuickfixjComponentTest.java

示例15: createConsumerFor

import org.apache.camel.Endpoint; //导入方法依赖的package包/类
private Consumer createConsumerFor(String path) throws Exception {
    Endpoint endpoint = context.getEndpoint("cmis://" + path);
    return endpoint.createConsumer(new Processor() {
        public void process(Exchange exchange) throws Exception {
            template.send("mock:result", exchange);
        }
    });
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:CMISConsumerTest.java


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