开发者

How to use Netty from inside a web app - steps to proper configuration

I'm trying to setup Netty to run embedded in my web application.

I have found the following document: http://docs.jboss.org/netty/3.2/api/org/jboss/netty/channel/socket/http/package-summary.html#package_description that describes how to configure a web.xml file that starts a Netty servlet.

Now the document says:

Second, you have to bind your Netty-based server application in the same Servlet context or shared class loader space using the local transport (see LocalServerChannelFactory.) You can use开发者_开发百科 your favorite IoC framework such as JBoss Microcontainer, Guice, and Spring to do this. The following example shows how to bind an echo server to the endpoint specifed above (web.xml) in JBossAS 5:

That sound reasonable but it is not clear to me how - practically - that should work. Say that I want to use Spring as Ioc container, what would be the proper beans configuration to bind netty to the local transport?

Also, how do I start the Spring context? From web.xml?

Thanks


I personally recommend using spring. It can integrate with almost everything under the sun.

Take a look at the following link which shows how to configure your Netty server as a spring bean and then using it in a web app.

This is the way you could do it for a spring + web app.

1) Create relevant spring beans for the server, pipeline factory etc.
2) In the web.xml configure the spring dispatcher servlet.

Note: The above configuration is for running the Netty server at some port along with your web app.

Basically you can call the spring bean init-method attribute on any bean to do the netty server startup

You could configure the servlet as mentioned in the link in your post. You can cross-reference any spring bean(say the netty server bean) within the servlet bean, or call it within your servlet bean's init-method.

Yet another possibility is that you can listen to spring application events and then after the container has started up, you can manually launch your servlet/netty server.

If you are using a grails app then the bootstrap class ( a convenience class which is called on application startup) can be used to startup the Netty server on web app startup

Spring provides n-number of ways to do what you require, you can choose based on your convenience.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