잡동사니
[Spring] Cassandra 연동 및 Insert 본문
안녕하세요. yeTi입니다.
오늘은 Spring에서 Cassandra를 연동해보려고 합니다.
설치 환경
- Spring Boot : 1.5.4.RELEASE
- Mybatis : 1.3.2
1. Cassandra의 SDK를 설치합니다. (저는 Gradle 활용)
- compile group: 'com.datastax.cassandra', name: 'cassandra-driver-core', version: '3.5.1'
compile group: 'com.datastax.cassandra', name: 'cassandra-driver-mapping', version: '3.5.1'
compile group: 'com.datastax.cassandra', name: 'cassandra-driver-extras', version: '3.5.1'
2. Mapper Object를 생성합니다.
- @Table(keyspace = "[Keyspace 명]", name = "[Table 명]",
readConsistency = "QUORUM",
writeConsistency = "QUORUM",
caseSensitiveKeyspace = false,
caseSensitiveTable = false)
public class TestVO {
@PartitionKey
@Column(name = "storySeq")
private int storySeq;
@Column(name = "type")
private String type;
}
2. Cassnadra API를 사용합니다.
- PoolingOptions poolingOptions = new PoolingOptions();
Cluster cluster = null;
try {
cluster = Cluster.builder()
.addContactPoint("[서버 IP 주소]")
.withPoolingOptions(poolingOptions)
.build();
Session session = cluster.connect("[Keyspace]");
MappingManager manager = new MappingManager(session);
Mapper<TestVO> mapper = manager.mapper(TestVO.class);
TestVO testVO= new TestVO();
testVO.setStorySeq(123);
testVO.setType("test");
mapper.save(testVO);
} finally {
if (cluster != null) cluster.close();
}
'IT > Java' 카테고리의 다른 글
[Spring Boot] Scheduled 어노테이션 활용하기 (0) | 2018.11.12 |
---|---|
[Spring] Cassandra CodecNotFoundException: Codec not found for requested operation: [timestamp <-> java.sql.Timestamp] 해결 (0) | 2018.08.30 |
[Spring] AOP기반 SQL Logging (4) | 2018.08.08 |
[SimpleDateFormat] java.lang.NumberFormatException 처리하기 (0) | 2018.08.01 |
[Spring] Spring Boot에서 HikariCP Datasource 연동하기 (0) | 2018.07.19 |