Send JMS Message with Spring JmsTemplate

3.1k Views Asked by At

I have a server that needs to send messages to a separate application. I'm using Spring JmsTemplate, however, I'm having some issues with getting the configuration up and running.

Right now, I'm getting the following exception:

Error creating bean with name 'connectionFactory' defined in ServletContext resource [/WEB-INF/config/application-context.xml]: Invocation of init method failed; nested exception is javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]

(I can post the full stack trace if you like, but it's just the long version of those nested exceptions.)

The "receive timed out" part makes it sound like it's trying to receive messages, which I don't want to do. Everything here has been pulled together from a couple different examples and SO posts, and I'm having trouble wrapping my head around all of the different parts and what they're doing. In addition to whatever might be causing the error, is there anything I don't need if I'm not receiving messages?

In my JmsQueueSender class (which sends messages):

private JmsTemplate jmsTemplate;
private Destination destination;

public void setConnectionFactory(ConnectionFactory cf) {
    jmsTemplate = new JmsTemplate(cf);
}

public void setQueue(Queue queue) {
    this.destination = queue;
}

In my application context:

<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
    <property name="environment">
        <props>
            <prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
            <!-- <prop key="java.naming.provider.url">jnp://address.com:port</prop> -->
            <prop key="java.naming.factory.url.pkgs">org.jboss.naming:org.jnp.interfaces</prop>
        </props>
    </property>
</bean>

<bean id="connectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiTemplate" ref="jndiTemplate" />
    <property name="jndiName" value="ConnectionFactory" />
</bean>

<bean id="jmsQueueConnectionFactory"
    class="org.springframework.jms.connection.SingleConnectionFactory">
    <property name="targetConnectionFactory" ref="connectionFactory"/>
    <property name="pubSubDomain" value="false" />
</bean>

<bean id="jmsDestinationResolver"
    class="org.springframework.jms.support.destination.JndiDestinationResolver">
    <property name="jndiTemplate">
        <ref bean="jndiTemplate"/>
    </property>
    <property name="cache">
        <value>true</value>
    </property>
</bean>

<bean id="jmsQueueTemplate" class="org.springframework.jms.core.JmsTemplate102">
    <property name="connectionFactory" ref="jmsQueueConnectionFactory" />
    <property name="destinationResolver" ref="jmsDestinationResolver" />
    <property name="pubSubDomain" value="false" />
</bean>

<bean id="jmsSender" class="package.JmsQueueSender">
    <property name="queue" value="queue/AlertQueueGIAfterSent" />
    <property name="connectionFactory" ref="jmsQueueTemplate" />
</bean>
0

There are 0 best solutions below