org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder Java Examples

The following examples show how to use org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmqpSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test
public void testSinkUsingIntegerUsingNonAnonymousSender() {
    String topic = UUID.randomUUID().toString();
    AtomicInteger expected = new AtomicInteger(0);
    usage.consumeIntegers(topic,
            v -> expected.getAndIncrement());

    SubscriberBuilder<? extends Message<?>, Void> sink = createProviderAndNonAnonymousSink(topic);
    //noinspection unchecked
    Multi.createFrom().range(0, 10)
            .map(Message::of)
            .subscribe((Subscriber<? super Message<Integer>>) sink.build());

    await().until(() -> expected.get() == 10);
    assertThat(expected).hasValue(10);
}
 
Example #2
Source File: EventBusSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testSinkUsingString() {
    String topic = UUID.randomUUID().toString();
    AtomicInteger expected = new AtomicInteger(0);
    usage.consumeStrings(topic, 10, 10, TimeUnit.SECONDS,
            v -> expected.getAndIncrement());

    Map<String, Object> config = new HashMap<>();
    config.put("address", topic);
    EventBusSink sink = new EventBusSink(vertx,
            new VertxEventBusConnectorOutgoingConfiguration(new MapBasedConfig(config)));

    SubscriberBuilder<? extends Message<?>, Void> subscriber = sink.sink();
    Multi.createFrom().range(0, 10)
            .map(i -> Integer.toString(i))
            .map(Message::of)
            .subscribe((Subscriber<Message<?>>) subscriber.build());
    await().untilAtomic(expected, is(10));
    assertThat(expected).hasValue(10);
}
 
Example #3
Source File: EventBusSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testSinkUsingInteger() {
    String topic = UUID.randomUUID().toString();
    AtomicInteger expected = new AtomicInteger(0);
    usage.consumeIntegers(topic, 10, 10, TimeUnit.SECONDS,
            v -> expected.getAndIncrement());

    Map<String, Object> config = new HashMap<>();
    config.put("address", topic);
    EventBusSink sink = new EventBusSink(vertx,
            new VertxEventBusConnectorOutgoingConfiguration(new MapBasedConfig(config)));

    SubscriberBuilder<? extends Message<?>, Void> subscriber = sink.sink();
    Multi.createFrom().range(0, 10)
            .map(v -> (Message<?>) Message.of(v))
            .subscribe((Subscriber<Message<?>>) subscriber.build());

    await().untilAtomic(expected, is(10));
    assertThat(expected).hasValue(10);
}
 
Example #4
Source File: EventBusSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testCodec() {
    String topic = UUID.randomUUID().toString();

    List<Person> persons = new ArrayList<>();
    vertx.eventBus().<Person> consumer(topic, m -> persons.add(m.body()));

    vertx.eventBus().getDelegate().registerCodec(new PersonCodec());

    Map<String, Object> config = new HashMap<>();
    config.put("address", topic);
    config.put("codec", "PersonCodec");
    EventBusSink sink = new EventBusSink(vertx,
            new VertxEventBusConnectorOutgoingConfiguration(new MapBasedConfig(config)));

    SubscriberBuilder<? extends Message<?>, Void> subscriber = sink.sink();
    Multi.createFrom().range(0, 10)
            .map(i -> new Person().setName("name").setAge(i))
            .map(Message::of)
            .subscribe((Subscriber<Message<?>>) subscriber.build());

    await().until(() -> persons.size() == 10);
    assertThat(persons.size()).isEqualTo(10);
}
 
