Can I run long tasks in a Spring Boot application? - java

I have a Spring Boot application, which shows some data from MongoDB on an AngularJS page and allows the user to change it.
Now I need to create a mechanism, which allows me to
run a long (1-3 hours) Java method,
which produces some files and
observe its state via web (does it run, is it finished, did it crash?).
Can I implement this in scope of the Spring Boot application? If yes, what parts of Spring can I use to do that?

I would argue that it's not good idea to embed batch processing into your service exposing MongoDB data store.
I would create separate batch application. Spring Batch would be natural choice if you are using Spring stack. You would need to figure out how you want to host Spring Batch job and how you want to trigger and schedule it. Spring Batch needs SQL storage for it's metadata.
Status of the batch processing could be monitored by one other application with Spring Batch Admin module running on Servlet container. If you point this application to SQL storage of Spring Batch job application, you get monitoring of status via web UI out of the box.
Of course it could run each app with Spring Boot.
If you don't want to handle this operational complexity it brings to host there three applications, yous still can all three embed into one and it would work fine with Spring Boot. You could even execute jobs with parameters manually or restart them via Spring Batch Admin configured to have access to Spring Batch Job beans.
You could also explore using MongoDb as storage for Spring Batch metadata. E.g. this project may help. But such mechanism would need to be used by Spring Batch application and also by Spring Batch Admin module visualizing status of processing.

Related

Azure webjobs with Spring Boot

I need to run a scheduler for every 1hour, and it has to read DB and send emails. I have deployed my Spring Boot app into Azure webjobs as a scheduled trigger. The app is deployed and the scheduler is working fine, but I don't see the trigger calling my app. Am I doing it correctly?
Also if my understanding is correct , when the trigger starts won't it deploy my Spring boot app again? Please let me know
Since the data from DB is less, I have not preferred to work with Spring Batch
Also if my understanding is correct , when the trigger starts won't it deploy my Spring boot app again?
yes, you can't deploy spring boot application once the trigger is started.
The app is deployed and the scheduler is working fine, but I don't see the trigger calling my app. Am I doing it correctly?
You can use Maven application Plugin to deploy the spring boot application a you are not using the spring boot batch
Also here is the Microsoft Official document where you can have a look on connecting the DB with the application and then running the scheduler.
You can even check this Spring Boot deployment documentation and this SO with related discussions.

QuartzDesk cannot manage the Quartz Jobs and Trigger in a Spring Boot 2 application

We let the Quartz Jobs in our Spring Boot 2 application be managed by QuartzDesk:
https://www.quartzdesk.com/documentation/how-it-works
QuartzDesk consists of three parts: the Web UI (its main purpose) which runs on its own Tomcat and from which you can manage the Quartz Jobs and Quartz Trigger from remote by RMI or JMXMP. Then there is the QuartzDesk Agent which the Spring Boot 2 application must adopt by setting a java agent (java -javaagent:agent.jar ...) when it starts. Last but not least the Spring Boot 2 application must use the QuartzDesk Public API just by declaring a further dependency in the pom.xml.
For Quartz in general we hava a central JDBC Jobstore in which the all the Quartz stuff is saved. The Spring Boot 2 application runs on two instances which are load balanced.
Our problem is that the Quartz Jobs and Trigger cannot be managed by the QuartzDesk Web UI. When you set up in QuartzDesk Web UI the connection to each instance then all Quartz Jobs and Trigger are there in advanced created. The worst thing however is that any changes from this central management console have no effect even though QuartzDesk Web UI confirms it mistakenly.
The problem was a wrongly configured property for the Quartz JDBC Jobstore, i.e. its datasource:
quartz.datasource.auto-commit=false
Changing it to true solved the problem and Quartz jobs and trigger were finally configurable.

How to interact with client only Spring Boot application

Circumstances
I have a spring boot application that is not accessible via web (spring.main.web-environment=false). The purpose of using spring boot is to have an out of the box support for interacting with a database. Maybe a JPA layer alone would also have been sufficient, but I went for spring boot.
The program has a GUI (JavaFX), and this GUI interacts with the spring boot application whenever a DB interaction is necessary.
Question
Now I am a bit confused, how the GUI can interact with Spring Boot. I start Spring Boot, better to say the main application (#SpringBootApplication) at the startup of the program (in a Thread if that matters, as it must not block the GUI). So far so good. But how can I call methods in spring boot? My last project was a web project, and I used REST APIs with according Spring Boot Controllers, which allowed me to interact with Spring Boot via a e.g. a browser.
But now I am client only, and I want to call methods which do something within my Spring boot Application from the GUI, e.g. when a button is pressed.
Maybe this is answered easily, but I couldn't find how to do it properly. I built a solution with ApplicationRunner where every time a new spring boot application is started and closed after doing it's job, but this is not really elegant, and I am not able to retrieve parameters back with this technique.

Running a Spring Boot App on Azure WebJob with a Schedule

I have a regular Java/Spring Batch job that runs every night to get data from one database and insert/update in my project's database. This is working fine in the current setup where it is deployed on Tomcat.
Now I need to separate it out and run it on an Azure WebJob. What will be a good approach?
Can I use Spring Boot for this purpose?
But I am not sure how it will work. I mean, I can create a JAR of my project (Job written using Spring Boot) and copy it on a Azure WebJob. Then have a batch file with "java -jar..." but:
wouldn't it be like running and deploying the Spring Boot App with it's inbuilt web-server that will continue to run once I run it?
secondly, the next time the batch file is executed by Azure WebJob as per the schedule I set it will try to run the Spring Boot App again and I will probably get bind exception since the port is already in use from the first run.
Would appreciate if somebody can help me in doing this.
Thank you.
wouldn't it be like running and deploying the Spring Boot App with it's inbuilt web-server that will continue to run once I run it?
A Spring Boot app can be a non web app, and a good example is a Spring Boot batch app without a dependency to a servlet container.
You can create a Spring Boot app that runs your Spring Batch job and then stops when the job is finished without the need to deploy it in a (embedded) Tomcat. You can find an example here: https://spring.io/guides/gs/batch-processing/
secondly, the next time the batch file is executed by Azure WebJob as per the schedule I set it will try to run the Spring Boot App again and I will probably get bind exception since the port is already in use from the first run.
Once you have a script to run your app with java -jar mybatchapp.jar, you can use Azure Scheduler to run your job when you want. Since your batch app does not contain/start an embedded servlet container, you won't get a port conflict.

Spring Boot : How to get Application name in Spring Boot Executable?

I have created a Spring boot application and executing the same as a an init.d service.
Tutorial Followed : https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html#deployment-initd-service
I have multiple symlink created in the same machine like worker-node1, worker-node2, worker-node3, worker-node4 etc so that i can run multiple instances of the same application in the same machine as independent processes. Is there any way to get the symlink name in the Spring boot application so that i can send which worker-node picked up a task to the job management server?
Any help on this regard would be helpful.

Categories

Resources