如何配置Tomcat和HAProxy以与WebSocket Framework Atmosphere一起使用? [英] How do I configure Tomcat and HAProxy to work with the WebSocket Framework Atmosphere?

查看:149
本文介绍了如何配置Tomcat和HAProxy以与WebSocket Framework Atmosphere一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行在Tomcat7上的Java应用程序,该应用程序使用 Atmosphere Framework . Atmosphere是一个Websocket框架.我使用了大气示例聊天中的示例应用程序. 我的问题是我没有得到运行我的Websocket Atmosphere应用程序的连接器以及正确的配置.

I have a Java application running on Tomcat7, which uses the Atmosphere Framework. Atmosphere is a Websocket Framework. I used a sample application from the Atmosphere Sample Chat. My problem is that I did not get the connectors as well as the proper configuration for my Websocket Atmosphere application running.

我遇到的问题是:

  1. 如何配置HAProxy?
  2. 如何配置Tomcat服务器?
  3. 如何为APR和NIO连接器配置Tomcat?
  4. 我是否需要更改我的应用程序(即我的web.xml)中的某些内容?
  5. 我该如何解决以下错误?

这是我的 HAProxy 配置:

defaults
mode http
log global
option httplog
option  http-server-close
option  dontlognull
option  redispatch
option  contstats
retries 3
backlog 10000
timeout client      25s
timeout connect     5s
timeout server      25s
# timeout tunnel available in ALOHA 5.5 or HAProxy 1.5-dev10 and higher
#   timeout tunnel  3600s
timeout http-keep-alive 1s
timeout http-request        15s
timeout queue        30s
timeout tarpit      60s
default-server inter 3s rise 2 fall 3
option forwardfor


frontend ft_web
  bind *:80 name http
  maxconn 60000

  acl host_testhostdev  hdr(host) -i www.testhost.com

  use_backend apache-8080 if host_testhostdev

  default_backend apache-8080


backend apache-8080
  balance roundrobin

  server websrv1 localhost:8080 maxconn 8000 weight 10 cookie websrv1 check

我的Atmosphere Servlet的 web.xml 部分:

The web.xml part for my Atmosphere Servlet:

<async-supported>true</async-supported>
<init-param>
   <param-name>org.atmosphere.useNative</param-name>
   <param-value>true</param-value>
</init-param>   

<init-param>
<param-name>org.atmosphere.cpr.AtmosphereInterceptor</param-name>
    <param-value>org.atmosphere.interceptor.HeartbeatInterceptor,org.atmosphere.interceptor.AtmosphereResourceLifecycleInterceptor,org.atmosphere.client.TrackMessageSizeInterceptor</param-value>
</init-param>

<init-param>
   <param-name>org.atmosphere.cpr.broadcaster.shareableThreadPool</param-name>
   <param-value>true</param-value>
</init-param>

<init-param>
   <param-name>org.atmosphere.cpr.sessionSupport</param-name>
   <param-value>true</param-value>
</init-param>
<init-param>
   <param-name>org.atmosphere.cpr.broadcasterCacheClass</param-name>
   <param-value>org.atmosphere.cache.UUIDBroadcasterCache</param-value>
</init-param>

我在Tomcat server.xml

!--
<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
 -->

<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"/>  

这些是我得到的错误:

 ERROR cpr.AtmosphereFramework  - If you have more than one Connector enabled, make sure they both use the same protocol, e.g NIO/APR or HTTP for all. If not, org.atmosphere.container.BlockingIOCometSupport will be used and cannot be changed.

 2013-08-02 11:03:11,384 [http-nio-8080-exec-26] ERROR test.ReflectionService  - 
 Service method exception in publishDataCreatedCount in service  ClientNotificationUpdateService
 java.lang.NullPointerException