Example #5
Source File: CamelConnector.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Override
public SubscriberBuilder<? extends Message<?>, Void> getSubscriberBuilder(Config config) {
    String name = new CamelConnectorOutgoingConfiguration(config).getEndpointUri();

    SubscriberBuilder<? extends Message<?>, Void> subscriber;
    if (name.startsWith(REACTIVE_STREAMS_SCHEME)) {
        // The endpoint is a reactive streams.
        name = name.substring(REACTIVE_STREAMS_SCHEME.length());
        log.creatingSubscriberFromStream(name);
        subscriber = ReactiveStreams.<Message<?>> builder()
                .map(this::createExchangeFromMessage)
                .to(reactive.streamSubscriber(name));
    } else {
        log.creatingSubscriberFromEndpoint(name);
        subscriber = ReactiveStreams.<Message<?>> builder()
                .map(this::createExchangeFromMessage)
                .to(reactive.subscriber(name));
    }
    return subscriber;
}
 
Example #6
Source File: AmqpSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
private SubscriberBuilder<? extends Message<?>, Void> createProviderAndNonAnonymousSink(String topic) {
    Map<String, Object> config = new HashMap<>();
    config.put(ConnectorFactory.CHANNEL_NAME_ATTRIBUTE, topic);
    config.put("address", topic);
    config.put("name", "the name");
    config.put("host", host);
    config.put("durable", false);
    config.put("port", port);
    config.put("use-anonymous-sender", false);
    config.put("username", "artemis");
    config.put("password", new String("simetraehcapa".getBytes()));

    this.provider = new AmqpConnector();
    provider.setup(executionHolder);
    return this.provider.getSubscriberBuilder(new MapBasedConfig(config));
}
 
Example #7
Source File: AmqpSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test
public void testSinkUsingInteger() {
    String topic = UUID.randomUUID().toString();
    AtomicInteger expected = new AtomicInteger(0);
    usage.consumeIntegers(topic,
            v -> expected.getAndIncrement());

    SubscriberBuilder<? extends Message<?>, Void> sink = createProviderAndSink(topic);
    //noinspection unchecked
    Multi.createFrom().range(0, 10)
            .map(Message::of)
            .subscribe((Subscriber<? super Message<Integer>>) sink.build());

    await().until(() -> expected.get() == 10);
    assertThat(expected).hasValue(10);
}
 
Example #8
Source File: AmqpSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreditBasedFlowControl() {
    String topic = UUID.randomUUID().toString();
    AtomicInteger expected = new AtomicInteger(0);
    usage.consumeIntegers(topic,
            v -> expected.getAndIncrement());

    SubscriberBuilder<? extends Message<?>, Void> sink = createProviderAndSink(topic);
    //noinspection unchecked
    Multi.createFrom().range(0, 5000)
            .map(Message::of)
            .subscribe((Subscriber<? super Message<Integer>>) sink.build());

    await().until(() -> expected.get() == 5000);
    assertThat(expected).hasValue(5000);
}
 
Example #9
Source File: ProcessorBuilderImpl.java    From microprofile-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Override
public SubscriberBuilder<T, Void> forEach(Consumer<? super R> action) {
    Objects.requireNonNull(action, "Action must not be null");
    return collect(Collector.<R, Void, Void>of(
        () -> null,
        (n, r) -> action.accept(r),
        (v1, v2) -> null,
        v -> null
    ));
}
 
Example #10
Source File: PubSubConnector.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Override
public SubscriberBuilder<? extends Message<?>, Void> getSubscriberBuilder(final Config config) {
    final PubSubConfig pubSubConfig = new PubSubConfig(projectId, getTopic(config), getCredentialPath(config),
            mockPubSubTopics, host.orElse(null), port.orElse(null));

    return ReactiveStreams.<Message<?>> builder()
            .flatMapCompletionStage(message -> CompletableFuture.supplyAsync(() -> {
                createTopic(pubSubConfig);
                return await(pubSubManager.publisher(pubSubConfig).publish(buildMessage(message)));
            }, executorService))
            .ignore();
}
 
