-
1. Re: How to integrate HornetQ in Spring?
clebert.suconic Dec 31, 2010 5:19 PM (in response to jbx)Bill Burke did some work on trunk... and I believe he wrote some doc about it.
This is something that we will improve early next year.
-
2. Re: How to integrate HornetQ in Spring?
jbx Jan 1, 2011 3:22 PM (in response to clebert.suconic)Any chance of getting a link to the doc?
-
3. Re: How to integrate HornetQ in Spring?
ataylor Jan 4, 2011 5:47 AM (in response to jbx)It should be pretty simple, look at the hornetq-beans.xml file which is used by the jboss microcontainer to instantiate the HornetQ pojo's. It should be simple to convert this to a spring beans file. When you do you can contribute it back to the project
-
4. Re: How to integrate HornetQ in Spring?
jbx Jan 4, 2011 8:08 AM (in response to ataylor)I checked the hornetq-beans.xml and I am already initialising all the beans mentioned there. I have also put jndi.properties in the classpath containing the following (I am also sure its picking it up, because when I remove it I get a NoInitialContextException):
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactoryjava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfacesjava.naming.provider.url=jnp://localhost:1099java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=jnp://localhost:1099
I also do have the JNDI Naming Server specified in the same way:
<bean name="namingServer" class="org.jnp.server.Main" init-method="start" destroy-method="stop">
<property name="namingInfo" ref="namingServerImpl" />
<property name="port" value="1099" />
<property name="bindAddress" value="localhost" />
<property name="rmiPort" value="1098" />
<property name="rmiBindAddress" value="localhost" />
</bean>
I just get the following exception, which seems to indicate that I am missing something related to JNDI because it is not connecting to the respective JNDI server on port 1099, but I can't find anywhere a simple working example of what I need to have.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'namingServerImpl' defined in file [C:\Projects\SpringMQTest\src\spring-config.xml]: Invocation of init method failed; nested exception is javax.naming.CommunicationException: Could not obtain connection to any of these urls: jnp://localhost:1099 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is javax.naming.ServiceUnavailableException: Failed to connect to server localhost/127.0.0.1:1099 [Root exception is java.net.ConnectException: Connection refused: connect]]]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1401)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
... -
5. Re: How to integrate HornetQ in Spring?
ataylor Jan 4, 2011 8:24 AM (in response to jbx)thats because you dont need the:
java.naming.provider.url=jnp://localhost:1099
this is just for clients, what happening is the naming server itself is trying to bind remotely. you should only use this for the client. If you are using both a client and server in the same vm then you need to set these params a different way
-
6. Re: How to integrate HornetQ in Spring?
jbx Jan 4, 2011 8:34 AM (in response to ataylor)If I remove that line I get a strange NoClassDefFoundError on org.jboss.util.threadpool.ThreadPool .
I included the Jar files mentioned in that article i.e.:
hornetq-bootstrap.jar
hornetq-core.jar
hornetq-jms.jar
hornetq-logging.jar
jbosslogging-spi-2.1.1.GA.jar
jnpserver.jar
netty.jar
jms.jar
Remember this is a standalone application not inside any J2EE container.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'namingServer' defined in file [C:\Projects\SpringMQTest\src\spring-config.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/jboss/util/threadpool/ThreadPool
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'namingServer' defined
in file [C:\Projects\SpringMQTest\src\spring-config.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/jboss/util/threadpool/ThreadPool
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450) -
7. Re: How to integrate HornetQ in Spring?
ataylor Jan 4, 2011 10:20 AM (in response to jbx)that class is in jboss-common-core.jar
-
8. Re: How to integrate HornetQ in Spring?
howtodoinjava Mar 25, 2013 12:53 AM (in response to jbx)Though it seems to be an old thread.. still people like me come here frequently. I also tried my hand on spring 3 + hornetq integration and was quite successfull. Possibly it could help someone.
http://howtodoinjava.com/2013/03/24/spring-3-hornetq-standalone-integration-example/
-
9. Re: How to integrate HornetQ in Spring?
sreejithsrkmr Apr 15, 2013 7:47 AM (in response to jbx)I am a newbie to HornetQ as well as Spring. So need some help.
I have a standalone HornetQ instance which has the ConnectionFactory and Queue defined and running. I am able to connect to the queue and send/receive messages using standalone java code.
I am now trying to wire the JNDI lookup, ConnectionFactory and Queue in a sample Spring webapplication. The basic idea is to put a message from the web application. Any pointers on how to setup the JNDI,
ConnectionFactory and Queue in the Spring applicationContext.xml ? The documentation floating around seem to suggest instances where the HornetQ is embedded within the same VM as where the web application runs, while I want to host the HornetQ on a different box.
-
10. Re: How to integrate HornetQ in Spring?
sreejithsrkmr Apr 17, 2013 6:23 AM (in response to sreejithsrkmr)Got it working. Spring configuration is as follows.
<bean id="hornetConnectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory">
<constructor-arg name="ha" value="false" />
<constructor-arg>
<bean class="org.hornetq.api.core.TransportConfiguration">
<constructor-arg
value="org.hornetq.core.remoting.impl.netty.NettyConnectorFactory" />
<constructor-arg>
<map key-type="java.lang.String" value-type="java.lang.Object">
<!-- HornetQ standalone instance details -->
<entry key="host" value="192.168.22.573"></entry>
<entry key="port" value="5445"></entry>
</map>
</constructor-arg>
</bean>
</constructor-arg>
</bean>
<!-- ConnectionFactory Definition -->
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<constructor-arg ref="hornetConnectionFactory" />
</bean>
<!-- Definition of the JMS queue -->
<bean id="defaultDestination" class="org.hornetq.jms.client.HornetQQueue">
<constructor-arg index="0" value="DemoQueue"/>
</bean>
<bean id="producerTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="defaultDestination" ref="defaultDestination" />
</bean>
<bean id="messageSender" class="com.samples.producer.JMSProducer">
<property name="jmsTemplate" ref="producerTemplate" />
</bean>
-
11. Re: How to integrate HornetQ in Spring?
mofarn Apr 22, 2013 9:22 AM (in response to jbx)Follow this for consuming message asynchronously with spring : http://stackoverflow.com/questions/15940783/in-the-hornetq-the-consumer-is-automatically-invoked/15941593#15941593
-
12. Re: How to integrate HornetQ in Spring?
ananymous7239 Nov 8, 2013 1:35 AM (in response to howtodoinjava)Hi lokesh iam new to hornetQ and i tried your example spring integration with HornetQ ,but i am getting the following exception,please help me
log4j:WARN No appenders could be found for logger (org.springframework.context.support.FileSystemXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'namingServerImpl' defined in file [F:\HornetQ Workspace\Spring3HornetQStandaloneIntegration\resource\config\server\spring.xml]: Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
at com.howtodoinjava.hornetq.demo.SpringContainerLoader.loadEnvironment(SpringContainerLoader.java:9)
at com.howtodoinjava.hornetq.demo.HornetQMessagingTest.main(HornetQMessagingTest.java:10)
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getEnvironment(Unknown Source)
at org.jnp.server.NamingBeanImpl.start(NamingBeanImpl.java:160)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1544)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 13 more
@Lokesh Gupta