at org.atmosphere.cpr.AtmosphereRequest.setAttribute(AtmosphereRequest.java:569)
at org.atmosphere.cpr.DefaultBroadcaster.executeAsyncWrite(DefaultBroadcaster.java:922)
at org.atmosphere.util.SimpleBroadcaster.queueWriteIO(SimpleBroadcaster.java:192)
at org.atmosphere.cpr.DefaultBroadcaster.deliverPush(DefaultBroadcaster.java:768)
at org.atmosphere.cpr.DefaultBroadcaster.push(DefaultBroadcaster.java:666)
at org.atmosphere.util.SimpleBroadcaster.broadcast(SimpleBroadcaster.java:133)
at test.ClientUpdateService.sendToBoard(ClientUpdateService.groovy:46)
at test.ClientNotificationUpdateService.publishDataCreatedCount(ClientNotificationUpdateService.groovy:179)
at test.ReflectionService.callByConvention(ReflectionService.groovy:59)
at test.ClientUpdateService.methodMissing(ClientUpdateService.groovy:65)
at test.NotificationService.create(NotificationService.groovy:206)
at test.HomeController.addAction(HomeController.groovy:402)
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)

,如果我使用IE8和IE9访问我的应用,则会显示此信息:

and this one if I access my app with IE8 and IE9:

2013-08-08 00:56:19,631 [http-nio-8080-exec-9] ERROR cpr.AtmosphereFramework  - AtmosphereFramework exception
java.lang.IllegalStateException: Not supported.
    at org.atmosphere.cpr.AtmosphereRequest.startAsync(AtmosphereRequest.java:594)
    at org.atmosphere.container.Servlet30CometSupport.suspend(Servlet30CometSupport.java:130)
    at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:105)
    at org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket.doService(Tomcat7Servlet30SupportWithWebSocket.java:65)
    at org.atmosphere.container.TomcatWebSocketUtil.doService(TomcatWebSocketUtil.java:87)
    at org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket.service(Tomcat7Servlet30SupportWithWebSocket.java:61)
    at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:1594)
    at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:176)
    at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:162)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
2013-08-08 00:56:19,670 [http-nio-8080-exec-2] ERROR cpr.AtmosphereFramework  - AtmosphereFramework exception
java.lang.IllegalStateException: Not supported.
    at org.atmosphere.cpr.AtmosphereRequest.startAsync(AtmosphereRequest.java:594)
    at org.atmosphere.container.Servlet30CometSupport.suspend(Servlet30CometSupport.java:130)
    at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:105)
    at org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket.doService(Tomcat7Servlet30SupportWithWebSocket.java:65)
    at org.atmosphere.container.TomcatWebSocketUtil.doService(TomcatWebSocketUtil.java:87)
    at org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket.service(Tomcat7Servlet30SupportWithWebSocket.java:61)
    at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:1594)
    at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:176)
    at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:162)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

推荐答案

好的,这就是我要做的.在您的Tomcat服务器上安装APR连接器.这将加快生产环境.下载 APR 并按照安装说明在您的操作系统上进行编译.您不再需要NIO连接器.

Okay here is what I would do. Install the APR Connector on your Tomcat server. This will speed up the production environment. Download APR and follow the install instructions to compile it on your os. You do not need the NIO Connector anymore.

编辑您的server.xml:

Edit your server.xml:

<Connector port="8080" 
            protocol="org.apache.coyote.http11.Http11AprProtocol" 
            URIEncoding="UTF-8" 
            maxThreads="250"
            redirectPort="8443" />  

请勿使用org.atmosphere.interceptor.AtmosphereResourceLifecycleInterceptor,这会对我造成错误.

Do not use the org.atmosphere.interceptor.AtmosphereResourceLifecycleInterceptor this causes errors for me.

您的HAProxy配置很好.您还应该使用而不是大气运行时.jar而不是大气运行时.jar.

Your HAProxy config is fine. You should also use the atmosphere-runtime-native.jar instead of the atmosphere-runtime.jar.

您可能会发生错误,因为您将不支持websocket的浏览器连接到使用websocket的应用程序.

Your errors might occur because you connect with a browser that does not support websockets to your application which uses websockets.

这篇关于如何配置Tomcat和HAProxy以与WebSocket Framework Atmosphere一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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