Example #11
Source File: ReactiveStreamsFactoryImpl.java    From microprofile-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Override
public <T, R> ProcessorBuilder<T, R> coupled(SubscriberBuilder<? super T, ?> subscriber,
    PublisherBuilder<? extends R> publisher) {
    Graph sGraph = ReactiveStreamsGraphBuilder.rsBuilderToGraph(Objects.requireNonNull(subscriber,
        "Subscriber must not be null"));
    Graph pGraph = ReactiveStreamsGraphBuilder.rsBuilderToGraph(Objects.requireNonNull(publisher,
        "Publisher must not be null"));
    return new ProcessorBuilderImpl<>(new Stages.Coupled(sGraph, pGraph), null);
}
 
Example #12
Source File: AwsSnsTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
private SubscriberBuilder<? extends Message<?>, Void> createSinkSubscriber(String topic) {
    Map<String, Object> config = new HashMap<>();
    config.put("connector", SnsConnector.CONNECTOR_NAME);
    config.put("topic", topic.concat("-transformed"));
    config.put("sns-url", String.format("http://%s:%d", ip(), port()));
    SnsConnector snsConnector = new SnsConnector();
    snsConnector.setup(executionHolder);
    snsConnector.initConnector();
    return snsConnector.getSubscriberBuilder(new MapBasedConfig(config));
}
 
Example #13
Source File: SubscriberShapeTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void assertThatSubscriberWasPublished(SeContainer container) {
    assertThat(registry(container).getOutgoingNames()).contains("subscriber");
    List<SubscriberBuilder<? extends Message<?>, Void>> subscriber = registry(container).getSubscribers("subscriber");
    assertThat(subscriber).isNotEmpty();
    List<String> list = new ArrayList<>();
    Multi.createFrom().items("a", "b", "c").map(Message::of)
            .onItem().invoke(m -> list.add(m.getPayload()))
            .subscribe(((SubscriberBuilder<Message<?>, Void>) subscriber.get(0)).build());
    assertThat(list).containsExactly("a", "b", "c");
}
 
Example #14
Source File: MyDummyConnector.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Override
public SubscriberBuilder<? extends Message<?>, Void> getSubscriberBuilder(Config config) {
    this.configs.add(config);
    return ReactiveStreams.<Message<?>> builder()
            .peek(x -> list.add(x.getPayload().toString()))
            .onComplete(() -> completed = true)
            .ignore();
}
 
Example #15
Source File: JmsConnector.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Override
public SubscriberBuilder<? extends Message<?>, Void> getSubscriberBuilder(Config config) {
    JmsConnectorOutgoingConfiguration oc = new JmsConnectorOutgoingConfiguration(config);
    JMSContext context = createJmsContext(oc);
    contexts.add(context);
    return new JmsSink(context, oc, json, executor).getSink();
}
 
Example #16
Source File: EventBusSink.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
SubscriberBuilder<? extends Message<?>, Void> sink() {
    DeliveryOptions options = new DeliveryOptions();
    if (this.codec != null) {
        options.setCodecName(this.codec);
    }
    if (this.timeout != -1) {
        options.setSendTimeout(this.timeout);
    }

    return ReactiveStreams.<Message<?>> builder()
            .flatMapCompletionStage(msg -> {
                // TODO support getting an EventBusMessage as message.
                if (!this.publish) {
                    if (expectReply) {
                        return vertx.eventBus().request(address, msg.getPayload(), options).subscribeAsCompletionStage()
                                .thenApply(m -> msg);
                    } else {
                        vertx.eventBus().sendAndForget(address, msg.getPayload(), options);
                        return CompletableFuture.completedFuture(msg);
                    }
                } else {
                    vertx.eventBus().publish(address, msg.getPayload(), options);
                    return CompletableFuture.completedFuture(msg);
                }
            })
            .ignore();
}
 
Example #17
Source File: PubSubTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
private SubscriberBuilder<? extends Message<?>, Void> createSinkSubscriber(final String topic) {
    final MapBasedConfig config = createSourceConfig(topic, null);
    config.setValue("topic", topic);
    config.write();

    return getConnector().getSubscriberBuilder(config);
}
 
