Configuring Cassandra with Spring Boot using Kundera
2018-02-12 17:35
471 查看
转自
The Apache Cassandra database is the great choice when you need scalability and high adaptability without affecting performance.
As Cassandra is very scalable databse while working with springboot and its Benchmark Scalability was found on AWS was over a million writes per second.
Kundera is a “Polyglot Object Mapper” with a JPA interface. The thought behind Kundera is to influence working with NoSQL Databases to drop dead straightforward and fun. Kundera is being created with following goals:
To make working with NoSQL as straightforward as working with SQL
To fill in as JPA Compliant mapping answer for NoSQL Datastores.
To help engineers, to overlook the many-sided quality of NoSQL stores and concentrate on Domain Model.
To make exchanging crosswise over information stores as simple as changing an arrangement.
Configuration of Kundera with SpringBoot:
1.Add Maven Dependency in your pom.xml file:
2.Application Properties File:
3.Persistence.xml
4.Entity Class of Kundera
5.Create a key space for your application.
官方参考资料地址
The Apache Cassandra database is the great choice when you need scalability and high adaptability without affecting performance.
As Cassandra is very scalable databse while working with springboot and its Benchmark Scalability was found on AWS was over a million writes per second.
Kundera is a “Polyglot Object Mapper” with a JPA interface. The thought behind Kundera is to influence working with NoSQL Databases to drop dead straightforward and fun. Kundera is being created with following goals:
To make working with NoSQL as straightforward as working with SQL
To fill in as JPA Compliant mapping answer for NoSQL Datastores.
To help engineers, to overlook the many-sided quality of NoSQL stores and concentrate on Domain Model.
To make exchanging crosswise over information stores as simple as changing an arrangement.
Configuration of Kundera with SpringBoot:
1.Add Maven Dependency in your pom.xml file:
<dependency> <groupId>com.impetus.kundera.client</groupId> <artifactId>kundera-cassandra</artifactId> <version>3.10.1</version> </dependency> <dependency> <groupId>com.impetus.kundera.client</groupId> <artifactId>kundera-cassandra-ds-driver</artifactId> <version>3.10.1</version> </dependency> <dependency> <groupId>com.datastax.cassandra</groupId> <artifactId>cassandra-driver-core</artifactId> <version>3.3.0</version> </dependency> <dependency> <groupId>com.datastax.cassandra</groupId> <artifactId>cassandra-driver-mapping</artifactId> <version>3.3.0</version> </dependency> <dependency> <groupId>com.datastax.cassandra</groupId> <artifactId>cassandra-driver-extras</artifactId> <version>3.3.0</version> </dependency>
2.Application Properties File:
spring.data.cassandra.keyspace-name=KunderaExamples spring.data.cassandra.contact-points=localhost spring.data.cassandra.port= 9042 spring.data.cassandra.cluster-name=Test Cluster spring.data.cassandra.username=cassandra spring.data.cassandra.password=cassandra
3.Persistence.xml
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="cassandra_pu"> <provider>com.impetus.kundera.KunderaPersistence</provider> <!-- <class>com.paritytrading.parity.client.domain.User</class> --> <class>com.paritytrading.parity.client.domain.UserOrder</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> <properties> <property name="kundera.nodes" value="127.0.0.1" /> <property name="kundera.port" value="9042" /> <property name="kundera.keyspace" value="KunderaExamples" /> <property name="kundera.dialect" value="cassandra" /> <property name="kundera.ddl.auto.prepare" value="create" /> <property name="kundera.client.lookup.class" value="com.impetus.kundera.client.cassandra.dsdriver.DSClientFactory" /> </properties> </persistence-unit> </persistence>
4.Entity Class of Kundera
@Entity @Table(name ="UserOrder", schema = "KunderaExamples@cassandra_pu") public class UserOrder implements Serializable { private static final long serialVersionUID = 8020522006409395867L; @Id @GeneratedValue(strategy = GenerationType.TABLE) @PrimaryKey private Integer id; @Column(nullable = false) private Integer userId; @Column(nullable = false, unique = true) private String orderId; @Column(nullable = false) @Enumerated(EnumType.STRING) private OrderType orderType; @Column(nullable = false) private Integer quantity; @Column(nullable = false) private String instrument; @Column(nullable = false) private Integer price; @Column(nullable = false) @Enumerated(EnumType.STRING) private OrderStatus orderStatus = OrderStatus.OPEN; @Column(nullable = false) private Boolean isLimitOrder = false; public String getOrderId() { return orderId; } public Integer getUserId() { return userId; } public void setUserId(Integer userId) { this.userId = userId; } public void setOrderId(String orderId) { this.orderId = orderId; } public OrderType getOrderType() { return orderType; } public void setOrderType(OrderType orderType) { this.orderType = orderType; } public String getInstrument() { return instrument; } public void setInstrument(String instrument) { this.instrument = instrument; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Integer getQuantity() { return quantity; } public void setQuantity(Integer integer) { this.quantity = integer; } public Integer getPrice() { return price; } public void setPrice(Integer price) { this.price = price; } public OrderStatus getOrderStatus() { return orderStatus; } public void setOrderStatus(OrderStatus orderStatus) { this.orderStatus = orderStatus; } public static long getSerialversionuid() { return serialVersionUID; } public Boolean getIsLimitOrder() { return isLimitOrder; } public void setIsLimitOrder(Boolean isLimitOrder) { this.isLimitOrder = isLimitOrder; } @Override public String toString() { return "{ userId : " + userId + ", orderId : " + orderId + ", orderType : " + orderType + ", quantity : " + quantity + ", instrument : " + instrument + ", price : " + price + ", orderStatus : " + orderStatus + ", isLimitOrder : " + isLimitOrder + "}"; } }
5.Create a key space for your application.
CREATE KEYSPACE KeySpaceName WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : ReplicationFactor};
官方参考资料地址
相关文章推荐
- Spring Boot 之 Accessing Relational Data using JDBC with Spring
- SPRING BOOT: USING JODA TIME ON JPA ENTITY WITH HIBERNATE
- Scalable, Distributed Systems Using Akka, Spring Boot, DDD, and Java--转
- spring data with cassandra
- 关于spring.net的面向切面编程 (Aspect Oriented Programming with Spring.NET)-使用工厂创建代理(Using the ProxyFactoryObject to create AOP proxies)
- Developing JSF applications with Spring Boot
- 【Spring-boot多数据库】Spring-boot JDBC with multiple DataSources sample
- PART 5: INTEGRATING SPRING SECURITY WITH SPRING BOOT WEB
- Using JWT with Spring Security OAuth
- Creating a REST API with Spring Boot and MongoDB
- Spring boot @Qualifier doesn't work with datasources
- How to use JDBC-Authentication of Spring Boot/Spring Security with Flyway
- Microservices with Spring Boot
- SpringBoot UnsatisfiedDependencyException: Error creating bean with name
- Spring Boot with JSP and Tiles3
- Spring Boot 项目构建 之 使用 Spring Boot 构建应用(Building an Application with Spring Boot)
- Using JWT with Spring Security OAuth
- Using Spring Boot without the parent POM
- spring boot 项目 redis启动报错 Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer'
- springBoot with cxf