page_type | languages | products | description | urlFragment | ||
---|---|---|---|---|---|---|
sample |
|
|
This sample shows how to use Spring Data Apache Cassandra module with Azure CosmosDB service. |
spring-data-cassandra-on-azure |
This sample shows how to use Spring Data Apache Cassandra module with Azure CosmosDB service.
- Azure Account
- JDK 1.8 or above
- Maven 3.0 or above
- Curl
-
Create a Cassandra account with Azure CosmosDB by following tutorial at here.
-
Use Data Explorer from Azure Portal to create a keyspace named
mykeyspace
. -
Find
application.properties
atsrc/main/resources
and fill in below properties.spring.data.cassandra.contact-points=<replace with your Cassandra contact point> #spring.data.cassandra.local-datacenter=<this is only required if not using custom load balancing policy> spring.data.cassandra.port=10350 spring.data.cassandra.username=<replace with your Cassandra account user name> spring.data.cassandra.password=<replace with your Cassandra account password>
-
Build the sample application into a
JAR
package by running below command.mvn clean package
Following below steps to run and test the sample application.
-
Run application.
java -jar target/spring-data-cassandra-on-azure-0.1.0-SNAPSHOT.jar
-
Create new users by running below command.
curl -s -d '{"name":"Tom","species":"cat"}' -H "Content-Type: application/json" -X POST http://localhost:8080/pets curl -s -d '{"name":"Jerry","species":"mouse"}' -H "Content-Type: application/json" -X POST http://localhost:8080/pets
Sample output is as below.
Added Pet(id=1, name=Tom, species=cat). ... Added Pet(id=2, name=Jerry, species=mouse).
-
Get all existing pets by running below command.
curl -s http://localhost:8080/pets
Sample output is as below.
[{"id":1,"name":"Tom","species":"cat"},{"id":2,"name":"Jerry","species":"mouse"}]