// Path: src/main/java/org/springside/examples/quickstart/jms/NotifyMessageListener.java
// public class NotifyMessageListener implements MessageListener {
// 
// 	private static Logger logger = LoggerFactory.getLogger(NotifyMessageListener.class);
// 
// //	@Autowired(required = false)
// //	private SimpleMailService simpleMailService;
// 
// 	/**
// 	 * MessageListener回调函数.
// 	 */
// 	@Override
// 	public void onMessage(Message message) {
// 		try {
// 			MapMessage mapMessage = (MapMessage) message;
// 			// 打印消息详情
// 			logger.info("UserName:{}, Email:{}", mapMessage.getString("userName"), mapMessage.getString("email"));
// 
// 			// 发送邮件
// //			if (simpleMailService != null) {
// //				simpleMailService.sendNotificationMail(mapMessage.getString("userName"));
// //			}
// 		} catch (Exception e) {
// 			logger.error("处理消息时发生异常.", e);
// 		}
// 	}
// }


import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.connection.CachingConnectionFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
import org.springside.examples.quickstart.jms.NotifyMessageListener;
import javax.jms.MessageListener;
import javax.jms.Queue;
import javax.jms.Topic;
    public Queue queue() {
        return new ActiveMQQueue("q.notify");
    }

    @Bean(name = "notifyTopic")
    public Topic topic() {
        return new ActiveMQTopic("t.notify");
    }

    @Bean
    public DefaultMessageListenerContainer queueContainer() {
        DefaultMessageListenerContainer queueContainer = new DefaultMessageListenerContainer();
        queueContainer.setConnectionFactory(connectionFactory());
        queueContainer.setDestination(queue());
        queueContainer.setMessageListener(notifyMessageListener());
        queueContainer.setConcurrentConsumers(10);
        return queueContainer;
    }

    @Bean
    public DefaultMessageListenerContainer topicContainer() {
        DefaultMessageListenerContainer topicContainer = new DefaultMessageListenerContainer();
        topicContainer.setConnectionFactory(connectionFactory());
        topicContainer.setDestination(topic());
        topicContainer.setMessageListener(notifyMessageListener());
        return topicContainer;
    }

    @Bean
    public MessageListener notifyMessageListener() {
// Path: src/main/java/org/springside/examples/quickstart/jms/NotifyMessageListener.java
// public class NotifyMessageListener implements MessageListener {
// 
// 	private static Logger logger = LoggerFactory.getLogger(NotifyMessageListener.class);
// 
// //	@Autowired(required = false)
// //	private SimpleMailService simpleMailService;
// 
// 	/**
// 	 * MessageListener回调函数.
// 	 */
// 	@Override
// 	public void onMessage(Message message) {
// 		try {
// 			MapMessage mapMessage = (MapMessage) message;
// 			// 打印消息详情
// 			logger.info("UserName:{}, Email:{}", mapMessage.getString("userName"), mapMessage.getString("email"));
// 
// 			// 发送邮件
// //			if (simpleMailService != null) {
// //				simpleMailService.sendNotificationMail(mapMessage.getString("userName"));
// //			}
// 		} catch (Exception e) {
// 			logger.error("处理消息时发生异常.", e);
// 		}
// 	}
// }


// Path: src/main/java/org/springside/examples/quickstart/config/ActiveMQConfiguration.java
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.connection.CachingConnectionFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
import org.springside.examples.quickstart.jms.NotifyMessageListener;
import javax.jms.MessageListener;
import javax.jms.Queue;
import javax.jms.Topic;

    public Queue queue() {
        return new ActiveMQQueue("q.notify");
    }

    @Bean(name = "notifyTopic")
    public Topic topic() {
        return new ActiveMQTopic("t.notify");
    }

    @Bean
    public DefaultMessageListenerContainer queueContainer() {
        DefaultMessageListenerContainer queueContainer = new DefaultMessageListenerContainer();
        queueContainer.setConnectionFactory(connectionFactory());
        queueContainer.setDestination(queue());
        queueContainer.setMessageListener(notifyMessageListener());
        queueContainer.setConcurrentConsumers(10);
        return queueContainer;
    }

    @Bean
    public DefaultMessageListenerContainer topicContainer() {
        DefaultMessageListenerContainer topicContainer = new DefaultMessageListenerContainer();
        topicContainer.setConnectionFactory(connectionFactory());
        topicContainer.setDestination(topic());
        topicContainer.setMessageListener(notifyMessageListener());
        return topicContainer;
    }

    @Bean
    public MessageListener notifyMessageListener() {
        return new NotifyMessageListener();