How does eventbus expose restful api for web?

130 views
Skip to first unread message

蓝鲸鱼

unread,
Sep 25, 2016, 10:01:31 PM9/25/16
to vert.x
I have a eventbus.send.

And I want my web restful api can handle that eventbus data.

Because that eventbus is sent by a socket handler. So it has no return value. Just  a send .


ad...@cs.miami.edu

unread,
Sep 25, 2016, 11:32:16 PM9/25/16
to vert.x
蓝鲸鱼

The eventbus has the ability to send a message, and also consume a message via a handler (among other things that the EB can do).

The EB can reach into the client browser via sockjs.

But, it sounds like you want the traditional restful api style (not a realtime sockjs).

If this is the case, you could do the following:

a) deploy a verticle that has a vertx httpserver. 
b) register  handlers on the httpserver to match the routes of your REST api
c) within those handlers, do whatever you want and send the answer back using the response object.

I am not quite sure where and how you want to incorporate the EB?  The EB often used passing messages between different parts of your vertx app (it could be between different JVMs across the network).  Think of it as another way to provide an addresss for a micro-service.

In the above situation, the http handlers could make a call along the EB, get the response, and the push it up the pipeline back to the client via the http response.

-Adam

蓝鲸鱼

unread,
Sep 27, 2016, 2:11:14 AM9/27/16
to vert.x
Yes, that's the point, but  the http handlers cannot make a call along the EB,because the socket handler has no return value.

So , that's what i am confusing.

i have a socket. and i don't know how to return value.

NetClient netClient = vertx.createNetClient();

netClient.connect(port, host, ar -> {

    if (ar.succeeded()) {

        socket = ar.result();

        socket.handler(this::onDataReceived);

        socket.write(buffer);

    }

});


private void onDataReceived(Buffer buffer) {

    // i want to use this method return value. so i can get the socket response.

}


the socket handler can not use return value or  message.reply thing.

Because i want to expose this data to the web.


在 2016年9月26日星期一 UTC+8上午11:32:16,ad...@cs.miami.edu写道:

Jez P

unread,
Sep 27, 2016, 4:08:03 AM9/27/16
to vert.x
This isn't really a vert.x question. REST is fundamentally request/response. Sockets are listened to.

So rather than thinking about the event bus/vert.x concepts, can you start by outlining your use-case and then maybe we can advise from there?

So what triggers your socket to connect? What triggers it receiving data (or does it just receive data constantly). That deals with one side.

Secondly, what do you want to return from your RESTful request? Do you need something else in there that aggregates data from the socket ready to return to the requests?  Or should the request trigger opening of the socket, listening for some data, then when it has all the data, closing the socket and returning a response containing all the data?

I don't think your question is about vert.x specifically (though you couch it in vert.x terms) but about what you actually want your system to do. Let's start from there please.

Jez P

unread,
Sep 27, 2016, 4:09:17 AM9/27/16
to vert.x
*Sockets are listened to or written to

蓝鲸鱼

unread,
Sep 27, 2016, 4:16:36 AM9/27/16
to vert.x
1) Request comes into http server
2) pass request parameters as a message along the eveentbus
3) handle that message in a separate verticle, and create a reesponse answer  (that verticle use a socket write and receive data)
4) pass response answer back along the eventbus     (because it's a socket to another server and netsocket use handler, so response along the eventbus.)
5) push the response answer back as a response to the originating htttp request. 







在 2016年9月27日星期二 UTC+8下午4:08:03,Jez P写道:

Jez P

unread,
Sep 27, 2016, 4:52:35 AM9/27/16
to vert.x
So how does your netsocket verticle know when it has all the data it needs from the socket? Surely at that point it can call message.reply, assuming that's when you set up the connection.

Mumuney Abdlquadri

unread,
Sep 27, 2016, 8:26:06 AM9/27/16
to ve...@googlegroups.com
Hi,

When you say:

3) handle that message in a separate verticle, and create a reesponse answer  (that verticle use a socket write and receive data)

Is data here referring to EventBus message or a separate client is writing to the socket..?

4) pass response answer back along the eventbus     (because it's a socket to another server and netsocket use handler, so response along the eventbus.)

Are you using the vertx.eventBus().send() that has a handler in (3) above? Are you calling message.reply() in (4)?

If (3) must be a TCP Server, Vertx has a EventBus TCPBridge that can be used...


On Tue, Sep 27, 2016 at 9:52 AM, Jez P <mr.n...@gmail.com> wrote:
So how does your netsocket verticle know when it has all the data it needs from the socket? Surely at that point it can call message.reply,  assuming that's when you set up the connection.

--
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+unsubscribe@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/60710f34-4f6f-443f-861b-70d1d3a5166a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages