infinispan配置

<?xml version="1.0" encoding="UTF-8"?>
<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:infinispan:config:4.0">
    <global>
      <transport transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport"
                 clusterName="infinispan-cluster"
                 nodeName="ClusterTest"
                 distributedSyncTimeout="50000">      
         <properties>
                 <property name="configurationFile" value="stacks/tcp.xml"/>
         </properties>
      </transport>                             
    </global>

    <default>
        <clustering mode="r">
            <l1 enabled="true" lifespan="60000"/>
            <hash numOwners="2" rehashRpcTimeout="60000"/>
            <sync/>
        </clustering>
        <transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"/>
    </default>

    <namedCache name="allocation">
      <transaction useEagerLocking="true" transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"/>                </namedCache>
<namedCache name="exclusion">  
        <clustering mode="replication">
            <sync/>
        </clustering>
        <expiration lifespan="5000"/>  
    </namedCache>
   <namedCache name="content">  
        <clustering mode="replication">
            <sync/>
        </clustering>  
    </namedCache>       
</infinispan>



tips:
transporttransportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport"
这里是将transportclass指定为JGroupsTransport,这里的transport必须是org.infinispan.remoting.transport.Transport的子类,infinispan自己仅仅实现了jgroups的transport,如果不想用jgroups的话,那么自己基于socket实现一个transport也是可以的。
clusterName="infinispan-cluster"
这里指定cluster name,只有在同一个cluster内部的节点才能互相复制数据。
nodeName="ClusterTest"
nodeName在默认情况下可以不写
<property name="configurationFile"value="stacks/tcp.xml"/>
这个属性很重要,表示stacks的配置信息是从statcks/tcp.xml里读取,注意,对应的name一定要设置成configurationFile。当然也可以使用编程的方式来指定,这里总共可以有四种方式,具体配置和代码可以参考infinispan的官方文档。


default的这一段是对cache做一些通用的配置,其中需要注意的是clusteringmode="r",mode有三种模式,local,replication anddistribution,如果不写模式的话,默认就是local,r和d分别是replication以及distribution的简写。
在infinispan里我们可以使用jpa或者jta的transactionmanager来管理事务,如果是测试环境下,则可以使用dummy transactionmanager(infinispan自己提供的,只是如果需要跟spring一起用的话,需要将这个transactionmanager作为spring中jta transaction manager的构造函数参数注入)

expirationlifespan="5000"也很重要,它规定了多长时间缓存的对象过期。当然这也可以在cache层面用编码的方式来指定。


jgroups的基本配置
使用tcp


<config xmlns="urn:org:jgroups"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:org:jgroups file:schema/JGroups-2.8.xsd">
   <TCP bind_port="7800"
        loopback="true"
        port_range="30"
        recv_buf_size="20000000"
        send_buf_size="640000"
        discard_incompatible_packets="true"
        max_bundle_size="64000"
        max_bundle_timeout="30"
        enable_bundling="true"
        use_send_queues="true"
        sock_conn_timeout="300"
        enable_diagnostics="false"
        skip_suspected_members="true"
 
        thread_pool.enabled="true"
        thread_pool.min_threads="2"
        thread_pool.max_threads="8"
        thread_pool.keep_alive_time="5000"
        thread_pool.queue_enabled="false"
        thread_pool.queue_max_size="100"
        thread_pool.rejection_policy="Run"

        oob_thread_pool.enabled="true"
        oob_thread_pool.min_threads="2"
        oob_thread_pool.max_threads="8"
        oob_thread_pool.keep_alive_time="5000"
        oob_thread_pool.queue_enabled="false"
        oob_thread_pool.queue_max_size="100"
        oob_thread_pool.rejection_policy="Run"/>

<!-- you need add initial hosts list in initial_hosts-->
   <TCPPING timeout="3000"
            initial_hosts="localhost[7800],localhost[7801]}"           
            port_range="5"
            num_initial_members="1"/>
<!-- use multicast here -->
   <!--<MPING bind_addr="127.0.0.1" break_on_coord_rsp="true"-->
   <!--mcast_addr="230.8.8.8" mcast_port="17890" ip_ttl="2"-->
   <!--num_initial_members="3"/>-->

   <MERGE2 max_interval="30000"
           min_interval="10000"/>
   <FD_SOCK/>
   <!--
       Note that this is an atypically short timeout and a small number of retries
       configured this way to speed up unit testing, since we know all nodes run in the same JVM
       and hence failure detections will be very quick.
          -->
   <FD timeout="3000" max_tries="3"/>
   <VERIFY_SUSPECT timeout="1500"/>
   <pbcast.NAKACK
         use_mcast_xmit="false" gc_lag="0"
         retransmit_timeout="300,600,1200,2400,4800"
         discard_delivered_msgs="false"/>
   <UNICAST timeout="300,600,1200"/>
   <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
                  max_bytes="400000"/>
   <pbcast.GMS print_local_addr="false" join_timeout="7000" view_bundling="true"/>
   <FC max_credits="2000000"
       min_threshold="0.10"/>
   <FRAG2 frag_size="60000"/>
   <pbcast.STREAMING_STATE_TRANSFER/>
   <!-- <pbcast.STATE_TRANSFER/> -->
   <pbcast.FLUSH timeout="0"/>
