首页 文章

使用Apache点燃的Web会话群集 . 会话在第二台服务器上无效

提问于
浏览
1

以下是使用的组件

我有一个使用粘性会话的Web应用程序,我想使用apache ignite迁移到非粘性会话 . 我按照apache点燃“网络会话聚类”指南来实现更改 . 添加了负载均衡器,将循环机制中的流量路由到已配置的节点列表 . 我在端口8080上运行节点1,在端口9090上运行节点2.两个节点都在功能区负载均衡器中配置 .

在指南中提到的配置更改后,我能够成功运行单个节点 . 我能够在visor中使用下面的命令看到apache中的会话和值点燃缓存

./ignitevisorcmd.sh
缓存会话缓存 - 扫描

但是当我启动第二个节点并请求命中节点2时,会话变得无效,并且由于会话信息不可用,应用程序抛出错误 .

我怀疑tomcat的节点2在调用“apache-ignite”WebSessionFilter.class之前创建了一个新会话,并且tomcat不知道会话中已存在会话 . 然后,当调用org.apache.ignite.cache.websession.WebSessionFilter时,它将使用org.apache.ignite.cache.websession.WebSessionV2包装新创建的HttpSession,并作为新会话推送到缓存存储 . 仅供参考,我使用SessionListener使用少量对象初始化会话 .

以下是我在发布之前所做的检查/试验

  • 我的配置与文档完全匹配 .

  • WebSessionFilter是过滤器顺序中的第一个

  • 使用status命令确认已连接两个节点

  • 尝试缓存模式为"replicated"

  • 试过tomcat8并发现同样的问题 .

默认-config.xml中

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="
   http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd">
<!--
    Alter configuration below as needed.
-->
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
    <property name="cacheConfiguration">
        <bean id="igniteCacheConfiguration" class="org.apache.ignite.configuration.CacheConfiguration">
            <!-- Cache name. -->
            <property name="name" value="session-cache"/>

            <!-- Cache mode. -->
            <property name="cacheMode" value="PARTITIONED"/>
            <property name="backups" value="2"/>
            <property name="statisticsEnabled" value="true"/>
            <property name="managementEnabled" value="true" />
        </bean>
    </property>
</bean>

web.xml中

<listener>
        <listener-class>org.apache.ignite.startup.servlet.ServletContextListenerStartup</listener-    class>
    </listener>

    <filter>
        <filter-name>IgniteWebSessionsFilter</filter-name>
        <filter-class>org.apache.ignite.cache.websession.WebSessionFilter</filter-class>
    </filter>

    <!-- You can also specify a custom URL pattern. -->
    <filter-mapping>
        <filter-name>IgniteWebSessionsFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- Specify Ignite configuration (relative to META-INF folder or Ignite_HOME). -->
    <context-param>
        <param-name>IgniteConfigurationFilePath</param-name>
        <param-value>default-config.xml </param-value>
    </context-param>

    <!-- Specify the name of Ignite cache for web sessions. -->
    <context-param>
        <param-name>IgniteWebSessionsCacheName</param-name>
        <param-value>session-cache</param-value>
    </context-param>

的pom.xml

<ignite.version>2.6.0</ignite.version>

    <dependency>
        <groupId>org.apache.ignite</groupId>
        <artifactId>ignite-core</artifactId>
        <version> ${ignite.version}</version>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>org.apache.ignite</groupId>
        <artifactId>ignite-web</artifactId>
        <version> ${ignite.version}</version>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>org.apache.ignite</groupId>
        <artifactId>ignite-log4j</artifactId>
        <version>${ignite.version}</version>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>org.apache.ignite</groupId>
        <artifactId>ignite-spring</artifactId>
        <version>${ignite.version}</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>javax.cache</groupId>
        <artifactId>cache-api</artifactId>
        <version>1.1.0</version>
    </dependency>

我需要了解需要做些什么才能使Web会话与2个节点一起工作 .

2 回答

  • 0

    弄清楚问题的根本原因是我们正在使用正在访问会话信息的SessionRequestListeners . 在Apache Ignite WebFilter之前调用这些侦听器,导致在Ignite可以在Ignite的缓存中找到会话之前创建新会话 . 当调用Apache Ignite WebFilter时可以使用新会话,它只使用现有会话并对其进行缓存 .

    解决方案 - 使用过滤器代替关键监听器并移除非关键监听器及其现在工作 .

    例如删除了org.springframework.web.context.request.RequestContextListener在IgniteFilter之后添加了org.springframework.web.filter.RequestContextFilter

  • 0

    确实,请提供一个小型的复制项目 . 它应该工作,很难说出了什么问题 .

相关问题