Historically, I deployed my consumer JMS applications as Spring webapps deployed under Tomcat (Windows window). Then these users will work with other web applications under the same instance of Tomcat. However, as the number of consumers I use has grown, I realized that this is turning into a bit of a nightmare for service.
My solution was to convert these web applications into standalone “core method” applications deployed like banks. In fact, I was able to successfully pack them all together, trying to reuse as many resources as possible (DAO, dependencies, etc.).
This is what my main method looks like:
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
try {
FooListener fooListener = (FooListener) context.getBean("fooListener");
fooListener.start();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
try {
BarListener barListener = (BarListener) context.getBean("barListener");
barListener.start();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
My question (s):
- - , JMS- - ?
- - - - , jms-, tomcat ?
Edit:
: FooListener BarListener . beans applicationContext.xml, onMessage() .
public abstract class TextMessageListener implements MessageListener {
protected ConnectionFactory connectionFactory;
protected String queueName;
protected String selectors;
public void start() throws JMSException {
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(session.createQueue(queueName), selectors);
consumer.setMessageListener(this);
connection.start();
}
public abstract void onMessage(Message message);
}