Building restful Web Services with spring boot to access storage in aerospike clusters

Source: Internet
Author: User
Tags command line web services xmlns aerospike

Spring Boot is a powerful tool for spring QuickStart. Spring boot can help you easily build applications based on spring. Aerospike is a distributed and replicable memory database optimized for either DRAM or native flash/ssd,aerospike. Aerospike is highly reliable and follows acid. Developers can quickly extend a database cluster from two nodes to 20 nodes without stopping the database service.

What are you going to build?

This article will guide you through the use of spring boot to create a simple restful Web service. The service to be built accepts an HTTP GET request. Its response is the following JSON:

{"Expiration": 121023390, "bins":

{"DISTANCE": 2446, "Dest_city_name": "New 
York, "DEST": "JFK", "Year": "ori_airport_id"

: "14679", "Dep_time": "The"
, "Day_of_month": "," dest_ State_abr ":" NY ","

ORIGIN ":" SAN "," Fl_num "
: 160," CARRIER ":" AA "," Ori_state_abr ":" CA "," Fl_da

TE ":" 2012 /01/12 ",
" Air_time ": 291," Ori_city_name ":" San 

Diego "," Elapsed_time ": 321,
" arr_time ":" 1623 "," airline_id ": 19805}," Generation ": 1

}

The data used here are commercial flight details (included in the sample code, this is a data file called Flights_from.csv, which contains about 1 million flight information).

In a production (or other) environment, there are many built-in features added to the application to manage the service. This feature comes from spring, see Spring Guidance: Building a RESTful Web service.

What are you looking for?

A favorite text editor or IDE

JDK 7 or later

Maven 3.0+

Aerospike Java SDK 3.0+

Build the Project

When building an application, you can use any building system you like, but here's the code for MAVEN. If you are unfamiliar with Maven, refer to the Spring Guide: Building Java Projects with maven.

You will also need to build and install Aerospike Java clients into the local MAVEN repository. Download the source release version, Unzip/untar it and run the following MAVEN command:

MVN install:install-file-dfile=client/depends/gnu-crypto.jar-dgroupid=org.gnu-dartifactid=gnu-crypto-dversion= 2.0.1-dpackaging=jar

MVN clean

MVN Package

Create a directory structure

In the project you selected, create the subdirectory structure as shown below:

->SRC->main->java->com->aerospike->client

Create Maven's Pom file

Create a Maven pom.xml in the root of the project with the following code:

<?xml version= "1.0" encoding= "UTF-8"?> <project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "http ://www.w3.org/2001/XMLSchema-instance "xsi:schemalocation=" http://maven.apache.org/POM/4.0.0 http:// Maven.apache.org/xsd/maven-4.0.0.xsd "> <modelVersion>4.0.0</modelVersion> <groupid>com.ae Rospike</groupid> <artifactId>aerospike-restful-example</artifactId> <version>1.0.0&lt ;/version> <parent> <groupId>org.springframework.boot</groupId> <artifactid&gt ;spring-boot-starter-parent</artifactid> <version>0.5.0.M4</version> </parent> &
            Lt;dependencies> <dependency> <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupid>org.springframework.bOot</groupid> <artifactId>spring-boot-starter-actuator</artifactId> </dependency&
            Gt <!--aerospike client. --> <dependency> <groupId>com.aerospike</groupId> <artifactid&
        Gt;aerospike-client</artifactid> <version>3.0.9</version> </dependency> <!--Apache command line parser. --> <dependency> <groupId>commons-cli</groupId> <artifactid&gt ;commons-cli</artifactid> <version>1.2</version> </dependency> </depend encies> <properties> <start-class>com.aerospike.client.rest.aerospikerestfulservice </start-cla ss> </properties> <build> <plugins> <plugin> <artifactid >maven-compiler-plugin</artifactId> <version>2.3.2</version> </plugin> <plugin> <groupid>org.spri Ngframework.boot</groupid> <artifactId>spring-boot-maven-plugin</artifactId> ;/plugin> </plugins> </build> <repositories> <repository> <id>s pring-snapshots</id> <name>spring snapshots</name> <url>http://repo.spring.io/ libs-snapshot</url> <snapshots> <enabled>true</enabled> </sna
          pshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>spring-snapshots</id> <name>spring snapshots</name> <url>h Ttp://repo.spring.io/libs-snapshot</url> <snapshots> &LT;ENABLED&GT;TRUE&LT;/ENABLED&G
          T </snapshots> </pluginRepository> </pluginRepositories> </project> 

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.