使用Spring JmsTemplate发送JMS消息

时间:2012-10-11 17:13:06

标签: spring jms spring-jms jmstemplate

我有一台服务器需要将消息发送到单独的应用程序。我正在使用Spring JmsTemplate,但是,我遇到了一些启动和运行配置的问题。

现在,我遇到以下异常:

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]

(如果你愿意,我可以发布完整的堆栈跟踪,但它只是那些嵌套异常的长版本。)

“接收超时”部分听起来像是在尝试接收消息,我不想这样做。这里的所有内容都是从几个不同的例子和SO帖子中汇总而来的,而我却无法绕过所有不同的部分和他们正在做的事情。除了可能导致错误的任何内容之外,如果我没有收到消息,还有什么我不需要的吗?

在我的JmsQueueSender类中(发送消息):

private JmsTemplate jmsTemplate;
private Destination destination;

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

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

在我的应用程序上下文中:

<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 个答案:

没有答案
相关问题