我们在weblogic10.3.4和JMS队列上设置了,下面是消息监听代码,它使用了Spring JMS,MessageProducer设置为ClientAcknowledgeMode。当发生异常时,消息仍然被移出队列并回滚,下面的代码有什么问题吗?
public class EmailListener implements MessageListener,ExceptionListener{
private EmailSend emailSend;
@SuppressWarnings("unchecked")
public void onMessage(Message message){
ObjectMessage om ;
try {
if(message instanceof ObjectMessage) {
om = (ObjectMessage)message;
emailSend.sendEmail((Map<String, String>)om.getObject());
//throw new JMSException("Test");
om.acknowledge();
}
}
catch(MailException me) {
logger.error("Mail server exception in sending email",me);
throw new RuntimeException(me);
}catch(JMSException jmse) {
logger.error("Error in sending email",jmse);
throw new RuntimeException(jmse);
}
}
public void setEmailSend(EmailSend emailSend){
this.emailSend = emailSend;
}
public void onException(JMSException jmse){
logger.error("Exception in sending email",jmse);
}
public void acknowledge(
) throws JMSException{
}
}
下面是Spring配置
<!--Spring JMS Message Listener Container -->
<bean id="jmsContainer"
class="org.springframework.jms.listener.DefaultMessageListenerContainer"
p:autoStartup="true" p:destination-ref="queue"
p:destinationResolver-ref="jmsDestinationResolver"
p:connectionFactory-ref="authenticationConnectionFactory"
p:exceptionListener-ref="emailListener"
p:messageListener-ref="emailListener" />