2014年8月15日星期五

JDG_005:JDG 6.3 Quick Start 例子学习:Football

运行环境:JBoss Data Grid 6.3.0

Football运行在remote client-server 模式下,展示了如何使用Hot Rod、Memcached、Rest客户端来访问Cache。

学习重点:

1. 配置Cache
(1)配置datasource
<subsystem xmlns="urn:jboss:domain:datasources:1.1">
            <!-- Define this Datasource with jndi name java:jboss/dataso urces/ExampleDS -->
            <datasources>
                <datasource jndi-name="java:jboss/datasources/ExampleDS"
                            pool-name="ExampleDS" enabled="true" use-java-context="true">
                    <!-- The connection URL uses H2 Database Engine with in-memory database called test -->
                    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
                    <!-- JDBC driver name -->
                    <driver>h2</driver>
                    <!-- Credentials -->
                    <security>
                        <user-name>sa</user-name>
                        <password>sa</password>
                    </security>
                </datasource>
                <!-- Define the JDBC driver called 'h2' -->
                <drivers>
                    <driver name="h2" module="com.h2database.h2">
                        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                    </driver>
                </drivers>
            </datasources>        
      </subsystem>

(2)配置Cache
        <subsystem xmlns="urn:infinispan:server:core:6.1" default-cache-container="local">
            <cache-container name="local" default-cache="default" statistics="true">
                <local-cache name="default" start="EAGER">
                    <locking isolation="NONE" acquire-timeout="30000" concurrency-level="1000" striping="false"/>
                    <transaction mode="NONE"/>
                </local-cache>
                <local-cache name="memcachedCache" start="EAGER" statistics="true">
                    <locking isolation="NONE" acquire-timeout="30000" concurrency-level="1000" striping="false"/>
                    <transaction mode="NONE"/>
                </local-cache>
                <local-cache name="namedCache" start="EAGER" statistics="true"/>
                <!-- ADD a local cache called 'teams' -->
                <local-cache name="teams" start="EAGER"
                             batching="false" statistics="true">
                    <!-- Disable transactions for this cache -->
                    <transaction mode="NONE" />
                    <!-- Define the JdbcBinaryStores to point to the ExampleDS previously defined -->
                    <string-keyed-jdbc-store datasource="java:jboss/datasources/ExampleDS" passivation="false"
                                             preload="false" purge="false">
                        <!-- Define the database dialect -->
                        <property name="databaseType">H2</property>
                        <!-- specifies information about database table/column names and data types -->
                        <string-keyed-table prefix="JDG">
                            <id-column name="id" type="VARCHAR"/>
                            <data-column name="datum" type="BINARY"/>
                            <timestamp-column name="version" type="BIGINT"/>
                        </string-keyed-table>
                    </string-keyed-jdbc-store>
                </local-cache>
                <!-- End of local cache called 'teams' definition -->
            </cache-container>
            <cache-container name="security"/>
</subsystem>

可以看出,Hot Rod 和 REST endpoints 使用名为teams的Cache,而memcached endpoint默认使用memcachedCache。

(3)配置rest-connector,去掉认证
 <subsystem xmlns="urn:infinispan:server:endpoint:6.1">
            <hotrod-connector socket-binding="hotrod" cache-container="local">
                <topology-state-transfer lazy-retrieval="false" lock-timeout="1000" replication-timeout="5000"/>
            </hotrod-connector>
            <memcached-connector socket-binding="memcached" cache-container="local"/>
            <rest-connector virtual-server="default-host" cache-container="local" />
 </subsystem>

2. 启动JBoss Data Grid 6.3
(1)cd /Users/maping/Redhat/Datagrid/jboss-datagrid-6.3.0-server/bin
(2)./standalone.sh -c standalone-football.xml

3. 运行客户端
分别进入hotrod-endpoint、memcached-endpoint、rest-endpoint,然后执行:mvn exec:java

没有评论: