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


Java CamelReactiveStreams类代码示例

本文整理汇总了Java中org.apache.camel.component.reactive.streams.api.CamelReactiveStreams的典型用法代码示例。如果您正苦于以下问题:Java CamelReactiveStreams类的具体用法?Java CamelReactiveStreams怎么用?Java CamelReactiveStreams使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CamelReactiveStreams类属于org.apache.camel.component.reactive.streams.api包,在下文中一共展示了CamelReactiveStreams类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testConsumerBackPressure

import org.apache.camel.component.reactive.streams.api.CamelReactiveStreams; //导入依赖的package包/类
@Test
public void testConsumerBackPressure() throws Exception {
    CamelReactiveStreamsService rsCamel = CamelReactiveStreams.get(context);

    // create an array with the messages
    String[] inbox = new String[100];
    for (int i = 0; i < 100; i++) {
        inbox[i] = "Hello " + i;
    }

    // use stream engine create a publisher
    Flowable.fromArray(inbox)
        .doOnRequest(n -> {
            // log each time we are request more data from the publisher
            log.info("Requesting {} messages", n);
        })
        .subscribe(rsCamel.streamSubscriber("inbox", String.class));

    // let it run for 10 seconds
    Thread.sleep(10 * 1000L);
}
 
开发者ID:camelinaction,项目名称:camelinaction2,代码行数:22,代码来源:CamelConsumerBackPressureTest.java

示例2: testNoBackPressure

import org.apache.camel.component.reactive.streams.api.CamelReactiveStreams; //导入依赖的package包/类
@Test
public void testNoBackPressure() throws Exception {
    CamelReactiveStreamsService rsCamel = CamelReactiveStreams.get(context);

    // create a published that receive from the inbox stream
    Publisher<String> inbox = rsCamel.fromStream("inbox", String.class);

    // use stream engine to subscribe from the publisher
    Flowable.fromPublisher(inbox)
        .doOnNext(c -> {
            log.info("Processing message {}", c);
            Thread.sleep(1000);
        })
        .subscribe();

    // send in 200 messages
    log.info("Sending 200 messages ...");
    for (int i = 0; i < 200; i++) {
        fluentTemplate.withBody("Hello " + i).to("seda:inbox?waitForTaskToComplete=Never").send();
    }
    log.info("Sent 200 messages done");

    // let it run for 250 seconds
    Thread.sleep(250 * 1000L);
}
 
开发者ID:camelinaction,项目名称:camelinaction2,代码行数:26,代码来源:CamelNoBackPressureTest.java

示例3: testInflightBackPressure

import org.apache.camel.component.reactive.streams.api.CamelReactiveStreams; //导入依赖的package包/类
@Test
public void testInflightBackPressure() throws Exception {
    CamelReactiveStreamsService rsCamel = CamelReactiveStreams.get(context);

    // create a published that receive from the inbox stream
    Publisher<String> inbox = rsCamel.fromStream("inbox", String.class);

    // use stream engine to subscribe from the publisher
    Flowable.fromPublisher(inbox)
        .doOnNext(c -> {
            log.info("Processing message {}", c);
            Thread.sleep(1000);
        })
        .subscribe();

    // send in 200 messages
    log.info("Sending 200 messages ...");
    for (int i = 0; i < 200; i++) {
        fluentTemplate.withBody("Hello " + i).to("seda:inbox?waitForTaskToComplete=Never").send();
    }
    log.info("Sent 200 messages done");

    // let it run for 250 seconds
    Thread.sleep(250 * 1000L);
}
 
开发者ID:camelinaction,项目名称:camelinaction2,代码行数:26,代码来源:CamelInflightBackPressureTest.java

示例4: testCamelFirst

import org.apache.camel.component.reactive.streams.api.CamelReactiveStreams; //导入依赖的package包/类
@Test
public void testCamelFirst() throws Exception {
    LOG.info("Starting RX-Java2 Flowable Camel first");

    // create Camel
    CamelContext camel = new DefaultCamelContext();

    // create Reative Camel
    CamelReactiveStreamsService rsCamel = CamelReactiveStreams.get(camel);

    camel.start();
    rsCamel.start();

    // create a publisher from Camel seda:words endpoint
    Publisher<String> publisher = rsCamel.from("seda:words", String.class);

    Flowable.fromPublisher(publisher)
        // upper case the word
        .map(w -> w.toUpperCase())
        // log the big number
        .doOnNext(w -> LOG.info(w))
        .subscribe();

    // send some words to Camel
    FluentProducerTemplate template = camel.createFluentProducerTemplate();

    template.withBody("Camel").to("seda:words").send();
    template.withBody("rocks").to("seda:words").send();
    template.withBody("streams").to("seda:words").send();
    template.withBody("as").to("seda:words").send();
    template.withBody("well").to("seda:words").send();

    // sleep a bit for reactive subscriber to complete
    Thread.sleep(1000);

    camel.stop();
    rsCamel.stop();
}
 
开发者ID:camelinaction,项目名称:camelinaction2,代码行数:39,代码来源:CamelFirstTest.java

示例5: testFiles

import org.apache.camel.component.reactive.streams.api.CamelReactiveStreams; //导入依赖的package包/类
@Test
public void testFiles() throws Exception {
    getMockEndpoint("mock:inbox").expectedMessageCount(4);
    getMockEndpoint("mock:camel").expectedMessageCount(2);

    CamelReactiveStreamsService rsCamel = CamelReactiveStreams.get(context);

    // use stream engine to subscribe from the publisher
    // where we filter out the big numbers which is logged
    Flowable.fromPublisher(rsCamel.from("file:target/inbox"))
        // call the direct:inbox Camel route from within this flow
        .doOnNext(e -> rsCamel.to("direct:inbox", e))
        // filter out files which has Camel in the text
        .filter(e -> e.getIn().getBody(String.class).contains("Camel"))
        // let Camel also be subscriber by the endpoint direct:camel
        .subscribe(rsCamel.subscriber("direct:camel"));

    // create some test files
    fluentTemplate.to("file:target/inbox").withBody("Hello World").withHeader(Exchange.FILE_NAME, "hello.txt").send();
    fluentTemplate.to("file:target/inbox").withBody("Hello Camel").withHeader(Exchange.FILE_NAME, "hello2.txt").send();
    fluentTemplate.to("file:target/inbox").withBody("Bye Camel").withHeader(Exchange.FILE_NAME, "bye.txt").send();
    fluentTemplate.to("file:target/inbox").withBody("Bye World").withHeader(Exchange.FILE_NAME, "bye2.txt").send();

    assertMockEndpointsSatisfied();
}
 
开发者ID:camelinaction,项目名称:camelinaction2,代码行数:26,代码来源:CamelFilesTest.java

示例6: testNumbers

import org.apache.camel.component.reactive.streams.api.CamelReactiveStreams; //导入依赖的package包/类
@Test
public void testNumbers() throws Exception {
    CamelReactiveStreamsService rsCamel = CamelReactiveStreams.get(context);

    // create a published that receive from the numbers stream
    Publisher<Integer> numbers = rsCamel.fromStream("numbers", Integer.class);

    // use stream engine to subscribe from the publisher
    // where we filter out the big numbers which is logged
    Flowable.fromPublisher(numbers)
        .filter(n -> n > 5)
        .doOnNext(c -> log.info("Streaming big number {}", c))
        .subscribe();

    // let it run for 10 seconds
    Thread.sleep(10000);
}
 
开发者ID:camelinaction,项目名称:camelinaction2,代码行数:18,代码来源:CamelNumbersTest.java

示例7: testLatestBackPressure

import org.apache.camel.component.reactive.streams.api.CamelReactiveStreams; //导入依赖的package包/类
@Test
public void testLatestBackPressure() throws Exception {
    CamelReactiveStreamsService rsCamel = CamelReactiveStreams.get(context);

    // create a published that receive from the inbox stream
    Publisher<String> inbox = rsCamel.fromStream("inbox", String.class);

    // use stream engine to subscribe from the publisher
    Flowable.fromPublisher(inbox)
        .doOnNext(c -> {
            log.info("Processing message {}", c);
            Thread.sleep(1000);
        })
        .subscribe();

    // send in 200 messages
    log.info("Sending 200 messages ...");
    for (int i = 0; i < 200; i++) {
        fluentTemplate.withBody("Hello " + i).to("seda:inbox?waitForTaskToComplete=Never").send();
    }
    log.info("Sent 200 messages done");

    // let it run for 250 seconds
    Thread.sleep(250 * 1000L);
}
 
