24.3.10. 使用远程存储外部化到红帽数据网格的 HTTP 会话

注意

您需要红帽数据网格订阅才能使用此功能。

此处的说明代表一种使会话外部化的旧方式。JBoss EAP 7.2 引入了基于与 elytron 子系统集成的 HotRod 协议的自定义优化缓存存储。建议您使用新的 热门存储如红帽数据网格外部化 HTTP 会话 中所述。

注意

必须为每个 distributable 应用创建一个全新的缓存。它可以在现有的缓存容器中创建,如 web

使 HTTP 会话外部化:

  1. 通过添加网络信息到 socket-binding-group,定义远程红帽数据网格服务器的位置。

    示例:添加远程套接字绑定

    /socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=remote-rhdg-server1:add(host=RHDGHostName1, port=11222)
    
    /socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=remote-rhdg-server2:add(host=RHDGHostName2, port=11222)

    生成 XML

    <socket-binding-group name="standard-sockets" ... >
      ...
      <outbound-socket-binding name="remote-rhdg-server1">
        <remote-destination host="RHDGHostName1" port="11222"/>
      </outbound-socket-binding>
      <outbound-socket-binding name="remote-rhdg-server2">
        <remote-destination host="RHDGHostName2" port="11222"/>
      </outbound-socket-binding>
    </socket-binding-group>

    注意

    您需要为每个红帽数据网格服务器配置远程套接字绑定。

  2. 确保在 JBoss EAP 的 infinispan 子系统中定义了远程缓存容器;在位于 remote-store 元素的 cache 属性的示例中,定义远程红帽数据网格服务器上的缓存名称。

    如果您在受管域中运行,请在这些命令之前使用 /profile=PROFILE_NAME

    示例:添加远程缓存容器

    /subsystem=infinispan/cache-container=web/invalidation-cache=rhdg:add(mode=SYNC)
    
    /subsystem=infinispan/cache-container=web/invalidation-cache=rhdg/component=locking:write-attribute(name=isolation,value=REPEATABLE_READ)
    
    /subsystem=infinispan/cache-container=web/invalidation-cache=rhdg/component=transaction:write-attribute(name=mode,value=BATCH)
    
    /subsystem=infinispan/cache-container=web/invalidation-cache=rhdg/store=remote:add(remote-servers=["remote-rhdg-server1","remote-rhdg-server2"], cache=default, socket-timeout=60000, passivation=false, purge=false, shared=true)

    生成 XML

    <subsystem xmlns="urn:jboss:domain:infinispan:7.0">
      ...
      <cache-container name="web" default-cache="dist" module="org.wildfly.clustering.web.infinispan" statistics-enabled="true">
        <transport lock-timeout="60000"/>
        <invalidation-cache name="rhdg" mode="SYNC">
          <locking isolation="REPEATABLE_READ"/>
          <transaction mode="BATCH"/>
          <remote-store cache="default" socket-timeout="60000" remote-servers="remote-rhdg-server1 remote-rhdg-server2" passivation="false" purge="false" shared="true"/>
        </invalidation-cache>
        ...
      </cache-container>
    </subsystem>

  3. 将缓存信息添加到应用 jboss-web.xml 文件中。在以下示例中,web 缓存容器的名称,rh dg 是此容器中相应缓存的名称。

    示例: jboss-web.xml 文件

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_10_0.xsd"
               version="10.0">
        <replication-config>
            <replication-granularity>SESSION</replication-granularity>
            <cache-name>web.rhdg</cache-name>
        </replication-config>
    </jboss-web>