Skip to content

hazelcast-demos/pet-clinic-index-job

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 

Pet Clinic Index Job

Source code for Enabling Full-text Search with Change Data Capture in a Legacy Application blog post.

How to

Follow these instructions to run the Spring Petclinic application and the PetClinicIndexJob:

Start MySQL database:

docker run --name petclinic-mysql -it \
  -e MYSQL_DATABASE=petclinic \
  -e MYSQL_USER=petclinic \
  -e MYSQL_PASSWORD=petclinic \
  -e MYSQL_ROOT_PASSWORD=mysql \
  -p 3306:3306 mysql

Start MySQL client (enter mysql password for root user):

docker run -it --rm --link petclinic-mysql:petclinic-mysql mysql mysql -hpetclinic-mysql -uroot -p

Grant privileges for change data capture:

ALTER USER petclinic IDENTIFIED WITH mysql_native_password BY 'petclinic';
GRANT RELOAD ON *.* TO 'petclinic';
GRANT REPLICATION CLIENT ON *.* TO 'petclinic';
GRANT REPLICATION SLAVE ON *.* TO 'petclinic';

Start Elasticsearch

docker run --name petclinic-elastic \
  -e discovery.type=single-node \
  -e cluster.routing.allocation.disk.threshold_enabled=false \
  -p9200:9200 elasticsearch:7.9.2

Create an Elasticsearch index mapping:

curl -XPUT -H "Content-type: application/json" -d '
{
  "mappings": {
    "properties": {
      "first_name": {
        "type": "text",
        "copy_to": "search"
      },
      "last_name": {
        "type": "text",
        "copy_to": "search"
      },
      "pets.name": {
        "type": "text",
        "copy_to": "search"
      },
      "pets.visits.keywords": {
        "type": "text",
        "copy_to": "search"
      },
      "search": {
        "type": "text"
      }
    }
  }
}' http://localhost:9200/petclinic-index

Clone the Spring Petclinic repository and checkout elasticsearch branch:

git clone https://github.com/hazelcast-demos/spring-petclinic.git
git checkout elasticsearch

Run the Petclinic application:

cd spring-petclinic
./mvnw spring-boot:run -Dspring-boot.run.profiles=mysql

Clone the PetClinicIndexJob repository:

git clone https://github.com/hazelcast-demos/pet-clinic-index-job.git

Build the jar:

cd pet-clinic-indexing-job
mvn package

(Option 1) Run the job (embedded, without submitting to a cluster)

mvn exec:java -Pstandalone

(Option 2) Submit the job to a cluster (you need to have modules elasticsearch-7, cdc-debezium and cdc-mysql enabled - copy the jars from opt to lib folder):

bin/jet submit \
path/to/pet-clinic-index-job/target/pet-clinic-index-job-1.0-SNAPSHOT-jar-with-dependencies.jar\
   --database-address localhost \
   --database-port 3306 \
   --database-user petclinic \
   --database-password petclinic \
   --elastic-host localhost:9200 \
   --elastic-index petclinic-index

About

Source code example for Enabling Full-text Search with Change Data Capture blog post.

Topics

Resources

Stars

Watchers

Forks

Languages