Spring web to connect to HornetQ JMS embeded with Jboss server 7.1.1

跟風遠走 提交于 2019-12-04 15:18:53

It should work, if you replace

<bean name="hornetConnectionFactory" class="org.hornetq.jms.client.HornetQJMSConnectionFactory">
    <constructor-arg name="ha" value="false"></constructor-arg>
    <constructor-arg>
        <bean name="transportConfiguration" 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">
                    <entry key="host" value="127.0.0.1" />
                    <entry key="port" value="5445" />
                </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"></constructor-arg>
</bean>

with

<jee:jndi-lookup id="connectionFactory" jndi-name="java:/JmsXA"/>
<jee:jndi-lookup id="defaultDestination" jndi-name="java:/queue/DemoQueue"/>

Doing that, you shouldn't need hornetq dependencies in your pom either, as doing it with a JNDI lookup is implementation agnostic (which is a good thing). The instructions you refer to are about connecting to standalone hornetq server, and in that case you would need the implementations. However, connecting to embedded should not need them.

Assuming, of course, that your spring app is deployed within JBoss having the embedded HornetQ.


Update: ok, so you added that you're actually connecting from Tomcat to JBoss instance. In that case I only see two things wrong:

<hornetq.version>2.2.18.Final</hornetq.version>

This is wrong as it doesn't match the version shipped with JBoss 7.1.1, and explains your topology error. It should be:

<hornetq.version>2.2.13.Final</hornetq.version>

Also, when that has been fixed, you'd get a security error as you haven't disabled the security but haven't provided any user credentials to your JMS connection either. Try adding this to your JBoss HornetQ configuration:

<subsystem xmlns="urn:jboss:domain:messaging:1.1">
    <hornetq-server>
        <security-enabled>false</security-enabled> <!-- <- this part -->

to disable the security, if you don't want to use it.

I also tested this, this contains the example code in github.


Update2: to be able to use JMS Security, replace this

<!-- ConnectionFactory Definition -->
<bean id="connectionFactory"
    class="org.springframework.jms.connection.CachingConnectionFactory">
    <constructor-arg ref="hornetConnectionFactory"/>
</bean>

with this

<!-- ConnectionFactory Definitions -->
<bean id="userCredsConnectionFactory" class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
   <property name="targetConnectionFactory"><ref bean="hornetConnectionFactory"/></property>
   <property name="username"><value>jmsuser</value></property>
   <property name="password"><value>hornetq</value></property>
   <!-- use credentials of some user you have added in 'jmsrole' group as application
        user in jboss in the above config -->
</bean>

<bean id="connectionFactory"
    class="org.springframework.jms.connection.CachingConnectionFactory">
    <constructor-arg ref="userCredsConnectionFactory"/>
</bean>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!