如果接收队列中断,我想捕获一个异常,并且我知道连接上有一个函数setExceptionListener。我不明白在使用@JmsListener和DefaultJmsListenerContainerFactory时如何设置此功能。有人可以指出我正确的方向。我也尝试使用JmsListenerEndpointRegistry,但是我无法访问与setExceptionListener的连接。我用过 @JmsListener(目的地=“ $ {mq.incoming-queueProducts}”,containerFactory =“ DefaultJmsListenerContainerFactory”)
@Bean(name = "DefaultJmsListenerContainerFactory")
public DefaultJmsListenerContainerFactory provideJmsListenerContainerFactory(
DefaultJmsListenerContainerFactoryConfigurer configurer) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setRecoveryInterval(10000L);
configurer.configure(factory, connectionFactory());
return factory;
}
@Bean(name = "JmsTemplate")
public JmsTemplate provideJmsTemplate() {
JmsTemplate jmsTemplate = new JmsTemplate(connectionFactory());
return jmsTemplate;
}
private ConnectionFactory connectionFactory() {
ConnectionFactory factory = null;
try {
factory = new MQConnectionFactory();
((MQConnectionFactory) factory).setHostName(properties.getHost());
((MQConnectionFactory) factory).setPort(properties.getPort());
((MQConnectionFactory) factory).setQueueManager(properties.getQueueManager());
((MQConnectionFactory) factory).setChannel(properties.getChannel());
((MQConnectionFactory) factory).setTransportType(WMQConstants.WMQ_CM_CLIENT);
} catch (JMSException e) {
throw new RuntimeException(e);
}
return factory;
}
@ConfigurationProperties(prefix = "mq")
public static class MQProperties {
String queueManager;
String host;
int port;
String channel;
String incomingQueueProducts;
String incomingQueueStores;
String incomingQueueShipments;
public String getQueueManager() {
return queueManager;
}
public void setQueueManager(String queueManager) {
this.queueManager = queueManager;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public String getChannel() {
return channel;
}
public void setChannel(String channel) {
this.channel = channel;
}
public String getIncomingQueueProducts() {
return incomingQueueProducts;
}
public void setIncomingQueueProducts(String incomingQueueProducts) {
this.incomingQueueProducts = incomingQueueProducts;
}
public String getIncomingQueueStores() {
return incomingQueueStores;
}
public void setIncomingQueueStores(String incomingQueueStores) {
this.incomingQueueStores = incomingQueueStores;
}
public String getIncomingQueueShipments() {
return incomingQueueShipments;
}
public void setIncomingQueueShipments(String incomingQueueShipments) {
this.incomingQueueShipments = incomingQueueShipments;
}
}
谢谢。