我们一直使用Hazelcast作为Hibernate L2缓存提供程序,用于我们的应用程序,使用相同的数据库,并部署为两个不同的Web应用程序。
webApp1.war:使用DB1
webApp2.war:使用DB1
两个Web应用程序的hazelcast配置与:
相同 <multicast enabled="true">
<multicast-group>224.2.2.3</multicast-group>
<multicast-port>54327</multicast-port>
</multicast>
两个网络应用的组名和密码也相同。
Hazelcast将它们添加到具有不同节点的群集中,这在Hazelcast的管理中心也是可见的。
Hazelcast为这些网络应用为同一个数据库实体创建了两个不同的地图。因此,对于例如如果实体“用餐”由“webApp1”更新,则不会反映在“webApp2”中。
管理中心显示,它为“餐”创建了两个不同的地图,即webApp1.war:meal和webApp2.war:meal
您能否建议使用多播,如何在同一群集中为两个不同的Web应用程序使用相同的L2缓存。
编辑 - 1: Hibernate配置 - Persistence.xml
<jta-data-source>java:jboss/datasources/mealsDS</jta-data-source>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="hibernate.connection.pool_size" value="1" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.region.factory_class" value="com.hazelcast.hibernate.HazelcastCacheRegionFactory"/>
</properties>
</persistence-unit>
Hazelcast配置 - Hazelcast.xml(类似于hazelacast.jar中提供的)
<group>
<name>local</name>
<password>local-pass</password>
</group>
<management-center enabled="true">http://localhost:8080/mancenter
</management-center>
<network>
<port auto-increment="true" port-count="100">5701</port>
<outbound-ports>
<ports>0</ports>
</outbound-ports>
<join>
<multicast enabled="true">
<multicast-group>224.2.2.3</multicast-group>
<multicast-port>54327</multicast-port>
</multicast>
<tcp-ip enabled="false">
<interface>127.0.0.1</interface>
</tcp-ip>
<aws enabled="false">
<access-key>my-access-key</access-key>
<secret-key>my-secret-key</secret-key>
<region>us-west-1</region>
<host-header>ec2.amazonaws.com</host-header>
<security-group-name>hazelcast-sg</security-group-name>
<tag-key>type</tag-key>
<tag-value>hz-nodes</tag-value>
</aws>
</join>
<interfaces enabled="false">
<interface>10.10.1.*</interface>
</interfaces>
<ssl enabled="false" />
<socket-interceptor enabled="false" />
<symmetric-encryption enabled="false">
<algorithm>PBEWithMD5AndDES</algorithm>
<salt>thesalt</salt>
<password>thepass</password>
<iteration-count>19</iteration-count>
</symmetric-encryption>
</network>
<partition-group enabled="false" />
<executor-service name="default">
<pool-size>16</pool-size>
<queue-capacity>0</queue-capacity>
</executor-service>
<queue name="default">
<max-size>0</max-size>
<backup-count>1</backup-count>
<async-backup-count>0</async-backup-count>
<empty-queue-ttl>-1</empty-queue-ttl>
</queue>
<map name="default">
<in-memory-format>BINARY</in-memory-format>
<backup-count>1</backup-count>
<async-backup-count>0</async-backup-count>
<time-to-live-seconds>0</time-to-live-seconds>
<max-idle-seconds>0</max-idle-seconds>
<eviction-policy>NONE</eviction-policy>
<max-size policy="PER_NODE">0</max-size>
<eviction-percentage>25</eviction-percentage>
<min-eviction-check-millis>100</min-eviction-check-millis>
<merge-policy>com.hazelcast.map.merge.PutIfAbsentMapMergePolicy
</merge-policy>
</map>
<multimap name="default">
<backup-count>1</backup-count>
<value-collection-type>SET</value-collection-type>
</multimap>
<multimap name="default">
<backup-count>1</backup-count>
<value-collection-type>SET</value-collection-type>
</multimap>
<list name="default">
<backup-count>1</backup-count>
</list>
<set name="default">
<backup-count>1</backup-count>
</set>
<jobtracker name="default">
<max-thread-size>0</max-thread-size>
<queue-size>0</queue-size>
<retry-count>0</retry-count>
<chunk-size>1000</chunk-size>
<communicate-stats>true</communicate-stats>
<topology-changed-strategy>CANCEL_RUNNING_OPERATION
</topology-changed-strategy>
</jobtracker>
<semaphore name="default">
<initial-permits>0</initial-permits>
<backup-count>1</backup-count>
<async-backup-count>0</async-backup-count>
</semaphore>
<serialization>
<portable-version>0</portable-version>
</serialization>
<services enable-defaults="true" />
答案 0 :(得分:1)
通过在my中设置属性解决了这个问题 的persistence.xml
<property name="hibernate.cache.region_prefix" value="myApp"/>
如果未设置此属性,则会限制hibernate将应用程序名称附加到内存中创建的地图,因此对于这两个Web应用程序,只有一个地图存在,无论他们是否使用相同的数据库。