Using SPDY with Netty
Asked Answered
H

2

7

I've set up MOD_SPDY on my Apache server and now want to retrofit my client code to use Netty's SPDY implementation to send my requests to the server over a SPDY channel.

This is my first experience using Netty, so I think I get that I need to somehow configure my Channel and then send requests through it. The problem is, that it doesn't seem very clear exactly how to configure the channels and even after that, how to track multiple HTTP requests inside the channel that might be executing concurrently.

I've googled around and found the SPDY package: http://netty.io/docs/stable/api/org/jboss/netty/handler/codec/spdy/package-summary.html

but the documentation is still quite thin there. I didn't seem to find any examples of using the code, only the announcement that it exists in the latest release.

Does someone have an example about how to construct a SPDY channel and then send/track multiple requests and responses through it? Also, how would this function when the server does not support SPDY and the channel falls back to a standard SSL connection?

Hillside answered 9/4, 2012 at 21:0 Comment(3)
If you're not tied to Netty, maybe you can try Jetty's SPDY, see webtide.intalio.com/2012/03/spdy-support-in-jetty and smartjava.org/content/how-use-spdy-jetty.Binny
@svordet Bill already has a server, he needs a client.Spatter
Actually, it looks like sbordet is correct; Jetty also has a SPDY client that might be easier to work with: wiki.eclipse.org/Jetty/Feature/…Hillside
S
3

Only example I could find on Netty and SPDY is a test code for SessionHandler and socket echo test. I'm yet to make this thing running, but Your client should make pipeline consisting of SpdyFrameCodec, SpdySessionHandler and your handler.

Your handler should be modeled after EchoHandler in session test, because that way SpdySessionHandler does job of decoding raw frames into more meaningful ones and does some things as required by SPDY protocol.

As for fall-backing, there are SpdyHttpCodec in snapshot version of the Netty that translates from SPDY to HTTP. That way you can build your client handler in terms of HTTP and receive messages that came either through SPDY or HTTP transparently. To do this it is required to implement something similar to port unification example.

All that said. There is room for few utility classes/handlers to make all of this an "out of the box" experience. I wanted to make a working example, but am lacking time right now for it, and there would be too much code to simply paste it here as answer.

Spatter answered 10/4, 2012 at 8:51 Comment(2)
Ah, so I just request multiple channels from the factory and under the hood the SPDY handlers will multiplex them? In what order should I add the handlers?Hillside
Unfortunately it's not that simple, but it is possible to make it using provided classes. I'm interested in making this work myself, so I'll try to build working code later.Spatter
S
2

There aren't much examples for using spdy with jetty. I'm usually not one for shameless promotion, but I just wrote down a complete example on how to do what you want. I've configured netty to serve spdy when the client supports it and fall back to http when spdy isn't available. You can find the code at: http://www.smartjava.org/content/using-spdy-and-http-transparently-using-netty

Shoer answered 28/4, 2012 at 7:52 Comment(2)
Thanks for the answer, but I'm looking for the opposite. I want an HTTP Client that will use SPDY when available but fall back to regular HTTP.Hillside
Ah, like that. Then you can still use pretty much the same approach and set of handlers. But instead of using a ServerBootstrap, use a ClientBootstrapShoer

© 2022 - 2024 — McMap. All rights reserved.