Code Monkey home page Code Monkey logo

spring-boot-quartz-scheduler's Introduction

Spring Boot Quartz Scheduler Example

I forked this repository which was using REST call to schedule email. I did not need to send email. Instead I needed to trigger an event ( logger ).

I have also extended the project with CRON scheduler, which I needed for my current work project.

Requirements

  1. Java - 1.8.x, Java 11

  2. Maven - 3.x.x

  3. MySQL - 5.x.x

Steps to Setup

1. Clone the application

2. Create MySQL database

There is a docker-compose.yml in docker directory. You can use it to start mysql.

create database quartz_demo

3. Change MySQL username and password as per your MySQL installation

open src/main/resources/application.properties, and change spring.datasource.username and spring.datasource.password properties as per your mysql installation

Make sure you set port correctly. I have different from default as my machine had both installed MySQL and Docker version

4. Create Quartz Tables

The project stores all the scheduled Jobs in MySQL database. You'll need to create the tables that Quartz uses to store Jobs and other job-related data. Please create Quartz specific tables by executing the quartz_tables.sql script located inside src/main/resources directory.

mysql> source <PATH_TO_QUARTZ_TABLES.sql>

6. Build and run the app using maven

Finally, You can run the app by typing the following command from the root directory of the project -

mvn spring-boot:run

Application contains build in cron job which logs the even every 15 seconds.

Scheduling an Event using the /scheduleJob API

curl -X POST \
  http://localhost:8081/scheduleJob \
  -H 'Accept: */*' \
  -H 'Content-Type: application/json' \
  -H 'Cookie: JSESSIONID=32A02F6E2D185C8702E7BA6016A913E3' \
  -H 'Host: localhost:8081' \
  -d '{
	"dateTime": "2019-10-02T15:14:00",
	"timeZone": "America/Los_Angeles"
}'

# Output
{
    "success": true,
    "jobId": "38aace30-ccf8-4c25-bca8-25f0f58b3c2a",
    "jobGroup": "rest-jobs",
    "message": "Scheduled Successfully!"
}

7. Running SpringBoot Quartz with MSSQL Server

Run MSSQL as docker: docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=2019October$$$' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest

Create database quartz_schema in MSSQL server

Run DDL script tables_sqlServer.sql provided with quartz jar file.

Add dependency to gradle ( or maven ) to import the driver: compile group: 'com.microsoft.sqlserver', name: 'mssql-jdbc', version: '8.1.0.jre11-preview'

Change application.yml to connect to database:

  datasource:
    password: 2019October$$$
    url: jdbc:sqlserver://localhost:1433;database=quartz_schema;SelectMethod=cursor
    username: sa
  jpa:
    hibernate:
      ddl-auto: update
    properties:
      hibernate:
        dialect: org.hibernate.dialect.SQLServer2008Dialect
  quartz:
    jdbc:
      schema: classpath:org/quartz/impl/jdbcjobstore/tables_sqlServer.sql
    job-store-type: jdbc
    properties:
      org:
        quartz:
          jobStore:
            isClustered: true
          scheduler:
            instanceId: AUTO
          threadPool:
            threadCount: 5

org.quartz.jobStore.driverDelegateClass: org.quartz.impl.jdbcjobstore.MSSQLDelegate```

spring-boot-quartz-scheduler's People

Contributors

mbronshteyn avatar

Stargazers

 avatar  avatar Nikhil Popli avatar Xingze Zhang avatar  avatar

Watchers

James Cloos 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.