Question

I am trying to create a sample JMS application. All I want it to do is start up, and have the producer send a message to the consumer when data is sent to an endpoint.

I am having trouble with my spring configuration, and I don't know what dependencies I need to bring in (and what versions) with Maven. I started with a simple Roo project.

Firstly, does my spring xml look ok, and secondly, are my maven dependencies right? From the error I get, I think I've got an outdated dependency being pulled in from Maven. I've also added a guest user/role to my jboss configuration.

Here is the relevant section of my spring xml:

<bean id="jnditemplate" class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
        <props>
            <prop key="java.naming.factory.initial">org.jboss.naming.remote.client.InitialContextFactory</prop>
            <prop key="java.naming.provider.url">remote://127.0.0.1:4447</prop>
            <prop key="java.naming.security.principal">guest</prop>
            <prop key="java.naming.security.credentials">password1</prop>
        </props>
    </property>
</bean>
<bean id="connectionfactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiTemplate" ref="jnditemplate"/>
    <property name="jndiName" value="jms/RemoteConnectionFactory"/>
</bean>
<bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiTemplate" ref="jnditemplate"/>
    <property name="jndiName" value="jms/queue/test"/>
</bean>
<bean id="credentialsconnectionfactory"
      class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
    <property name="targetConnectionFactory" ref="connectionfactory"/>
    <property name="username" value="guest"/>
    <property name="password" value="password1"/>
</bean>
<bean id="jmstemplate" class="org.springframework.jms.core.JmsTemplate">
    <property name="connectionFactory" ref="credentialsconnectionfactory"/>
    <property name="defaultDestination" ref="destination"/>
</bean>
<bean class="org.springframework.jms.listener.SimpleMessageListenerContainer">
    <property name="connectionFactory" ref="credentialsconnectionfactory"/>
    <property name="destination" ref="destination"/>
    <property name="messageListener" ref="receiver"/>
</bean>
<bean id="sender" class="com.example.web.Producer">
    <property name="jmsTemplate" ref="jmstemplate"/>
</bean>
<bean id="receiver" class="com.example.web.Consumer"/>

