I’ve been doing some work on HornetQ SVN trunk to improve the embeddable HornetQ experience (you’ll see these improvements in the next HornetQ release). You can disagree with me, but I thought that embedding HornetQ was a bit verbose, especially for JMS, so first of all, I wrote two wrapper classes to make this easier. While these classes will be in the next release along with a full docbook explanation, here’s what configuring JMS looks like now:
import org.hornetq.jms.server.embedded.EmbeddedJMS; ... EmbeddedJMS jms = new EmbeddedJMS(); jms.start();
This class will look for hornetq-configuration.xml, hornetq-jms.xml, and hornetq-users.xml within your classpath. It also has the option of manually creating configuration objects via pojo instantiation if you desire (or if you want to wire it with Spring for instance).
Simple Spring Integration
Another thing I did was to provide some simple Spring integration with the HornetQ JMS implementation. I wrote a simple class that extends EmbeddedJMS that will register any configured queues, topics, and ConnectionFactorys direction within the Spring application context so that other beans can reference them. Here’s an example of bootstrapping HornetQ JMS and referencing a queue within a Spring message listener container.
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="EmbeddedJms" class="org.hornetq.integration.spring.SpringJmsBootstrap" init-method="start" destroy-method="stop"/> <bean id="listener" class="org.hornetq.tests.integration.spring.ExampleListener"/> <bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="ConnectionFactory"/> <property name="destination" ref="/queue/exampleQueue"/> <property name="messageListener" ref="listener"/> </bean> </beans>
Again, this assumes you have configured HornetQ properly within HornetQ specific configuration files. You can also manually declare HornetQ config objects within Spring and inject them into the EmbeddedJMS bean instance too if you don’t want to use HornetQ config files.
Right now, the code does not also register HornetQ objects within JNDI. Do you think I should add this capability? Anyways, I hope you’ll find this HornetQ + Spring integration useful in the next HornetQ release.
Sep 16, 2010 @ 13:42:27
This is great!
I used to do it from version 2.0.0.GA of HornetQ, though it required a lot more configuration (basically what you hard-wired inside of the embedder.
I which part of SVN is it available?
Sep 16, 2010 @ 13:45:59
Its in TRUNK.
Sep 16, 2010 @ 13:46:28
and please please please provide some feedback either here or on the hornetq dev list
Sep 16, 2010 @ 14:11:30
Will do that ASAP. Preferably on dev list. Is it relevant to raise possible issues in HORNETQ’s JIRA, or not yet?
Feb 14, 2011 @ 23:24:07
I’ve been poking around in your new Spring integration code in HornetQ TRUNK and I can’t seem to figure out how its wired together. The example Spring config file is referring to a bean named “ConnectionFactory” but that bean is never defined. There IS a ConnectionFactory declared in the hornetq-jms.xml file, but that doesn’t create a bean that can be referenced in a Spring config file.
How would I declare an in-vm Connection Factory bean in Spring config?
Aug 07, 2011 @ 18:22:00
This what i am getting
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘listenerContainer’ defined in ServletContext resource [/WEB-INF/spring/jms-context.xml]: Cannot resolve reference to bean ‘ConnectionFactory’ while setting bean property ‘connectionFactory’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ‘ConnectionFactory’ is defined
Trying to integrate HornetQ in Tomcat