Small HTTP routing library for already configured Netty - java

We have service which mostly use gRPC. So we just use netty+io.grpc and need no extra frameworks here.
But we also need to support some HTTP requests for our infrastructure team.
And I think it will be better to reuse Netty (EventLoopGroup, ChannelFactory, etc) which we already configured.
So basically I need small HTTP routing library for already configured Netty.
But most of HTTP over Netty frameworks like Vert.x, Jooby, Ratpack or Armeria, manage Netty by their-self and just too complex for my case.
It will be simpler to me just use HttpServer from JDK and doesn't care about a bit of context switches because of over creating event loops.
But I really want to get clean solution.
I'm open to any suggestions.

Related

Configure a Netty application to use a proxy

Telerik has an how-to on Configure a Java Application to Use Fiddler. That does not seem to work (meaning it seems to have no effect) with our Netty based application, which I assume is because that would only apply to applications that use the default J2SE built-in HTTP libraries? Also see Java Networking and Proxies in the Java SE docs.
Is there a standard way of configuring a Netty based application for picking up proxying, or would I need to manually add a handler to the channel pipeline that would change the HTTP requests (and responses?) to use the proxy? If the latter, is there a standard handler I could employ that has all the logic for setting headers, changing urls, etc. built-in?
There is a proxy package in Netty, in which HttpProxyHandler seems to be what you are looking for, with regards to the last question on whether there is standard handler built-in. Have not used it, though, so cannot say whether or not it picks up on those system props.

Migrate Netty Websocket to Jetty Websocket

My application uses a custom binary protocol which is implemented with Netty. Recently I changed it to use Netty's websocket implementation. It works quite well.
My application also has a Jetty web server included and it offers websockets, too. Now I want to reduce the opened ports my server needs and handle all http traffic with one port.
I see three options:
Use either Netty or Jetty to proxy the traffic which belongs to the other implementation.
Reimplement the custom protocol on Jetty without the use of Netty's channels and piplines.
Create a custom implementation of Netty's channels that sends and receives it's data not over a socket but the methods Jetty's WebSocketListener offers.
Since Netty provides such a good api for writing binary protocols and a proxy sounds like extra problems to me I tend using the third approach. It shouldn't be too difficult to implement even though I don't know how to do it, yet.
Any thoughts what would be the best option and how I should implement it?

RestTemplate for AsyncHttpClient

After some benchmarking I've found that AsyncHttpClient (https://github.com/AsyncHttpClient/async-http-client) seems to be the most stable and scalable async http client out there as it's based on NIO and seems to scale very well during load. I compared it against OkHttp and Apache Async and it seems to perform really well when simulating a backend with latency.
Unfortunately I have not yet found any way to expose it as a Spring AsyncRestTemplate, making a migration in our existing codebase a pain.
Does anyone know of any good bridge to RestTemplate's using the library, or if otherwise, how to create an issue in the Spring project to include it among the other Async http client factories?
You can't use RestTemplate for async requests, that's what the AsyncRestTemplate is for. You'll need to implement your own AsyncClientHttpRequestFactory. I briefly looked into the link you provided in your post, and it looked like you could wrap a AsyncRestClient and return BoundRequestBuilder from AsyncClientHttpRequestFactory.createAsyncRequest. Then onwards, you basically need to delegate the calls from Spring-specific interfaces to AsyncRestClient-specific classes. It shouldn't be too hard.
That said, Spring 5 Web comes with a WebClient that does async and more. I suggest seriously considering it before building your own async library, albeit on top of another one.
Here is an official java doc of spring RestTemplate.
Note: by default the RestTemplate relies on standard JDK facilities to
establish HTTP connections. You can switch to use a different HTTP
library such as Apache HttpComponents, Netty, and OkHttp through the
HttpAccessor.setRequestFactory(org.springframework.http.client.ClientHttpRequestFactory)
property.
EDIT:
OK here you go with spoon feeded answer:
AsyncRestTemplate template = new AsyncRestTemplate(
new HttpComponentsAsyncClientHttpRequestFactory());
HttpComponentsAsyncClientHttpRequestFactory is part of spring since 4.0

Best way to manage asynchronous / push communication with web clients on a Spring based Java server

I need to push events to web clients in a cross-browser manner (iPhone, iPad, Android, IE/FF/Chrome/etc.) from a Spring based Java server. I am using backbone.js on the client side.
To my best knowledge, I can either go with a Web socket only approach, or I can use something like socket.io.
What is the best practice for this issue, and which platform/frameworks should I use?
Thanks
Looks like you're interested in an AJAX Push engine. ICEPush (same group that makes ICEFaces) provides these capabilities, and works with a variety of server- and client-side frameworks. There is also APE.
You can have a look at Lightstreamer.
My company is currently using it to push real time financial data from a web server.
I suppose Grizzly or Netty may fit your needs. Don't have a real experience in that scope, unfortunately.
I'd recommend socket.io as you mentioned in your question, if you're doing browser based eventing from a remote host. Socket.io handles all the connection keep-alives and reconnections directly from javascript and has facilities for channeling messages to specific sessions (users). The real advantage comes from the two-way communication of WebSockets without all the boilerplate code of maintaining the connection.
You will need to do some digging for a java implementation thoughConsider running the server directly from V8.

Which Client - Server Communication Approach?

Basically I need a bidirectional client-server communication (Java) where the client calls methods on the server, but also needs to get "callbacks" if certain events in the server occur.
The methods theirselves have quite complex input and output parameters and lateron it would be nice to include authentication to the system.
Which approach would fit my requirements?
I already build a prototype with RMI, but I read that there exists a number of problems especially for "callbacks" when the c/s are in different networks.
Additionally I would like to avoid JAX related technology, becuase of my complex data structures in the parameters.
Have you thought about using JMS. Within this architecture, server and client will register to a queue or topic and are able to send messages to each other. This enables sych and async application behaviour.
Please have a deeper look into JMS here:
http://java.sun.com/developer/technicalArticles/Ecommerce/jms/index.html
And a really nice implementation is ActiveMQ:
http://activemq.apache.org/
I've had lots of luck with using CometD for callbacks for webapps.

Categories

Resources