Answer the question
In order to leave comments, you need to log in
What is the correct architecture for deploying an application with a REST service?
There is a task: to write a telegram bot that will notify the user about the occurrence of an event in some external system. The bot must be deployed on the company's internal server.
I have written a project in Java where the logic of the bot (long pooling) is implemented and the REST service (Jersey) is deployed, which will be accessed by the external system. All within one project.
Deploying all this at once on tomcat (with one war) did not work, since long pooling simply does not work as a servlet. Separately, I can raise REST on tomcat, but the bot does not work. If you run the application from the IDE - the bot works, the REST service does not work.
It may be worth setting up the bot via a web hook and raising it to tomcat with a separate application, but it is not clear how the REST service will interact with it.
Perhaps I made a mistake in the architecture of the application itself and it needs to be designed differently. Perhaps I decided to use the wrong deployment method and technology.
Help with advice on how to get it all to work on the server.
Answer the question
In order to leave comments, you need to log in
And what are the problems with Tomcat? In servlets, there is such a thing as listeners. Define a listener that implements ServletContextListener. In it, start your own threads that live as long as your application lives in Tomcat. You register it in web.xml. In your rest services, it is enough to get the ServletContext and from there take the created class instance.
<listener>
<listener-class>
my.long.life.clazz.Listener
</listener-class>
</listener>
import io.javalin.Javalin;
public class HelloWorld {
public static void main(String[] args) {
MyTelegramBot mybot = new MyTelegramBot(); // тут херачим телеграм
Javalin app = Javalin.create().start(7000); // тут запускаем сервер
app.get("/", ctx -> ctx.result("Hello World")); // тут херачим свои REST
app.put("/myrest", ctx -> mybot.send(ctx));
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question