Java Code Examples for reactor.core.publisher.Flux#from()

The following examples show how to use reactor.core.publisher.Flux#from() . These examples are extracted from open source projects. 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
@Test
@Disabled // related to boot 2.1 no bean override change
public void functionRegistrar() {
	this.initializer = new AbstractSpringFunctionAdapterInitializer<Object>(FunctionRegistrar.class) {

	};
	this.initializer.initialize(null);
	Flux<?> result = Flux.from(this.initializer.apply(Flux.just(new Foo())));
	assertThat(result.blockFirst()).isInstanceOf(Bar.class);
}
 
Example 2
public static void readFile(File file) {
    try (final BufferedReader br = new BufferedReader(
            new FileReader(file))) {

        Flux<String> flow = Flux.from(new FilePublisher(br));

        flow.publishOn(Schedulers.elastic())
                .subscribeOn(Schedulers.immediate())
                .subscribe(System.out::println);

    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 3
Source Project: reactor-core   File: FluxTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void fluxFromFluxSourceDoesntCallAssemblyHook() {
	final Flux<Integer> source = Flux.range(1, 10);

	//set the hook AFTER the original operators have been invoked (since they trigger assembly themselves)
	AtomicInteger wrappedCount = new AtomicInteger();
	Hooks.onEachOperator(p -> {
		wrappedCount.incrementAndGet();
		return p;
	});

	Flux.from(source);
	Assertions.assertThat(wrappedCount).hasValue(0);
}
 
Example 4
Source Project: james-project   File: GetFilterMethod.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Flux<JmapResponse> process(JmapRequest request, MethodCallId methodCallId, MailboxSession mailboxSession) {
    Preconditions.checkNotNull(request);
    Preconditions.checkNotNull(methodCallId);
    Preconditions.checkNotNull(mailboxSession);
    Preconditions.checkArgument(request instanceof GetFilterRequest);

    GetFilterRequest filterRequest = (GetFilterRequest) request;

    return Flux.from(metricFactory.decorateSupplierWithTimerMetricLogP99(JMAP_PREFIX + METHOD_NAME.getName(),
        () -> process(methodCallId, mailboxSession, filterRequest)
            .subscriberContext(context("GET_FILTER", MDCBuilder.of(MDCBuilder.ACTION, "GET_FILTER")))));
}
 
Example 5
Source Project: tutorials   File: Server.java    License: MIT License 5 votes vote down vote up
/**
 * Handle request for bidirectional channel
 *
 * @param payloads Stream of payloads delivered from the client
 * @return
 */
@Override
public Flux<Payload> requestChannel(Publisher<Payload> payloads) {
    Flux.from(payloads)
      .subscribe(gameController::processPayload);
    Flux<Payload> channel = Flux.from(gameController);
    return channel;
}
 
Example 6
Source Project: tutorials   File: Server.java    License: MIT License 5 votes vote down vote up
/**
 * Handle Request/Stream messages. Each request returns a new stream.
 *
 * @param payload Payload that can be used to determine which stream to return
 * @return Flux stream containing simulated measurement data
 */
@Override
public Flux<Payload> requestStream(Payload payload) {
    String streamName = payload.getDataUtf8();
    if (DATA_STREAM_NAME.equals(streamName)) {
        return Flux.from(dataPublisher);
    }
    return Flux.error(new IllegalArgumentException(streamName));
}
 
Example 7
Source Project: styx   File: StyxBackendServiceClient.java    License: Apache License 2.0 5 votes vote down vote up
private Flux<LiveHttpResponse> retry(
        LiveHttpRequest request,
        RetryPolicyContext retryContext,
        List<RemoteHost> previousOrigins,
        int attempt,
        Throwable cause,
        HttpInterceptor.Context context) {
    LoadBalancer.Preferences lbContext = new LoadBalancer.Preferences() {
        @Override
        public Optional<String> preferredOrigins() {
            return Optional.empty();
        }

        @Override
        public List<Origin> avoidOrigins() {
            return previousOrigins.stream()
                    .map(RemoteHost::origin)
                    .collect(Collectors.toList());
        }
    };

    if (this.retryPolicy.evaluate(retryContext, loadBalancer, lbContext).shouldRetry()) {
        return Flux.from(sendRequest(request, previousOrigins, attempt, context));
    } else {
        return Flux.error(cause);
    }
}
 
Example 8
@Test
public void noDefaultConstructor() {
	Flux<DataBuffer> input =
			Flux.from(stringBuffer("{\"property1\":\"foo\",\"property2\":\"bar\"}"));
	ResolvableType elementType = forClass(BeanWithNoDefaultConstructor.class);
	Flux<Object> flux = new Jackson2JsonDecoder().decode(input, elementType, null, emptyMap());
	StepVerifier.create(flux).verifyError(CodecException.class);
}
 
Example 9
public void setBody(Publisher<DataBuffer> body) {
	this.body = Flux.from(body);
}
 
Example 10
@Override
public Flux<WebSocketMessage> receive() {
	return (canSuspendReceiving() ? Flux.from(this.receivePublisher) :
			Flux.from(this.receivePublisher).onBackpressureBuffer(RECEIVE_BUFFER_SIZE));
}
 
Example 11
static Flux<Integer> extractId(Result result) {
    return Flux.from(result.map((row, metadata) -> row.get(0, Integer.class)));
}
 
Example 12
@Override
public Flux<MessageFullView> fromMessageIds(List<MessageId> messageIds, MailboxSession mailboxSession) {
    Flux<MessageResult> messages = Flux.from(messageIdManager.getMessagesReactive(messageIds, FetchGroup.FULL_CONTENT, mailboxSession));
    return Helpers.toMessageViews(messages, this::fromMessageResults);
}
 
Example 13
Source Project: cyclops   File: FluxReactiveSeq.java    License: Apache License 2.0 4 votes vote down vote up
public static <T> ReactiveSeq<T> reactiveSeq(Publisher<T> flux){
    return new FluxReactiveSeqImpl<>(Flux.from(flux));
}
 
Example 14
@PostMapping(path = "/mirrorBodyStream")
@Override
public Flux<TestObject> mirrorBodyStream(
		@RequestBody Publisher<TestObject> bodyStream) {
	return Flux.from(bodyStream);
}
 
Example 15
Source Project: spring-analysis-note   File: WiretapConnector.java    License: MIT License 4 votes vote down vote up
@Override
@SuppressWarnings("ConstantConditions")
public Flux<DataBuffer> getBody() {
	return Flux.from(this.recorder.getPublisherToUse());
}
 
Example 16
public JettyClientHttpResponse(ReactiveResponse reactiveResponse, Publisher<DataBuffer> content) {
	this.reactiveResponse = reactiveResponse;
	this.content = Flux.from(content);
}
 
Example 17
Source Project: redisson   File: RedissonBaseReactive.java    License: Apache License 2.0 4 votes vote down vote up
<V, T> Flux<T> execute(Publisher<V> commands, Function<V, Publisher<T>> mapper) {
    Flux<V> s = Flux.from(commands);
    return s.concatMap(mapper);
}
 
Example 18
@Override
public Flux<DataBuffer> getBody() {
	return Flux.from(this.bodyPublisher);
}
 
Example 19
@Test
public void decodeEmptyArrayToFlux() {
	Flux<DataBuffer> input = Flux.from(stringBuffer("[]"));

	testDecode(input, Pojo.class, step -> step.verifyComplete());
}
 
Example 20
@Test
default void processedMailsShouldNotDecreaseSize() throws Exception {
    enQueue(defaultMail().name("name").build());

    Flux.from(getManageableMailQueue().deQueue());

    long size = getManageableMailQueue().getSize();

    assertThat(size).isEqualTo(1L);
}