</config>

使用udp.xml


<config xmlns="urn:org:jgroups"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="urn:org:jgroups http://www.jgroups.org/schema/JGroups-2.8.xsd">
    <UDP
         mcast_port="${jgroups.udp.mcast_port:45555}"
         tos="8"
         ucast_recv_buf_size="20000000"
         ucast_send_buf_size="640000"
         mcast_recv_buf_size="25000000"
         mcast_send_buf_size="640000"
         loopback="false"
         discard_incompatible_packets="true"
         max_bundle_size="64000"
         max_bundle_timeout="30"
         ip_ttl="${jgroups.udp.ip_ttl:2}"
         enable_bundling="true"
         enable_diagnostics="true"
         thread_naming_pattern="cl"
         timer.num_threads="4"

         thread_pool.enabled="true"
         thread_pool.min_threads="2"
         thread_pool.max_threads="8"
         thread_pool.keep_alive_time="5000"
         thread_pool.queue_enabled="true"
         thread_pool.queue_max_size="10000"
         thread_pool.rejection_policy="discard"

         oob_thread_pool.enabled="true"
         oob_thread_pool.min_threads="1"
         oob_thread_pool.max_threads="8"
         oob_thread_pool.keep_alive_time="5000"
         oob_thread_pool.queue_enabled="false"
         oob_thread_pool.queue_max_size="100"
         oob_thread_pool.rejection_policy="Run"/>

    <PING timeout="2000"
            num_initial_members="3"/>
    <MERGE2 max_interval="30000"
            min_interval="10000"/>
    <FD_SOCK/>
    <FD_ALL/>
    <VERIFY_SUSPECT timeout="1500"  />
    <BARRIER />
    <pbcast.NAKACK use_stats_for_retransmission="false"
                   exponential_backoff="0"
                   use_mcast_xmit="true" gc_lag="0"
                   retransmit_timeout="300,600,1200"
                   discard_delivered_msgs="true"/>
    <UNICAST timeout="300,600,1200"/>
    <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000"
                   max_bytes="1000000"/>
    <pbcast.GMS print_local_addr="true" join_timeout="3000"

                view_bundling="true"/>
    <FC max_credits="500000"
                    min_threshold="0.20"/>
    <FRAG2 frag_size="60000"  />
    <!--pbcast.STREAMING_STATE_TRANSFER /-->
    <pbcast.STATE_TRANSFER  />
    <pbcast.FLUSH  />
</config>

tips:
大部分情况下tcp/udp的配置没有这么复杂,这两个是最复杂的例子,如果自己配置的话
 

<pbcast.FLUSHtimeout="0"/>是非常重要的,这个配置是告诉jgroups立即刷新而不是等待


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用Redis作为JBoss的Session共享存储,需要配置以下步骤: 1. 首先,在JBoss服务器上安装Redis服务器和相关的Java Redis客户端 2. 在JBoss服务器的standalone.xml文件中添加以下配置: ``` <subsystem xmlns="urn:jboss:domain:infinispan:6.0" default-cache-container="web" jndi-name="infinispan"> <cache-container name="web" jndi-name="infinispan/web"> <transport lock-timeout="60000"/> <distributed-cache name="sessions" mode="SYNC" segmented="false"> <expiration max-idle="1800000"/> <persistence passivation="false"> <file-store path="${jboss.server.temp.dir}/infinispan/web/sessions" /> </persistence> <partition-handling when-split="MERGE" merge-policy="REMOVE_ALL" /> <file-store /> <remote-store> <property name="hotrod-client-properties" value="hotrod-client.properties"/> <property name="remote-cache-name" value="sessions"/> <property name="raw-values" value="false"/> <property name="shared" value="true"/> <property name="preload" value="true"/> </remote-store> </distributed-cache> </cache-container> </subsystem> ``` 3. 新建一个hotrod-client.properties文件,内容如下: ``` infinispan.client.hotrod.server_list=redis_host:redis_port ``` 其中,redis_host是Redis服务器的地址;redis_port是Redis服务器的端口号。 4. 将hotrod-client.properties文件放在JBoss服务器的classpath下。 5. 在Web应用程序的web.xml文件中添加以下配置: ``` <session-config> <session-store-name>infinispan</session-store-name> <cookie-config> <path>/</path> </cookie-config> </session-config> ``` 6. 重新启动JBoss服务器,即可使用Redis作为Session共享存储。 注意: 多个JBoss服务器之间通过Redis共享Session时,需要保证Redis使用的是同一个实例。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值