1

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>
Michelle
  • 2,830
  • 26
  • 33
  • It actually can't connect to the broker: "`java.net.SocketTimeoutException: Receive timed out`" - which suggests there is some network/configuration issue. No messages are received yet. – Tomasz Nurkiewicz Oct 11 '12 at 17:18
  • What's the "broker"? Please tell me it's not the java.naming.provider.url? – Michelle Oct 11 '12 at 17:20
  • JMS broker - server that you connect to in order to send and receive messages. Apparently Spring can't connect to that server (deployed on JBoss) due to some network issue. Can you post full stack trace (at least last *Caused by*) or put it on gist.github.com or pastebin? – Tomasz Nurkiewicz Oct 11 '12 at 17:22
  • Full trace at http://pastebin.com/LUb8pg7C – Michelle Oct 11 '12 at 17:43
  • Thanks, looks like Spring can't connect to JNDI deployed on JBoss. Why is `"java.naming.provider.url"` commented out? It should point to `jnp://localhost:1099` if you are connecting to the same JBoss. – Tomasz Nurkiewicz Oct 11 '12 at 17:50
  • It's going to be deployed to a client's environment where they have their messaging system all set up, so I'll interpret this as "I'm screwed until we can deploy in their environment" (and never mind testing). I was hoping I wouldn't have to worry about the connection not actually existing until it actually tried to send something. Oh well. Is there anything other than the provider that you can see that obviously won't work, or does everything other than that look fine? – Michelle Oct 11 '12 at 18:03
  • Just setup JBoss (it's free and not that heavyweight these days) and use it for development. For unit and integration testing you can mock connection factory. The rest of your configuration looks fine. – Tomasz Nurkiewicz Oct 11 '12 at 18:07

0 Answers0