Giter VIP home page Giter VIP logo

quartz-cluster-demo's Introduction

Quartz Cluster Demo

Features of this Demo

  • show usage of Spring Boot and the Quartz-Scheduler
  • enable cluster mode for Quartz Jobs in Spring Boot
  • Provide docker-compose file to start a realistic cluster
  • use PostgreSQL to demonstrate JDBC Store and concurrent job execution

Source of Quartz Database Script for Postgres

This demo uses Flyway to populate the database. Including the Quartz required tables mean you need to make Flyway aware of those scripts. In the demo we copied it. It's source:

Quartz Postgres Scripts

quartz-2.3.2.jar!/org/quartz/impl/jdbcjobstore/tables_postgres.sql

Running the Demo

Start Single Instance (Development)

If you just run the QuartzDemoApplication.kt Spring-Boot Application you need to start the database first, using run-postgres.sh

Open localhost to view the state of the application.

Start Cluster Demo with Docker-Compose

The docker-compose.yaml allows you to spin up the database and 3 instances of the quartz-demo application.

You need to build the image first mvn cerify

and then use docker-compose up -d to start the cluster.

You can browse each instance by itself or open /frames which will create a page with 3 iframes showing each instance side-by-side.

Quartz Cron Help

Learn and Observe

Every instance of the application will start with two properties:

INST_NAME: "anyNumer-somename"
INST_WAITMILLIS: 25000

INST_NAME is used to identify the instance of the application in the cluster - it is used for logging and creating the Job keys and information.

INST_WAITMILLIS is used to allow every instance of the application to execute the Jobs slower than other nodes - if you want to play around with overlapping job execution times.

Watch out for the concurrent jobs (the might just run several times, even on the same node - especially if the jobs overlap - meaning they execute faster than they complete, so the next execution starts before the last one finished). A different behaviour is shown with the non-concurrent variation of the job (look out for the DisallowConcurrentExecution annotation!)

You can still use the Scheduled annotation from spring - but be aware that all instances will run them (might still be useful for some use-cases).

If you pause the scheduler, this will only affect that one instance of the application. The others still run.

To stop all processing you can stop all the triggers - this will affect the whole cluster.

JobListener only fire on the instance that was executing the job as well.

The Order66 Button creates an order (not a Quartz feature, it is meant to represent some sort of item that needs processing). With every order there is also a quartz job and trigger created. The Job execution is then distributed within the cluster by quartz.

Alternatives to Quartz Scheduler

There are options if the quartz scheduler cannot be used.

quartz-cluster-demo's People

Contributors

wemu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.