如何从Web应用程序内部使用Netty-正确配置的步骤 [英] How to use Netty from inside a web app - steps to proper configuration

查看:110
本文介绍了如何从Web应用程序内部使用Netty-正确配置的步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置 Netty 以在我的Web应用程序中嵌入运行.

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.

现在文档显示:

第二,您必须绑定您的 基于Netty的服务器应用程序 相同的Servlet上下文或共享类 使用本地运输的装载机空间 (请参阅LocalServerChannelFactory.) 可以使用您喜欢的IoC框架 例如JBoss Microcontainer,Guice, 和Spring做到这一点.以下 示例显示了如何绑定回声 服务器到上面指定的端点 (web.xml)在JBossAS 5中:

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:

这听起来很合理,但我不清楚实际上-应该如何工作.假设我要使用Spring作为Ioc容器,将netty绑定到本地传输的正确bean配置是什么?

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?

此外,如何启动Spring上下文?来自web.xml?

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

谢谢

推荐答案

我个人建议使用spring.它可以与几乎所有的阳光融为一体.

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

看看下面的链接其中显示了如何将Netty服务器配置为spring bean,然后在Web应用程序中使用它.

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.

这是您可以在Spring + Web应用程序中实现的方法.

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.

注意:上面的配置用于在Web应用程序的某个端口上运行Netty服务器.

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

基本上,您可以在任何bean上调用spring bean的init-method属性来启动Netty服务器

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

您可以按照您的帖子中的链接中所述配置servlet.您可以交叉引用servlet bean中的任何spring bean(例如netty服务器bean),或在servlet bean的init-method中调用它.

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.

另一种可能性是,您可以侦听spring应用程序事件,然后在容器启动后,可以手动启动servlet/netty服务器.

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.

如果您使用的是grails应用程序,则可以使用bootstrap类(在应用程序启动时调用的便捷类)来在Web应用程序启动时启动Netty服务器

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提供了n种方法来满足您的要求,您可以根据自己的方便进行选择.

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

这篇关于如何从Web应用程序内部使用Netty-正确配置的步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