All Downloads are FREE. Search and download functionalities are using the official Maven repository.

examples.ReactiveStreamsExamples Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR3
Show newest version
/*
 * Copyright 2014 Red Hat, Inc.
 *
 *  All rights reserved. This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License v1.0
 *  and Apache License v2.0 which accompanies this distribution.
 *
 *  The Eclipse Public License is available at
 *  http://www.eclipse.org/legal/epl-v10.html
 *
 *  The Apache License v2.0 is available at
 *  http://www.opensource.org/licenses/apache2.0.php
 *
 *  You may elect to redistribute this code under either of these licenses.
 */

package examples;

import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.docgen.Source;
import io.vertx.ext.reactivestreams.ReactiveReadStream;
import io.vertx.ext.reactivestreams.ReactiveWriteStream;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;

/**
 * @author Tim Fox
 */
@Source(translate = false)
public class ReactiveStreamsExamples {

  public void example1(HttpServerResponse response, Publisher otherPublisher) {

    ReactiveReadStream rrs = ReactiveReadStream.readStream();

    // Subscribe the read stream to the publisher
    otherPublisher.subscribe(rrs);

    // Pipe from the read stream to the http response
    rrs.pipeTo(response);

  }

  public void example2(Vertx vertx, HttpServerRequest request, Subscriber otherSubscriber) {

    ReactiveWriteStream rws = ReactiveWriteStream.writeStream(vertx);

    // Subscribe the other subscriber to the write stream
    rws.subscribe(otherSubscriber);

    // Pipe the http request to the write stream
    request.pipeTo(rws);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy