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

The following examples show how to use reactor.core.publisher.Flux#from() . 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: Jackson2JsonDecoderTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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 2
Source File: ReactorDemo.java    From reactive-streams-in-java with Apache License 2.0 5 votes vote down vote up
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 File: FluxTests.java    From reactor-core with 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 File: GetFilterMethod.java    From james-project with 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 File: Server.java    From tutorials with 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 File: SpringFunctionAdapterInitializerTests.java    From spring-cloud-function with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: StyxBackendServiceClient.java    From styx with 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
Source File: Server.java    From tutorials with 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 9
Source File: FluxReactiveSeq.java    From cyclops with 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 10
Source File: Jackson2JsonDecoderTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void decodeEmptyArrayToFlux() {
	Flux<DataBuffer> input = Flux.from(stringBuffer("[]"));

	testDecode(input, Pojo.class, step -> step.verifyComplete());
}
 
Example 11
Source File: ServletServerHttpRequest.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public Flux<DataBuffer> getBody() {
	return Flux.from(this.bodyPublisher);
}
 
Example 12
Source File: RedissonBaseReactive.java    From redisson with 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 13
Source File: JettyClientHttpResponse.java    From java-technology-stack with MIT License 4 votes vote down vote up
public JettyClientHttpResponse(ReactiveResponse reactiveResponse, Publisher<DataBuffer> content) {
	this.reactiveResponse = reactiveResponse;
	this.content = Flux.from(content);
}
 
Example 14
Source File: WiretapConnector.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
@SuppressWarnings("ConstantConditions")
public Flux<DataBuffer> getBody() {
	return Flux.from(this.recorder.getPublisherToUse());
}
 
Example 15
Source File: AllFeaturesController.java    From feign-reactive with Apache License 2.0 4 votes vote down vote up
@PostMapping(path = "/mirrorBodyStream")
@Override
public Flux<TestObject> mirrorBodyStream(
		@RequestBody Publisher<TestObject> bodyStream) {
	return Flux.from(bodyStream);
}
 
Example 16
Source File: MessageFullViewFactory.java    From james-project with Apache License 2.0 4 votes vote down vote up
@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 17
Source File: QueryIntegrationTestSupport.java    From r2dbc-mysql with Apache License 2.0 4 votes vote down vote up
static Flux<Integer> extractId(Result result) {
    return Flux.from(result.map((row, metadata) -> row.get(0, Integer.class)));
}
 
Example 18
Source File: AbstractListenerWebSocketSession.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public Flux<WebSocketMessage> receive() {
	return (canSuspendReceiving() ? Flux.from(this.receivePublisher) :
			Flux.from(this.receivePublisher).onBackpressureBuffer(RECEIVE_BUFFER_SIZE));
}
 
Example 19
Source File: MockClientHttpResponse.java    From spring-analysis-note with MIT License 4 votes vote down vote up
public void setBody(Publisher<DataBuffer> body) {
	this.body = Flux.from(body);
}
 
Example 20
Source File: ManageableMailQueueContract.java    From james-project with Apache License 2.0 3 votes vote down vote up
@Test
default void processedMailsShouldNotDecreaseSize() throws Exception {
    enQueue(defaultMail().name("name").build());

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

    long size = getManageableMailQueue().getSize();

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