Example #18
Source File: PubSubTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void send(final String message, final String topic) {
    final SubscriberBuilder<? extends Message<?>, Void> subscriber = createSinkSubscriber(topic);
    Multi.createFrom().item(message)
            .map(Message::of)
            .subscribe((Subscriber<Message<String>>) subscriber.build());
}
 
Example #19
Source File: EventBusSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testPublish() {
    String topic = UUID.randomUUID().toString();
    AtomicInteger expected1 = new AtomicInteger(0);
    usage.consumeStrings(topic, 10, 10, TimeUnit.SECONDS,
            v -> expected1.getAndIncrement());

    AtomicInteger expected2 = new AtomicInteger(0);
    usage.consumeStrings(topic, 10, 10, TimeUnit.SECONDS,
            v -> expected2.getAndIncrement());

    Map<String, Object> config = new HashMap<>();
    config.put("address", topic);
    config.put("publish", true);
    EventBusSink sink = new EventBusSink(vertx,
            new VertxEventBusConnectorOutgoingConfiguration(new MapBasedConfig(config)));

    SubscriberBuilder<? extends Message<?>, Void> subscriber = sink.sink();
    Multi.createFrom().range(0, 10)
            .map(i -> Integer.toString(i))
            .map(Message::of)
            .subscribe((Subscriber<Message<?>>) subscriber.build());
    await().untilAtomic(expected1, is(10));
    assertThat(expected1).hasValue(10);
    assertThat(expected2).hasValue(10);
}
 
Example #20
Source File: EventBusSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testSendAndMultipleConsumers() {
    String topic = UUID.randomUUID().toString();
    AtomicInteger expected1 = new AtomicInteger(0);
    usage.consumeStrings(topic, 5, 10, TimeUnit.SECONDS,
            v -> expected1.getAndIncrement());

    AtomicInteger expected2 = new AtomicInteger(0);
    usage.consumeStrings(topic, 5, 10, TimeUnit.SECONDS,
            v -> expected2.getAndIncrement());

    Map<String, Object> config = new HashMap<>();
    config.put("address", topic);
    config.put("publish", false);
    EventBusSink sink = new EventBusSink(vertx,
            new VertxEventBusConnectorOutgoingConfiguration(new MapBasedConfig(config)));

    SubscriberBuilder<? extends Message<?>, Void> subscriber = sink.sink();
    Multi.createFrom().range(0, 10)
            .map(i -> Integer.toString(i))
            .map(Message::of)
            .subscribe((Subscriber<Message<?>>) subscriber.build());
    await().untilAtomic(expected1, is(5));
    await().untilAtomic(expected2, is(5));
    assertThat(expected1).hasValueBetween(4, 6);
    assertThat(expected2).hasValueBetween(4, 6);
}
 
Example #21
Source File: EventBusSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testExpectReply() {
    String topic = UUID.randomUUID().toString();

    List<Integer> integers = new ArrayList<>();
    AtomicReference<io.vertx.mutiny.core.eventbus.Message<Integer>> last = new AtomicReference<>();
    vertx.eventBus().<Integer> consumer(topic, m -> {
        last.set(m);
        if (m.body() < 8) {
            integers.add(m.body());
            m.replyAndForget("foo");
        }
    });

    Map<String, Object> config = new HashMap<>();
    config.put("address", topic);
    config.put("expect-reply", true);
    EventBusSink sink = new EventBusSink(vertx,
            new VertxEventBusConnectorOutgoingConfiguration(new MapBasedConfig(config)));

    SubscriberBuilder<? extends Message<?>, Void> subscriber = sink.sink();
    Multi.createFrom().range(0, 10)
            .map(Message::of)
            .subscribe((Subscriber<Message<?>>) subscriber.build());

    await().until(() -> integers.size() == 8 && last.get().body() == 8);
    last.get().replyAndForget("bar");
    await().until(() -> last.get().body() == 9);
    assertThat(last.get().body()).isEqualTo(9);
    last.get().replyAndForget("baz");
}
 
