"Upgrade to WebSocket required" using the development environment

992 views
Skip to first unread message

Samuele Di Rito

unread,
Sep 1, 2017, 4:35:26 AM9/1/17
to Lagom Framework Users
Hello,

I'm trying to follow the documentation to write an API to GET some data from a table in Cassandra.
I work on a dev environment and my project is based on the simple example from github.

When I invoke the API from a client, the server answer me "Upgrade to WebSocket required". I think, due to the dev env, that everything is set up just to work fine.

From what I can understand by myself reading the docs, it's related to the signature I put on the Service:

ServiceCall<NotUsed, Source<Person, ?>> getPeople();


Because I use Source<?, ?> as type of return, it will use Akka Streams so on client-side it expects to be consumed by websockets, isn't it?

Then, following this supposition, I try to open a websocket channel on the gateway and on the API url, but neither of the two options worked.


Maybe I just need to change the signature of the getPeople method, but Cassandra driver returns a Source and I don't know how to convert it to a simple list.


I'm moving my first steps with Lagom, so I'm not able to be more clear than this... :(


Can you help me?

Thank you very much.


Tim Moore

unread,
Sep 3, 2017, 6:55:10 PM9/3/17
to Samuele Di Rito, Lagom Framework Users
Hi Samuele,

What client are you using to access your service?

The "Upgrade to WebSocket required" message is normal when trying to connect an HTTP client that doesn't support WebSocket upgrade headers.

You are correct that using a "Source" in the response type (or request type) will cause Lagom to use a WebSocket transport. Source indicates streaming communication, and at this time, WebSocket is Lagom's only means of streaming communication over HTTP.

You mention: "I try to open a websocket channel on the gateway and on the API url, but neither of the two options worked" but could you be more specific about what you tried and what actually happened? Either one should work (if you have declared the appropriate ACLs in your service interface to make the service available from the gateway).

If you can share your source code, that might help us see where the problem is.

You might want to consider changing the signature. The question comes down to: what kind of interface do you want to expose to clients? Source is appropriate if you want to stream data continuously to the client, which would be good if you have a large number of responses. List is appropriate if you are returning a small number of responses that can be fully buffered in memory before sending the response.

If you would like to return a List from the Cassandra client, there are alternate methods called "selectAll" (instead of "select") that return CompletionStage<List<Row>> instead of Source<Row>.


Best,
Tim



--
You received this message because you are subscribed to the Google Groups "Lagom Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lagom-framework+unsubscribe@googlegroups.com.
To post to this group, send email to lagom-framework@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lagom-framework/855b4f47-7458-4808-8627-88255532bcb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages