public class BusSample extends AbstractVerticle {
@Override
public void start(final Future<Void> startFuture) throws Exception {
// The server to show the output
final HttpServer httpServer = this.vertx.createHttpServer();
httpServer.requestHandler(this::httpRequestHandler).listen(8805);
final EventBus eb = this.vertx.eventBus();
eb.consumer("bustest", this::busIncoming);
startFuture.complete();
}
// Simple action to write something back
private void busIncoming(final Message<String> incoming) {
final int turns = Integer.valueOf(incoming.body()).intValue();
final Buffer result = Buffer.buffer(turns * 10);
for (int i = 0; i < turns; i++) {
result.appendString("Line ");
result.appendString(Integer.toString(i));
result.appendString("\n");
}
incoming.reply(result);
}
// Simple example, just write 42 on the bus and write out
private void httpRequestHandler(final HttpServerRequest request) {
final HttpServerResponse response = request.response();
response.setChunked(true);
final EventBus eb = this.vertx.eventBus();
eb.send("bustest", "42", reply -> {
response.putHeader("Content-type", "text/plain");
final Buffer result = (Buffer) reply.result().body();
response.end(result);
});
}
}
Advice is highly appreciated
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/030d22e2-0c76-47da-b648-847e970afcf7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/472ebdd6-fde0-4ab5-b42e-7de6859af3f6%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/a4fd8820-e455-4bb3-bfa1-04ae8e994c80%40googlegroups.com.
On Apr 25, 2017, at 5:57 PM, Hoobajoob <chefho...@gmail.com> wrote:Cool - thank you for the reference! I'll take a look and see how we might approach this.We're interested in this for supporting blob retrieval where any given blob might be many megabytes in size. We do our REST front ends in javascript, though, and the pattern in other areas is to support pluggable providers written as verticles that service a well-known event bus address.For blobs, we're not sure exactly what to do because we think we'd introduce a custom codec to avoid copies on every chunked buffer message, but my understanding is that custom codecs aren't supported in javascript (is that right)?
If we try to implement the REST interface for blob retrieval in Java so we can use the custom codec, we'd need to use a separate verticle than the javascript verticle that currently sets up all the routes at that endpoint. I don't see a way to share an HTTP router instance between languages, and that seems to lead us to requiring a separate HTTP service instance (at least) serving on a different port, if not a separate jvm/vertx instance. This is not a choice we would make based on a separation-of-concerns consideration though, so it seems unfortunate.
Is there a way to have a javascript REST front end making streaming requests across the event bus to a java streaming provider with a non-copying codec (say for vertx Buffers)? Or, are we correct in assuming we are going to have to introduce a new endpoint?
Thanks for any advice you might have!
On Tuesday, April 25, 2017 at 7:40:47 AM UTC-7, Julien Viet wrote:Hi,I totally forgot this thread :-)I started a proof of concept about setting up a stream basd on event bus : https://github.com/vert-x3/vertx-service-proxy/tree/stream-protocolI used the vertx-service-proxy project because I think it I see this similar to what already exist in service proxy with @ProxyClose and so this could be based (or compatible) with the service-proxy “protocol” (i.e how it uses the event bus) and also provide streaming support for vertx-service-proxy, in short an @ServiceProxy can return or consume a ReadStream, à la gRPC.Julien
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/045e839d-fa2e-43d0-9402-1f8801e32503%40googlegroups.com.
[custom codecs] are supported if you register them from a Java, i.e a main verticle could register the codecs in Java and deploy the JavaScript verticle.
it also depends on what you send on the event bus from JS, most of the times it will be unwrapped by the JS shim.
If we try to implement the REST interface for blob retrieval in Java so we can use the custom codec, we'd need to use a separate verticle than the javascript verticle that currently sets up all the routes at that endpoint. I don't see a way to share an HTTP router instance between languages, and that seems to lead us to requiring a separate HTTP service instance (at least) serving on a different port, if not a separate jvm/vertx instance. This is not a choice we would make based on a separation-of-concerns consideration though, so it seems unfortunate.HTTP router cannot be shared between Verticles event without polyglot (that being said, it’s a request that is often asked by community that would like to make more modular HTTP routers)
Is there a way to have a javascript REST front end making streaming requests across the event bus to a java streaming provider with a non-copying codec (say for vertx Buffers)? Or, are we correct in assuming we are going to have to introduce a new endpoint?if you don’t copy, does it mean you are holding the stream data in memory to serve them ?
by new endpoint you mean http servers on different ports ?
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/1004ffdd-f531-4a57-a8e0-38261a636ce9%40googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/483589dc-43fb-4e11-aa8f-da262d98a294n%40googlegroups.com.
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/KX0qopBJoTo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/CACiEr_Te83_crkN78b1%2BNLh%2BvMidoybdTKyHtS-4mqShbH5imA%40mail.gmail.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/CAJ3ZeoisHkhughX73ROrfhEZL3mp8ZSHKpWBkTRTeF_4dLQEfg%40mail.gmail.com.