Example #22
Source File: SubscriberStageFactoryTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Test
public void create() {
    Flowable<Integer> flowable = Flowable.fromArray(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
            .subscribeOn(Schedulers.computation());

    SubscriberBuilder<Integer, Optional<Integer>> builder = ReactiveStreams.<Integer> builder().findFirst();

    Optional<Integer> optional = ReactiveStreams.fromPublisher(flowable).filter(i -> i > 5)
            .to(builder).run().toCompletableFuture().join();

    assertThat(optional).contains(6);
}
 
Example #23
Source File: AmqpSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
private SubscriberBuilder<? extends Message<?>, Void> createProviderAndSinkUsingChannelName(String topic) {
    Map<String, Object> config = new HashMap<>();
    config.put(ConnectorFactory.CHANNEL_NAME_ATTRIBUTE, topic);
    config.put("name", "the name");
    config.put("host", host);
    config.put("durable", false);
    config.put("port", port);
    config.put("username", "artemis");
    config.put("password", new String("simetraehcapa".getBytes()));

    this.provider = new AmqpConnector();
    provider.setup(executionHolder);
    return this.provider.getSubscriberBuilder(new MapBasedConfig(config));
}
 
Example #24
Source File: Operators.java    From smallrye-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
public void to() {
    //tag::to[]
    SubscriberBuilder<Integer, Optional<Integer>> subscriber
            = ReactiveStreams.<Integer>builder()
                .map(i -> i + 1)
                .findFirst();

    ReactiveStreams.of(1, 2, 3)
            .to(subscriber)
            .run()
            // Produce Optional[2]
            .thenAccept(optional ->
                    optional.ifPresent(i -> System.out.println("Result: " + i)));
    //end::to[]
}
 
Example #25
Source File: AmqpSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test
public void testSinkUsingAmqpMessage() {
    String topic = UUID.randomUUID().toString();
    AtomicInteger expected = new AtomicInteger(0);

    List<AmqpMessage<String>> messages = new ArrayList<>();
    usage.consume(topic,
            v -> {
                expected.getAndIncrement();
                v.getDelegate().accepted();
                messages.add(new AmqpMessage<>(v, null, null));
            });

    SubscriberBuilder<? extends Message<?>, Void> sink = createProviderAndSink(topic);

    //noinspection unchecked
    Multi.createFrom().range(0, 10)
            .map(v -> AmqpMessage.<String> builder()
                    .withBody(HELLO + v)
                    .withSubject("foo")
                    .build())
            .subscribe((Subscriber<? super AmqpMessage<String>>) sink.build());

    await().untilAtomic(expected, is(10));
    assertThat(expected).hasValue(10);

    messages.forEach(m -> {
        assertThat(m.getPayload()).isInstanceOf(String.class).startsWith(HELLO);
        assertThat(m.getSubject()).isEqualTo("foo");
    });
}
 
Example #26
Source File: AmqpSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test
public void testSinkUsingAmqpMessageWithNonAnonymousSender() {
    String topic = UUID.randomUUID().toString();
    AtomicInteger expected = new AtomicInteger(0);

    List<AmqpMessage<String>> messages = new ArrayList<>();
    usage.consume(topic,
            v -> {
                expected.getAndIncrement();
                v.getDelegate().accepted();
                messages.add(new AmqpMessage<>(v, null, null));
            });

    SubscriberBuilder<? extends Message<?>, Void> sink = createProviderAndNonAnonymousSink(topic);

    //noinspection unchecked
    Multi.createFrom().range(0, 10)
            .map(v -> AmqpMessage.<String> builder()
                    .withBody(HELLO + v)
                    .withSubject("foo")
                    .withAddress("unused")
                    .build())
            .subscribe((Subscriber<? super AmqpMessage<String>>) sink.build());

    await().untilAtomic(expected, is(10));
    assertThat(expected).hasValue(10);

    messages.forEach(m -> {
        assertThat(m.getPayload()).isInstanceOf(String.class).startsWith(HELLO);
        assertThat(m.getSubject()).isEqualTo("foo");
    });
}
 
Example #27
Source File: AmqpSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test
public void testSinkUsingVertxAmqpMessage() {
    String topic = UUID.randomUUID().toString();
    AtomicInteger expected = new AtomicInteger(0);

    List<AmqpMessage<String>> messages = new CopyOnWriteArrayList<>();
    usage.consume(topic,
            v -> {
                expected.getAndIncrement();
                messages.add(new AmqpMessage<>(v, null, null));
            });

    SubscriberBuilder<? extends Message<?>, Void> sink = createProviderAndSink(topic);

    //noinspection unchecked
    Multi.createFrom().range(0, 10)
            .map(v -> io.vertx.mutiny.amqp.AmqpMessage.create()
                    .withBody(HELLO + v)
                    .subject("bar")
                    .build())
            .map(Message::of)
            .subscribe((Subscriber<? super Message<io.vertx.mutiny.amqp.AmqpMessage>>) sink.build());

    await().untilAtomic(expected, is(10));
    assertThat(expected).hasValue(10);

    messages.forEach(m -> {
        assertThat(m.getPayload()).isInstanceOf(String.class).startsWith(HELLO);
        assertThat(m.getSubject()).isEqualTo("bar");
    });
}
 
Example #28
Source File: AmqpSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Test
public void testSinkUsingAmqpMessageAndChannelNameProperty() {
    String topic = UUID.randomUUID().toString();
    AtomicInteger expected = new AtomicInteger(0);

    List<AmqpMessage<String>> messages = new ArrayList<>();
    usage.consume(topic,
            v -> {
                expected.getAndIncrement();
                messages.add(new AmqpMessage<>(v, null, null));
            });

    SubscriberBuilder<? extends Message<?>, Void> sink = createProviderAndSinkUsingChannelName(topic);

    //noinspection unchecked
    Multi.createFrom().range(0, 10)
            .map(v -> AmqpMessage.<String> builder().withBody(HELLO + v).withSubject("foo").build())
            .subscribe((Subscriber<? super AmqpMessage<String>>) sink.build());

    await().untilAtomic(expected, is(10));
    assertThat(expected).hasValue(10);

    messages.forEach(m -> {
        assertThat(m.getPayload()).isInstanceOf(String.class).startsWith(HELLO);
        assertThat(m.getSubject()).isEqualTo("foo");
    });
}
 
Example #29
Source File: SubscriberStageFactoryTest.java    From smallrye-reactive-streams-operators with Apache License 2.0 5 votes vote down vote up
@Test
public void createFromContext() {
    Flowable<Integer> flowable = Flowable.fromArray(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
            .subscribeOn(Schedulers.computation());
    executeOnEventLoop(() -> {
        SubscriberBuilder<Integer, Optional<Integer>> builder = ReactiveStreams.<Integer> builder().findFirst();
        return ReactiveStreams.fromPublisher(flowable).filter(i -> i > 5)
                .to(builder).run();
    }).assertSuccess(Optional.of(6));
}
 
Example #30
Source File: AmqpSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
private SubscriberBuilder<? extends Message<?>, Void> createProviderAndSink(String topic) {
    Map<String, Object> config = new HashMap<>();
    config.put(ConnectorFactory.CHANNEL_NAME_ATTRIBUTE, topic);
    config.put("address", topic);
    config.put("name", "the name");
    config.put("host", host);
    config.put("durable", false);
    config.put("port", port);
    config.put("username", "artemis");
    config.put("password", new String("simetraehcapa".getBytes()));

    this.provider = new AmqpConnector();
    provider.setup(executionHolder);
    return this.provider.getSubscriberBuilder(new MapBasedConfig(config));
}