开发者ID:camelinaction,项目名称:camelinaction2,代码行数:26,代码来源:CamelLatestBackPressureTest.java

示例8: testNumbers

import org.apache.camel.component.reactive.streams.api.CamelReactiveStreams; //导入依赖的package包/类
@Test
public void testNumbers() throws Exception {
    CamelReactiveStreamsService reactive = CamelReactiveStreams.get(context);

    // create a published that receive from the numbers stream
    Publisher<Integer> numbers = reactive.fromStream("numbers", Integer.class);

    // use stream engine to subscribe from the publisher
    // where we filter out the big numbers which is logged
    Flux.from(numbers)
        .filter(n -> n > 5)
        .doOnNext(c -> log.info("Streaming big number {}", c))
        .subscribe();

    // let it run for 10 seconds
    Thread.sleep(10000);
}
 
开发者ID:camelinaction,项目名称:camelinaction2,代码行数:18,代码来源:CamelNumbersTest.java

示例9: testFrom

import org.apache.camel.component.reactive.streams.api.CamelReactiveStreams; //导入依赖的package包/类
@Test
public void testFrom() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.start();
    try {
        CamelReactiveStreamsService crs = CamelReactiveStreams.get(camelctx);
        Publisher<Exchange> timer = crs.from("timer:reactive?period=250&repeatCount=3");

        AtomicInteger value = new AtomicInteger(0);
        CountDownLatch latch = new CountDownLatch(3);

        Flux.from(timer)
            .map(exchange -> ExchangeHelper.getHeaderOrProperty(exchange, Exchange.TIMER_COUNTER, Integer.class))
            .doOnNext(res -> Assert.assertEquals(value.incrementAndGet(), res.intValue()))
            .doOnNext(res -> latch.countDown())
            .subscribe();

        Assert.assertTrue(latch.await(2, TimeUnit.SECONDS));
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:23,代码来源:ReactorIntegrationTest.java

示例10: testToStream

import org.apache.camel.component.reactive.streams.api.CamelReactiveStreams; //导入依赖的package包/类
@Test
public void testToStream() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        public void configure() {
            from("reactive-streams:reactive")
                .setBody().constant("123");
        }
    });

    camelctx.start();
    try {
        CamelReactiveStreamsService crs = CamelReactiveStreams.get(camelctx);
        Publisher<Exchange> publisher = crs.toStream("reactive", new DefaultExchange(camelctx));
        Exchange res = Flux.from(publisher).blockFirst();

        Assert.assertNotNull(res);

        String content = res.getIn().getBody(String.class);

        Assert.assertNotNull(content);
        Assert.assertEquals("123", content);
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:27,代码来源:ReactorIntegrationTest.java

示例11: testTo

import org.apache.camel.component.reactive.streams.api.CamelReactiveStreams; //导入依赖的package包/类
@Test
public void testTo() throws Exception {
    CamelContext camelctx = createWildFlyCamelContext();
    camelctx.start();
    try {
        CamelReactiveStreamsService crs = CamelReactiveStreams.get(camelctx);

        Set<String> values = Collections.synchronizedSet(new TreeSet<>());
        CountDownLatch latch = new CountDownLatch(3);

        Flux.just(1, 2, 3)
            .flatMap(e -> crs.to("bean:hello", e, String.class))
            .doOnNext(res -> values.add(res))
            .doOnNext(res -> latch.countDown())
            .subscribe();

        Assert.assertTrue(latch.await(2, TimeUnit.SECONDS));
        Assert.assertEquals(new TreeSet<>(Arrays.asList("Hello 1", "Hello 2", "Hello 3")), values);
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:23,代码来源:ReactorIntegrationTest.java

示例12: testToWithExchange

import org.apache.camel.component.reactive.streams.api.CamelReactiveStreams; //导入依赖的package包/类
@Test
public void testToWithExchange() throws Exception {
    CamelContext camelctx = createWildFlyCamelContext();
    camelctx.start();
    try {
        CamelReactiveStreamsService crs = CamelReactiveStreams.get(camelctx);

        Set<String> values = Collections.synchronizedSet(new TreeSet<>());
        CountDownLatch latch = new CountDownLatch(3);

        Flux.just(1, 2, 3)
            .flatMap(e -> crs.to("bean:hello", e))
            .map(e -> e.getOut())
            .map(e -> e.getBody(String.class))
            .doOnNext(res -> values.add(res))
            .doOnNext(res -> latch.countDown())
            .subscribe();

        Assert.assertTrue(latch.await(2, TimeUnit.SECONDS));
        Assert.assertEquals(new TreeSet<>(Arrays.asList("Hello 1", "Hello 2", "Hello 3")), values);
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:25,代码来源:ReactorIntegrationTest.java

示例13: testToFunction

import org.apache.camel.component.reactive.streams.api.CamelReactiveStreams; //导入依赖的package包/类
@Test
public void testToFunction() throws Exception {
    CamelContext camelctx = createWildFlyCamelContext();
    camelctx.start();
    try {
        CamelReactiveStreamsService crs = CamelReactiveStreams.get(camelctx);

        /* A TreeSet will order the messages alphabetically regardless of the insertion order
         * This is important because in the Flux returned by Flux.flatMap(Function<? super T, ? extends
         * Publisher<? extends R>>) the emissions may interleave */
        Set<String> values = Collections.synchronizedSet(new TreeSet<>());
        CountDownLatch latch = new CountDownLatch(3);
        Function<Object, Publisher<String>> fun = crs.to("bean:hello", String.class);

        Flux.just(1, 2, 3)
            .flatMap(fun)
            .doOnNext(res -> values.add(res))
            .doOnNext(res -> latch.countDown())
            .subscribe();

        Assert.assertTrue(latch.await(2, TimeUnit.SECONDS));
        Assert.assertEquals(new TreeSet<>(Arrays.asList("Hello 1", "Hello 2", "Hello 3")), values);
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:27,代码来源:ReactorIntegrationTest.java

示例14: testToFunctionWithExchange

import org.apache.camel.component.reactive.streams.api.CamelReactiveStreams; //导入依赖的package包/类
@Test
public void testToFunctionWithExchange() throws Exception {
    CamelContext camelctx = createWildFlyCamelContext();
    camelctx.start();
    try {
        CamelReactiveStreamsService crs = CamelReactiveStreams.get(camelctx);
        Set<String> values = Collections.synchronizedSet(new TreeSet<>());
        CountDownLatch latch = new CountDownLatch(3);
        Function<Object, Publisher<Exchange>> fun = crs.to("bean:hello");

        Flux.just(1, 2, 3)
            .flatMap(fun)
            .map(e -> e.getOut())
            .map(e -> e.getBody(String.class))
            .doOnNext(res -> values.add(res))
            .doOnNext(res -> latch.countDown())
            .subscribe();

        Assert.assertTrue(latch.await(2, TimeUnit.SECONDS));
        Assert.assertEquals(new TreeSet<>(Arrays.asList("Hello 1", "Hello 2", "Hello 3")), values);
    } finally {
        camelctx.stop();
    }
}
 
开发者ID:wildfly-extras,项目名称:wildfly-camel,代码行数:25,代码来源:ReactorIntegrationTest.java

示例15: testConsumeNumbers

import org.apache.camel.component.reactive.streams.api.CamelReactiveStreams; //导入依赖的package包/类
@Test
public void testConsumeNumbers() throws Exception {
    CamelReactiveStreamsService rsCamel = CamelReactiveStreams.get(context);

    // use stream engine create a publisher
    // that just sends 5 numbers, which needs to be sorted
    // and then each data is send to Camel on the reactive-streams:number endpoint
    Flowable.just("3", "4", "1", "5", "2")
        .sorted(String::compareToIgnoreCase)
        .subscribe(rsCamel.streamSubscriber("numbers", String.class));

    // let it run for 2 seconds
    Thread.sleep(2000);
}
 
开发者ID:camelinaction,项目名称:camelinaction2,代码行数:15,代码来源:CamelConsumeNumbersTest.java


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