Multi Tenancy Quartz Scheduler - java

I have a backend spring boot application that has a quartz scheduler with multiple job triggers working all good but now we got a new client who wants the exact same solution so in order to support this we choose multi-tenancy by SEPERATE SCHEMA approach so each client/tenant will now have his own schema but I am not sure on how do we have quartz running in each schema individually.
Any help is greatly appreciated.

Did you explore on the use of the Custom ConnectionProvider Implementations in Quartz, wherein, we can provide a custom connection provider that can look up the database of your application to identify the tenant specific connection string and then return to Quartz to be used.
This will allow you to use multiple connections based on some tenancy data.
More here

Related

Hibernate database (maria-db) change detect

I need to understand, Is there anyway I can continuously look for change in Maria-DB table using Hibernate.
I have a spring boot application that is connected to Maria-DB. If some other application perform CURD on table, I want to catch that in spring.
If it's not possible using hibernate, suggest me alternative.
PS : This spring boot application is running is different Docker Container and Maria-DB is running is different Docker Container.
You can use Database Triggers, or better why don't you try enabling Hibernates 2nd level cache?
Solution to this specific problem is Spring Integration module as other ways not working here. I have create a sample application to demonstrate here you can find the source code
What this application does look database continuously.

Multi tenancy with Spring boot

I'm planning to work on a multi-tenancy application and for now I'm just looking at different implementations on the web to understand the requirements needed to implement such task.
Hibernate + Spring boot are the technologies I'm planning to use.
From my readings, all the different tutorials are using the same approach which is to declare the data sources in a config file so that session factories are launched with the boot of the application, but I really want to have a higher level of the app, where I can add tenants dynamically and input their data sources informations.
This way the application can get the information of the new tenant without the need to touch the config files and re-boot the app.
I thought about having a separate database where I can store my tenants data source credentials or something like that. Can you give me another approach to solve this requirement or a link to an existing implementation that I can refer to.
Thanks
I got similar requirements in the past.
I implemented DataSource proxy class. The class has tenant resolver and a map of simple DataSources. All the places where we need a DataSource use the proxy.
On any method call e.g. getConnection() it resolves tenant, check whether the map contains already created DataSource (if not a new DataSource is created for the tenant and stored in the DB). Then the same method of real DataSource from the map is invoked.
Tenant resolver is ThreadLocal based where tenant value is stored in a filter (got tenant from request header) and used in the DataSource proxy.
What you need to do is using dynamic datasource routing of Spring Framweork via AbstractRoutingDataSource. This answer explains all for you.
In my question.I implements MultiTenantConnectionProvider and CurrentTenantIdentifierResolver.And use DataSourceLookup to choose datasource by tenant.This links is helpful to me.
Here is a full working example of a database-per-tenant multitenat app I built using Spring Boot 2, Spring JPA (Hibernate), Spring Security 5 running on MySQL.
I have explained how it all works and have shared the entire code too.
Take a look here.

Spring Multi-Tenancy - Adding new tenant without restart (using AbstractRoutingDataSource)

I'm implementing a multi-tenant system using Spring where each tenant has its own database. I have everything up and running.
I've extended "AbstractRoutingDataSource" and overridden "determineCurrentLookupKey" to determine which connection to use via the users domain/tenancy.
The "AbstractRoutingDataSource" is instantiated when the app loads and all the possible database connections are set there.
Here's my question -
Is there a way of dynamically adding additional connections to the AbstractRoutingDataSource? I want to be able to add additional tenants without restarting.
Any help would be greatly appreciated
Thanks
I am too late to this thread, but recently I needed to build a Saas style multi-tenant web app. Tenants needed to be added dynamically without requiring a server restart. So I shared my learnings here with a complete working example.
Yes You can do So, Here is complete project which explains very nicely about your requirement:
Multi-tenancy: Managing multiple datasources with Spring Data JPA

Is there a way to split read/write queries in Quartz Scheduler to use mysql master slave replication?

I am using Quartz scheduler in my application and I am also using master-slave replication for my other DB queries. I want to use the master-slave replication for Quartz scheduler as well hence I want to know if there is a way I can make the changes to split write/read queries which quartz makes to master/slave respectively?
I tried changing the "quartz.properties" but then all the calls going to the master node only
org.quartz.dataSource.quartzDS.driver=com.mysql.jdbc.ReplicationDriver
org.quartz.dataSource.quartzDS.URL=jdbc:mysql:replication://localhost:3306,localhost:3307/quartz?useUnicode=true&characterEncoding=utf8&useTimezone=true&serverTimezone=UTC&useLegacyDatetimeCode=false
org.quartz.dataSource.quartzDS.user=root
org.quartz.dataSource.quartzDS.password=root
org.quartz.dataSource.quartzDS.maxConnections=10
org.quartz.dataSource.quartzDS.validationQuery=select 1
You can define multiple datasources in quartz.properties.
quartzDS is a specific datasource. You can add more with different names by tagging the properties with the name you want (like org.quartz.dataSource.quartzDSTheSecond).
See: http://www.quartz-scheduler.org/documentation/quartz-1.x/configuration/ConfigDataSources
You then can get a connection using DBConnectionManager.getInstance().getConnection("quartzDSTheSecond");

Quartz jobs hanging around in DB tables

We are using Quartz 2.1.6 for job scheduling on a cluster, and storing the job data in a JDBC jobstore in our MySQL database (MySQL 5.1).
All our Quartz configuration (scheduler, jobs, triggers) is done at startup through Spring. We store the data in the database for clustering purposes.
Problem: We have several jobs that were added and then deleted from the Quartz configuration. They are no longer in the config, but they are still present in the tables. How do we get rid of them? Reading the Quartz documentation, it appears that doing manual edits of the tables is a Very Bad Thing.
We do not appear to be explicitly setting JobDetail.setDurability(true), so I'm not sure why these jobs and triggers are hanging around, but they are.
Anyone have an answer?
Yep, it's not the best idea to do this in the database unless you're very on clear what you're doing. So, try doing it programmatically:
ISchedulerFactory factory = new StdSchedulerFactory();
IScheduler schedulder = factory.GetScheduler();
schedulder.DeleteJob(JobName, JobGroup);

Categories

Resources