Reputation: 7084
I'm upgrading an old system that was a batch job that used Camel Main to continue running, so that it can basically loop and query a database every few seconds. It also uses Spring for configuration, but doesn't use Spring Boot. It was on Camel 2.x and I'm having to upgrade it to Camel 3.14. The Main class has changed in that time. In addition to being moved to a different package, it has lost the method it was using to add the Spring context, which was setApplicationContextUri("app-context")
. There is a configure()
method on Main now, but I still don't see a way of adding a Spring context to Main.
Looking at javadocs for the new Main, I see there are methods in MainSupport that reference CamelContext, but they seem to be about creating a blank CamelContext. There is also an autoconfigure(CamelContext)
which takes in CamelContext, but it's protected, so I don't see how to call it. I guess without extending Main, which I don't see any use cases or examples for.
Alternatively, if there's a way to do this without using Main, I'm open to that as well.
The Spring and CamelContext are mainly used to set up beans like dataSources and Properties. The Route is defined in the same class that contains the java main() method that is called from the script used to start the whole process (this is the old version):
package com.foo.email.ffdb.listener;
import java.util.Properties;
import javax.annotation.Resource;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.spring.Main;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import com.foo.email.ffdb.util.FireFrgtConstants;
public class EmailDBListener extends RouteBuilder {
private static Logger log = LogManager.getLogger(EmailDBListener.class.getName());
private static String routeId = FireFrgtConstants.EMAIL_ROUTE_ID;
@Autowired
private EmailDBProcessor emaiDBProcessor;
@Resource
private Properties emailProperties;
public static void main(String[] args) throws Exception {
System.out.println("STARTING EMAILDBLISTENER");
log.debug("Starting Email Batch ");
Main main = new Main();
main.setApplicationContextUri("app-context.xml");
main.run();
log.info("Email Batch Started:");
}
@Override
public void configure() throws Exception {
log.debug("configure() ");
from(configureSqlTimer())
.routeId(routeId)
.to("sqlComponent:{{SQL.READ_EMAIL_REQUESTS}}")
.bean("fireForgetServiceMapper", "readEmailRequests")
.process(emaiDBProcessor);
}
private String configureSqlTimer() {
log.debug("configureSqlTimer() ");
String pollingTime = emailProperties.getProperty(FireFrgtConstants.POLLING_TIME);
String sqlTimer = "timer://pollFireFrgtTable?period=" + pollingTime + "s";
return sqlTimer;
}
}
Upvotes: 0
Views: 344
Reputation: 7084
I just had the wrong Main. There is one in camel-main, and another in camel-spring-main. I just needed to use the camel-spring-main, and it started running and staying alive.
Except for a transaction problem I am creating another question for...
But the main program is running
Upvotes: 0