Deploying Clojure Applications in a Single JVM Instance

Suppose I have two or more different server applications developed in Clojure using the ZeroMQ and BSON protocols. How can I deploy them with a single JVM instance and also use common dependencies?

It seems like a waste of memory to use a JVM instance for each individual application. I plan to develop several Clojure applications in the future, and VPS memory is not cheap.

Although not explicitly said, applications running on the application server (Jetty, Glassfish) seem to use the same JVM to isolate their state. However, they require a container, and neither servlets nor Enterprise JavaBeans have an implementation that I could easily adapt to my user protocol.

I was thinking about using Servlets and implementing the dummy service () method, although I don't like the idea of ​​having meaningless HTTP server overhead. As for the EJB container, I can't even understand its implementation.

It would be nice to have a container that requires only the init () and destroy () methods, but I cannot find the application server that provides it.

Maybe there is a way, or I don’t even need an application server. Can someone point me in the right direction?

+4
source share
4 answers

It looks like an EJB container would be nice, but only if it were easier or easier to work with. Have you looked at Immutant ? This is basically a wrapper around JBossAS for Clojure, written by the Red Hat guys (who also have JBossAS).

In addition to the application server, these guys wrapped JMS and other Java-EE features around Clojure, so sending messages between applications seems pretty simple :

In addition, they have Daemons and Jobs , which can provide something similar to what you described as simple services with init() and destroy() .

Saying this, I did not use it, so I can not vouch for it, awesomenss / awfulness.

+2
source

Thus, you have two applications that share the same dependencies, and both want to respond to events and / or generate events on the message bus.

If I understand what you are saying, it should be as simple as starting the JVM with access to all the code in the classpath and initializing your message bus and your code from the main method.

If you want to use a container, you can create some kind of fake beans-driven message that sits between your clojure code and the message bus, assuming there is a JMS adapter for your message bus. Using netbeans / glassfish, this might not be so bad. You can get some monitoring results, but I'm not sure what else you will win.

+2
source

I continued to search and find out that some application servers that implement the OSGi service platform have lighter containers than those offered by Java EE.

Apache Karaf , for example, can load POJO applications directly from JAR files.

+1
source

I do not know what DD is, but any JAR is a valid package. Since clojure is not type safe, you will need to combine the clojure world with the OSGi / Java world, but the OSGi API is a wet dream for such bridges.

Not that the OSGi package does not automatically provide its content, the OSGi package is closed by default. However, the API allows you to punch holes wherever you want.

0
source

Source: https://habr.com/ru/post/1443209/


All Articles