nekop's blog

OpenShift / JBoss / WildFly / Infinispanの中の人 http://twitter.com/nekop

JBoss EAP 6.2でAtmosphereのnativeを動かす

JBoss / WildFly (全部俺) Advent Calendar 2013の25日目です。

Atmosphere Frameworkという非同期アプリケーションフレームワークがあります。作者はGrizzlyの作者でもあるjfarcandさんです。

AtmosphereをJBoss EAP 6.2.0のNativeコネクタで提供されるAsyncサポートと組み合わせて利用するセットアップががなかなかWeb上に情報のないものだったので書いておきます。

JBoss EAP 6.2.0はNativeコネクタを追加インストール(要サブスクリプション、もしくはコミュニティ版JBoss Web Native Connectorsでがんばる)してwebサブシステムのnative="false"をtrueに変更。

OS側依存もインストールしておきます。

$ sudo yum install apr openssl zlib-devel

これでネイティブコネクタ(APR)が有効化されます。

この時点でAtmosphereのサンプルのchatのwarをデプロイすると怒られます。

WARN  [org.atmosphere.cpr.AtmosphereFramework] (http-thread-pool-threads - 10) Failed using comet support: org.atmosphere.container.JBossWebCometSupport, error: JBoss failed to detect this is a Comet application because the APR Connector is not enabled. 
Make sure atmosphere-compat-jboss.jar is not under your WEB-INF/lib and You must use the atmosphere-native-runtime dependency in order to use native Comet Support
there is no context.xml under WEB-INF Is the NIO or APR Connector enabled?
ERROR [org.atmosphere.cpr.AtmosphereFramework] (http-thread-pool-threads - 10) 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.
WARN  [org.atmosphere.cpr.AtmosphereFramework] (http-thread-pool-threads - 10) Using org.atmosphere.container.BlockingIOCometSupport

エラーメッセージがあまり親切ではないのですが、これはAtmosphereのセットアップの問題で、コンテナ依存のAsyncサポートを使う場合はドキュメントにある通りatmosphere-runtime.jarを使ってはいけません。atmosphere-runtime-nativeと、実際に利用するコンテナ以外のスタブjarを利用します。

    <dependency>
      <groupId>org.atmosphere</groupId>
      <artifactId>atmosphere-runtime-native</artifactId>
      <version>2.0.5</version>
    </dependency>
    <dependency>
      <groupId>org.atmosphere</groupId>
      <artifactId>atmosphere-compat-tomcat</artifactId>
      <version>2.0.1</version>
    </dependency>
    <dependency>
      <groupId>org.atmosphere</groupId>
      <artifactId>atmosphere-compat-tomcat7</artifactId>
      <version>2.0.1</version>
    </dependency>

chatのwarのlibを上の通りに差し替えてデプロイするとnativeサポートが有効になります。

INFO  [org.atmosphere.cpr.AtmosphereFramework] (ServerService Thread Pool -- 49) Atmosphere is using async support: org.atmosphere.container.JBossWebCometSupport running under container: JBoss Web/7.2.2.Final-redhat-1
INFO  [org.atmosphere.cpr.AtmosphereFramework] (ServerService Thread Pool -- 49) Atmosphere Framework 2.0.5 started.
INFO  [org.atmosphere.cpr.AtmosphereServlet] (ServerService Thread Pool -- 49) AtmosphereServlet with native support for Tomcat 6/7 and JBossWeb Installed.