Here is the relevant section of my POM:

        <spring.version>3.2.0.RELEASE</spring.version>
    <hornetq.client.version>2.3.0.Final</hornetq.client.version>
 ...
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jms</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.jboss.as</groupId>
        <artifactId>jboss-as-ejb-client-bom</artifactId>
        <version>7.1.1.Final</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-core-client</artifactId>
        <version>${hornetq.client.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-jms-client</artifactId>
        <version>${hornetq.client.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jboss</groupId>
        <artifactId>jboss-ejb-client</artifactId>
        <version>1.0.5.Final</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.jboss.ejb3</groupId>
        <artifactId>jboss-ejb3-ext-api</artifactId>
        <version>2.0.0-beta-2</version>
    </dependency>
    <dependency>
        <groupId>org.jboss.netty</groupId>
        <artifactId>netty</artifactId>
        <version>3.2.9.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-core</artifactId>
        <version>2.0.0.GA</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-jms</artifactId>
        <version>2.0.0.GA</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-logging</artifactId>
        <version>2.0.0.GA</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.hornetq</groupId>
        <artifactId>hornetq-transports</artifactId>
        <version>2.0.0.GA</version>
        <scope>compile</scope>
    </dependency>

And the relevant section of my jboss standalone.xml:

   <subsystem xmlns="urn:jboss:domain:messaging:1.1">
        <hornetq-server>
            <persistence-enabled>true</persistence-enabled>
            <journal-file-size>10240</journal-file-size>
            <journal-min-files>2</journal-min-files>

            <connectors>
                <netty-connector name="netty" socket-binding="messaging"/>
                <netty-connector name="netty-throughput" socket-binding="messaging-throughput">
                    <param key="batch-delay" value="50"/>
                </netty-connector>
                <in-vm-connector name="in-vm" server-id="0"/>
            </connectors>

            <acceptors>
                <netty-acceptor name="netty" socket-binding="messaging"/>
                <netty-acceptor name="netty-throughput" socket-binding="messaging-throughput">
                    <param key="batch-delay" value="50"/>
                    <param key="direct-deliver" value="false"/>
                </netty-acceptor>
                <in-vm-acceptor name="in-vm" server-id="0"/>
            </acceptors>

            <security-settings>
                <security-setting match="#">
                    <permission type="send" roles="guest"/>
                    <permission type="consume" roles="guest"/>
                    <permission type="createNonDurableQueue" roles="guest"/>
                    <permission type="deleteNonDurableQueue" roles="guest"/>
                </security-setting>
            </security-settings>

            <address-settings>
                <address-setting match="#">
                    <dead-letter-address>jms.queue.DLQ</dead-letter-address>
                    <expiry-address>jms.queue.ExpiryQueue</expiry-address>
                    <redelivery-delay>0</redelivery-delay>
                    <max-size-bytes>10485760</max-size-bytes>
                    <address-full-policy>BLOCK</address-full-policy>
                    <message-counter-history-day-limit>10</message-counter-history-day-limit>
                </address-setting>
            </address-settings>

            <jms-connection-factories>
                <connection-factory name="InVmConnectionFactory">
                    <connectors>
                        <connector-ref connector-name="in-vm"/>
                    </connectors>
                    <entries>
                        <entry name="java:/ConnectionFactory"/>
                    </entries>
                </connection-factory>
                <connection-factory name="RemoteConnectionFactory">
                    <connectors>
                        <connector-ref connector-name="netty"/>
                    </connectors>
                    <entries>
                        <entry name="RemoteConnectionFactory"/>
                        <entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
                    </entries>
                </connection-factory>
                <pooled-connection-factory name="hornetq-ra">
                    <transaction mode="xa"/>
                    <connectors>
                        <connector-ref connector-name="in-vm"/>
                    </connectors>
                    <entries>
                        <entry name="java:/JmsXA"/>
                    </entries>
                </pooled-connection-factory>
            </jms-connection-factories>

            <jms-destinations>
                <jms-queue name="testQueue">
                    <entry name="queue/test"/>
                      <entry name="java:/queue/test"/>
                    <entry name="java:jboss/exported/jms/queue/test"/>
                </jms-queue>
                <jms-queue name="DemoQueue">
                    <entry name="/queue/DemoQueue"/>
                </jms-queue>
                <jms-topic name="testTopic">
                    <entry name="topic/test"/>
                    <entry name="java:jboss/exported/jms/topic/test"/>
                </jms-topic>
            </jms-destinations>
        </hornetq-server>
    </subsystem>
    <subsystem xmlns="urn:jboss:domain:weld:1.0"/>
</profile>

and the error I receive when I try to start it up through eclipse/vmware vFabric

 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.jms.listener.SimpleMessageListenerContainer#0' defined in ServletContext resource [/WEB-INF/spring/webmvc-config.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hornetq.utils.HornetQThreadFactory.<init>(Ljava/lang/String;Z)V
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
Was it helpful?

Solution

At least some dependencies in the pom.xml are flat out wrong. Look at the bottom for hornetq-logging, hornetq-transports, hornetq-jms etc. These do not exist anymore in the 2.3.X releases and should be removed.

As a rule, if you have any JAR from the main HornetQ project, it should use the same version. Remove all those jars using 2.0.0.GA. Some of those were renamed, in either case, you should try to only have org.hornetq JARs using the same version. In the case of your pom that would be 2.3.0-Final. BTW, the latest version is 2.3.2-Final, and you should upgrade to that IMHO.

IIRC hornetq-jms was broken into hornetq-jms-server or hornetq-jms-client. You probably want hornetq-jms-client. Core was also broken into hornetq-core-client and hornetq-server.

Search for JARs available with version number 2.3.2.Final here https://repository.jboss.org/nexus/index.html#nexus-search;quick~org.hornetq (do some more advanced search).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top