我最近两天都在处理简单的任务,我已经在JBOSS6.x中配置了jms消息队列。我在spring中使用applicationContext.xml文件中的jmstemplate配置了jndi、jms MQ,
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean id="messageListener" class="com.test.QueuereceiverDB" />
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.provider.url">localhost:1099</prop>
<prop key="java.naming.factory.url.pkgs">org.jnp.interfaces:org.jboss.naming</prop>
<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
</props>
</property>
</bean>
<bean id="queueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate" />
</property>
<property name="jndiName">
<value>ConnectionFactory</value>
</property>
</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="QueueTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory">
<ref bean="queueConnectionFactory" />
</property>
<property name="destinationResolver">
<ref bean="jmsDestinationResolver" />
</property>
</bean>
<bean id="jmsSender" class="com.test.MessageSender">
<property name="jmsTemplate"> <ref bean="QueueTemplate" />
</property>
</bean>
<bean id="Queue" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate"> <ref bean="jndiTemplate" />
</property>
<property name="jndiName">
<value>queue/MyQueue</value>
</property>
</bean>
<bean id="jmscontainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="concurrentConsumers" value="5" />
<property name="connectionFactory" ref="queueConnectionFactory" />
<property name="destination" ref="Queue" />
<property name="messageListener" ref="messageListener" />
</bean>
下面是邮件发送者
package com.test;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
public class MessageSender {
private JmsTemplate jmsTemplate;
public void setJmsTemplate(JmsTemplate jmsTemplate) {
this.jmsTemplate = jmsTemplate;
}
public void sendMesage() {
MessageCreator messageCreator=new MessageCreator() {
public Message createMessage(Session session) throws
JMSException {
return session.createTextMessage("I am sending Invoice message");}
};
jmsTemplate.send("queue/MyQueue", messageCreator);
}
}
public class QueuereceiverDB implements MessageListener {
/**
* Default constructor.
*/
public QueuereceiverDB() {
// TODO Auto-generated constructor stub
}
/**
* @see MessageListener#onMessage(Message)
*/
public void onMessage(Message message) {
try {
if (message instanceof TextMessage) {
System.out.println("Queue: I received a TextMessage at "
+ new Date());
TextMessage msg = (TextMessage) message;
System.out.println("Message is : " + msg.getText());
} else {
System.out.println("Not valid message for this Queue MDB");
}
} catch (JMSException e) {
e.printStackTrace();
}
}
Caused by: java.lang.RuntimeException: Neither any mapped-name/lookup/jndi-name specified nor any ResourceProvider could process resource-ref named env/ConnectionFactory of type javax.jms.QueueConnectionFactory
at org.jboss.switchboard.mc.resource.provider.ResourceRefResourceProviderDelegator.provide(ResourceRefResourceProviderDelegator.java:125) [:1.0.0-alpha-15]
at org.jboss.switchboard.mc.resource.provider.ResourceRefResourceProviderDelegator.provide(ResourceRefResourceProviderDelegator.java:44) [:1.0.0-alpha-15]
at org.jboss.switchboard.mc.JndiEnvironmentProcessor.process(JndiEnvironmentProcessor.java:68) [:1.0.0-alpha-15]
at org.jboss.switchboard.mc.deployer.AbstractSwitchBoardDeployer.process(AbstractSwitchBoardDeployer.java:119) [:1.0.0-alpha-15]
at org.jboss.switchboard.mc.deployer.WebEnvironmentSwitchBoardDeployer.internalDeploy(WebEnvironmentSwitchBoardDeployer.java:66) [:1.0.0-alpha-15]
at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:55) [:2.2.0.GA]
at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:179) [:2.2.0.GA]
<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="urn:hornetq"
xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd" >
<queue name="MyQueue2" >
<entry name="/queue/MyQueue" />
</queue>
</configuration>
所有这些都是正确的,您是否可以验证在web.xml中声明了ressources:
<resource-ref>
<res-ref-name>ConnectionFactory</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<resource-ref>
<res-ref-name>queue/MyQueue</res-ref-name>
<res-type>javax.jms.Queue</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
我正在读一条来自Solace的信息。我能够成功地阅读信息。假设我正在阅读一条消息,在侦听器线程上读取/处理消息时,应用程序崩溃。那我怎么能在那上面再读一遍那条信息呢。使用下面的代码,我无法再次阅读该消息。下面是我的配置
当BOTHRESH=0时,MQ JMS类是否可以重新传递消息? 使用上述设置,是否可以使用重新传递计数通过应用程序代码管理邮件传递重试?
我们有一个camel路由,在这里我们从输入队列读取消息,处理它,设置一些JMS头(使用exchange.getin().setheader(...)),然后将消息路由到某个输出队列。在MQ故障转移方案期间,将重新传递消息。但是,当重新传递消息时,我前面放置的JMS头丢失了。是否有任何方法可以在重新交付后保留JMS头?
我读到:http://www.javaworld.com/article/2074123/java-web-development/transaction-and-redelivery-in-jms.html?page=2 "通常,确认特定消息会确认会话接收的所有先前消息"(在客户端确认模式下) “邮件重新传递不是自动的,但在某些情况下会重新传递邮件” 我的问题是: 如何确保每次收到消息时都有一个
问题内容: 我正在尝试创建一个Java Application Client项目,该项目将JMS消息发送到Glassfish服务器上的队列。 问题在于,应用发送完消息后,它在应退出时挂起。该消息已成功传输,但是由于某种原因该应用程序没有退出。我已经尝试调试该应用程序,并且可以将其一直走到的结尾,这就是它的挂起位置。 这是代码: 如何使其停止挂起? 问题答案: 长期以来,它一直是Glassfish中
我正在使用WerbLogic 10.3.5和Spring 3.0实现JMS队列。我有以下Spring配置: 我的消息创建代码如下所示: 我的听众是这样的: 消息被正确创建,侦听器的onMessage()方法被调用,但是如果逻辑失败,我抛出RuntimeException(),消息不会被重新传递。我尝试了上述代码的许多细微变化(例如设置SessionAcknowledgeMemodeName=SES