當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。