Spring JMS (1)
1. DestinationResolver
将给定的目的地地址解析为目的地实例。
Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain)throws JMSException;
public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain)throws JMSException {Assert.notNull(session, "Session must not be null");Assert.notNull(destinationName, "Destination name must not be null");if (pubSubDomain) { //return resolveTopic(session, destinationName);}else {return resolveQueue(session, destinationName);}}
protected Topic resolveTopic(Session session, String topicName) throws JMSException {if (session instanceof TopicSession) {// Cast to TopicSession: will work on both JMS 1.1 and 1.0.2return ((TopicSession) session).createTopic(topicName);}else {// Fall back to generic JMS Session: will only work on JMS 1.1return session.createTopic(topicName);}}protected Queue resolveQueue(Session session, String queueName) throws JMSException {if (session instanceof QueueSession) {// Cast to QueueSession: will work on both JMS 1.1 and 1.0.2return ((QueueSession) session).createQueue(queueName);}else {// Fall back to generic JMS Session: will only work on JMS 1.1return session.createQueue(queueName);}}
void removeFromCache(String destinationName);void clearCache(); //清空所有目的地缓存
private boolean cache = true;private boolean fallbackToDynamicDestination = false;
public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain)throws JMSException {Assert.state(this.beanFactory != null, "BeanFactory is required");try {return (Destination) this.beanFactory.getBean(destinationName, Destination.class);}catch (BeansException ex) {throw new DestinationResolutionException("Failed to look up Destinaton bean with name '" + destinationName + "'", ex);}}