1
我們在這個weblogic10.3.4和JMS隊列上建立了,下面是消息監聽器代碼,它使用Spring JMS,MessageProducer設置爲ClientAcknowledgeMode。當發生異常時,消息仍然被移出隊列並回滾,下面的代碼有什麼問題?weblogic JMS隊列消息沒有回滾到異常
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" />