I thought someone might be interested in a ActiveMQ setup. It turned out be be quite easy as well.
The following assumes you are using Tomcat and have two seperate web applications - say a master and a slave one ;-)
First step is to make sure that each of the applications has its own hibernate configuration according to the Hibernate Search documentation.
Next step is to make sure that JNDI is setup properly. Just add the following to the context.xml of your apps.
Code:
<!-- ActiveMQ ConnectionFactory -->
<Resource name="jms/ConnectionFactory" auth="Container" type="org.apache.activemq.ActiveMQConnectionFactory"
description="JMS Connection Factory" factory="org.apache.activemq.jndi.JNDIReferenceFactory"
brokerURL="vm://localhost" brokerName="LocalActiveMQBroker"/>
<!-- ActiveMQ HibernateSearch queue -->
<Resource name="queue/hibernatesearch" auth="Container" type="org.apache.activemq.command.ActiveMQQueue"
description="Hiebrnate search queue" factory="org.apache.activemq.jndi.JNDIReferenceFactory"
physicalName="HibernateSearchController"/>
In case you are using maven you can add the following dependency to your pom.xml to get the ActiveMQ dependencies:
Code:
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
<version>4.1.1</version>
</dependency>
Next step is to implement a subclass of
AbstractJMSHibernateSearchController in the master application. This class has to register itself as listener to the queue. The code could look somewhat like this:
Code:
Context initCtx = new InitialContext();
// Look up for connection factory & create connection, session
ConnectionFactory connectionFactory = (ConnectionFactory) initCtx.lookup("java:comp/env/jms/ConnectionFactory");
connection = connectionFactory.createConnection();
connection.start();
javax.jms.Session session = connection.createSession(true, 0);
// Look up for destination and set listner
Queue queue = (Queue) initCtx.lookup("java:comp/env/queue/hibernatesearch");
MessageConsumer consumer = session.createConsumer(queue);
consumer.setMessageListener(this);
Last but not least you have to make sure that this code is executed at application startup, eg by implementing a startup listener.
That's pretty much it. Not too hard I think.
I hope it helps someone.
--Hardy