Skip to content

Instantly share code, notes, and snippets.

@sohangp
sohangp / pom.xml
Created October 2, 2019 01:19
Embedded Debezium Dependency
....
<!-- Debezium dependencies -->
<dependency>
<groupId>io.debezium</groupId>
<artifactId>debezium-embedded</artifactId>
<version>${io.debezium.version}</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
@sohangp
sohangp / EventService.java
Created October 2, 2019 01:01
Event Service for writing outbox data.
@EventListener
public void handleOutboxEvent(OutboxEvent event) {
UUID uuid = UUID.randomUUID();
OutBoxEntity entity = new OutBoxEntity(
uuid,
event.getAggregateId(),
event.getEventType(),
event.getPayload().toString(),
new Date()
@sohangp
sohangp / StudentServiceImpl.java
Last active October 2, 2019 01:30
Student Service
@Transactional
public StudentDTO enrollStudent(EnrollStudentDTO student) throws Exception {
log.info("Enroll Student details for StudentId: {}", student.getName());
StudentEntity studentEntity = StudentMapper.INSTANCE.studentDTOToEntity(student);
studentRepository.save(studentEntity);
//Publish the event
event.fire(EventUtils.createEnrollEvent(studentEntity));
@sohangp
sohangp / docker-compose.yml
Last active October 2, 2019 17:23
Docker Compose for Embedded Debizium
version: "3.5"
services:
# Install postgres and setup the student database.
postgres:
container_name: postgres
image: debezium/postgres
ports:
- 5432:5432
environment:
@sohangp
sohangp / grand-daughters.sh
Last active June 20, 2019 15:41
Query All Grandparents who have grand-daughters
curl -X POST 'http://localhost:9200/family_tree/_search' \
-H 'content-type: application/json' \
-d '{
"query":{
"has_child":{
"type":"child",
"query":{
"has_child":{
"type":"grandchild",
"query":{
@sohangp
sohangp / insert_grandChildren.sh
Last active June 20, 2019 15:38
Insert GrandChildren
# Insert GrandChildren for the Fords
curl -X PUT \
'http://localhost:9200/family_tree/_bulk?routing=Darren' -H 'content-type: application/json' \
-d '
{"index": {"_type": "_doc", "_id": "14"}}
{"firstName":"Douglas", "lastName":"Ford", "gender":"Male", "isAlive":true, "relation_type":{ "name":"grandchild", "parent":"5" } }
'
# Insert GrandChildren for the Turners
curl -X PUT \
@sohangp
sohangp / grandChildren_Darren.sh
Last active June 20, 2019 15:42
Insert GrandChildren for Darren
curl -X PUT 'http://localhost:9200/family_tree/_doc/14?routing=Darren' \
-H 'content-type: application/json' \
-d '{
"firstName":"Douglas",
"lastName":"Ford",
"gender":"Male",
"isAlive":true,
"relation_type":{
"name":"grandchild",
"parent":"5"
@sohangp
sohangp / crandChild_index.sh
Last active June 20, 2019 15:30
Recreate Index with a GrandChild
curl -X PUT 'http://localhost:9200/family_tree' \
-H 'content-type: application/json' \
-d '{
"settings":{
...
},
"mappings":{
"properties":{
...
@sohangp
sohangp / parentsWithWife.sh
Last active June 20, 2019 15:25
Get the Parents who have a Wife
curl -X GET 'http://localhost:9200/family_tree/_search?pretty=true' \
-H 'content-type: application/json' \
-d '{
"query":{
"has_child":{
"type":"wife",
"query":{
"match_all": {}
}
}
@sohangp
sohangp / melissa.sh
Last active June 20, 2019 15:24
Insert Melissa Ford
curl -X PUT 'http://localhost:9200/family_tree/_doc/13?routing=Darren' \
-H 'content-type: application/json' \
-d '{
"firstName":"Melissa",
"lastName":"Ford",
"gender":"Female",
"isAlive":false,
"relation_type":{
"name":"wife",
"parent":"1"