Apache Ignite Series (i): Introduction

Source: Internet
Author: User
Tags gemfire apache ignite

Apache-ignite Introduction (i) 1, Introduction

? Ignite is a distributed memory grid implementation, based on the Java platform, with the characteristics of persistence, distributed transactions, distributed computing, in addition to support rich key-value storage and SQL syntax (based on the H2 engine), can be seen as a distributed memory database.

Products similar to ignite have GemFire (12306 currently in use) and the open source version is Geode. Compared with GemFire, ignite support for SQL is perfect, provides data to be collocated to improve performance, as well as the support of distributed things and the integration of spring is relatively friendly, it is convenient for embedded integration into the application services.

2, basic use

? There are two ways to use ignite: one is to download release version from the official website, unzip the run deployment, and the other is to integrate into the existing application through embedded.

2.1, the use of the official website binary release version

: https://ignite.apache.org/download.cgi

After download apache-ignite-fabric-2.3.0-bin.zip , get the compressed package, unzip it into the bin path:

Mainly used in two scripts: ignite.bat startup script, ignitevisorcmd.bat monitoring script

Execute ignite.bat script to start a ignite service

Execution ignitevisorcmd.bat can enter the monitoring command interface:

Enter open a command to select the configuration file, where 0 | config\default-config.xml you can select the default input number 0

Common commands are as follows:

Command function
Top View Cluster network topology diagram
Cache View Overall Cache condition
Config View node Configuration
Open Open a configuration file to connect to the cluster
Close Close the connection

More detailed commands can be viewed by entering the help command to see the command assistance (enter the assist return).

2.2,java Services use Ignite clients to access ignite clusters

? Using a ignite cluster that has been started by the Java service, theJava service can use the client mode, the application side does not store the data, or use the server-side mode to become a node to join an existing ignite cluster, the application side caches part of the data . If the service-side mode is used, the whole cluster can actually use the application node to form the cluster, which is the embedded integration mentioned above. This allows the node to be customized and more flexible.

Here is a demonstration of simple use using the client mode:

1) Adding dependent dependencies

        <dependency>            <groupId>org.apache.ignite</groupId>            <artifactId>ignite-core</artifactId>            <version>2.3.0</version>        </dependency>        <dependency>            <groupId>org.apache.ignite</groupId>            <artifactId>ignite-spring</artifactId>            <version>2.3.0</version>        </dependency>

2) define the configuration file

default-config.xml

<beans xmlns= "Http://www.springframework.org/schema/beans" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance "xmlns:util=" Http://www.springframework.org/schema/util "xsi:schemalocation=" http:/ /www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd HTTP://WW W.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd "> <bean id=" I Gnitecfg "class=" org.apache.ignite.configuration.IgniteConfiguration "> <property name=" Clientmode "value=" tr UE "/> <property name=" Discoveryspi "> <bean class=" Org.apache.ignite.spi.discovery.tcp.TcpDis Coveryspi "> <property name=" localport "value=" 48500 "/> <property name=" LocalPort Range "value="/> <property name= "Ipfinder" > <bean class= "org.apache.ignit E.spi.discovery.tcp.ipfinder.vm.tcpdiscoveryvMipfinder "> <property name=" Addresses "> <list>                        <value>127.0.0.1:48500..48520</value> </list>        </property> </bean> </property> </bean> </property> <property name= "Communicationspi" > <bean class= "Org.apache.ignite.spi. Communication.tcp.TcpCommunicationSpi "> <property name=" localport "value=" 48100 "/> < /bean> </property> </bean></beans>

3) Start Ignite client and implement simple data access

ClientStartApplication.java

@SpringBootApplication@ImportResource(locations={"classpath:default-config.xml"}) //ignite配置文件路径public class ClientStartApplication implements CommandLineRunner {    @Autowired    private IgniteConfiguration igniteCfg;    public static void main(String[] args) {        SpringApplication.run(ClientStartApplication.class,args);    }      /**启动完成之后执行初始化*/    @Override    public void run(String... strings) {        //启动ignite服务        Ignite ignite = Ignition.start(igniteCfg);        //创建cache        IgniteCache<String, String> cache =  ignite.getOrCreateCache("test");        //存入数据        cache.put("cord",  "hello");        //查询数据        System.out.format("key[%s]->value[%s]\n", "cord", cache.get("cord"));    }}

The results of the implementation are as follows:

[15:46:44] Ignite node started OK (id=48cfd9ce)[15:46:44] Topology snapshot [ver=30, servers=1, clients=1, CPUs=4, heap=2.7GB]key[cord]->value[hello]

By ignitevisorcmd.bat viewing the current cluster status and cache conditions:

visor> cache(wrn) <visor>: No caches found.(wrn) <visor>: Type ‘help cache‘ to see how to use this command.

The result is that there is no data, this is because the default config\default-config.xml configuration is empty, the execution of the ignite.bat startup service Although the file is used, but because there is a default value, so it does not affect, but the monitor ignitevisorcmd.bat must be based on the configuration file to access the cluster information, so modify config\default-config.xml the following as follows :
(This is actually removed from the above default-config.xml <property name="clientMode" value="true"/> )

<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.SPRINGFR Amework.org/schema/beans/spring-beans.xsd "> <bean id=" grid.cfg "class=" org.apache.ignite.configuration.Ign Iteconfiguration "> <property name=" Discoveryspi "> <bean class=" org.apache.ignite.spi.discove Ry.tcp.TcpDiscoverySpi "> <property name=" localport "value=" 48500 "/> <property na Me= "Localportrange" value= "/> <property name=" Ipfinder "> <bean class=" org . Apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder "> <property name=" Address Es "> <list> <value>127.0.0.1:48500..48520</val Ue> </list&Gt </property> </bean> </property> </bean> </p roperty> <property name= "Communicationspi" > <bean class= "org.apache.ignite.spi.communication . TCP. Tcpcommunicationspi "> <property name=" localport "value=" 48100 "/> </bean> & Lt;/property> </bean> </beans>

And then reboot ignitevisorcmd.bat and open modify the following config\default-config.xml :

To execute a top command, you can see that the type of two nodes is different:

visor> topHosts: 1+=================================================|  Int./Ext. IPs  |   Node ID8(@)    | Node Type |+=================================================| 0:0:0:0:0:0:0:1 | 1: 875F3FCF(@n0) | Server    || 10.118.144.74   | 2: 48CFD9CE(@n1) | Client    || 127.0.0.1       |                  |           |+-------------------------------------------------

To execute the cache command, you can see the information that was created in the code named test cache:

visor> cacheTime of the snapshot: 08/03/18, 16:20:35+==============================================================|  Name(@)  |    Mode     | Nodes | Entries (Heap / Off-heap) |+==============================================================| test(@c0) | PARTITIONED | 2     | min: 0 (0 / 0)            ||           |             |       | avg: 0.50 (0.00 / 0.50)   ||           |             |       | max: 1 (0 / 1)            |+--------------------------------------------------------------
2.3, Java service Integration Ignite as a service node

Just change the configuration file in the Java project to default-config.xml <property name="clientMode" value="true"/>

<property name="clientMode" value="false"/>becomes the service node mode, so that the node can also store data.

After startup, the Java service output is as follows:

[00:08:45] Topology snapshot [ver=7, servers=2, clients=0, CPUs=4, heap=2.8GB]

There is an increase in the number of visible servers, indicating that the service node started successfully, so ignite profile ends.

For a complete sample code, please refer to:

Https://github.com/cording/ignite-example

Apache Ignite Series (i): Introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.