apache官网下载了5.9.1很扯淡的,3次无法解压成功,换了4次镜像,算是解压好了。。。
activemq.bat运行显示:
…
WARN | Store limit is 102400 mb (current store usage is 0 mb). The data directo
ry: E:\workspace\apache-activemq-5.9.1\bin\..\data\kahadb only has 35873 mb of u
sable space – resetting to maximum available disk space: 35873 mb
ERROR | Temporary Store limit is 51200 mb, whilst the temporary data directory:
E:\workspace\apache-activemq-5.9.1\bin\..\data\localhost\tmp_storage only has 35
873 mb of usable space – resetting to maximum available 35873 mb.
…
出了个错误,不过能正常使用,
目前还不知道有什么影响。
后台地址
http://localhost:8161/admin
admin/admin
可以正常打开
运行webappdemo
提示
 missing brokerURL (specified via org.apache.activemq.brokerURL init-Param) or embedded broker
 呃呃,又找了个简单例子:
代码来源:http://blog.csdn.net/jason5186/article/details/9196041
发送:
public class JmsSender {
public static void main(String[] args) throws JMSException{
	ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(“tcp://127.0.0.1:61616”);    
    Connection connection = connectionFactory.createConnection();
    connection.start();
;//    connection.
    Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue(“Test.foo”);    
    MessageProducer producer = session.createProducer(destination);
    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
    for(int i=0; i<100; i++) {    
        int id = i+1;  
        ObjectMessage message = session.createObjectMessage();  
        message.setObject(new User(id, "张三"+id, "123456"));  
        producer.send(message);    
    }    
    session.commit();  
    session.close();    
    connection.close();  
}
}
之后能在后台看见队列中的内容
接收
public class JmsReceiver {
	public static void main(String[] args) throws JMSException, InterruptedException{
	    ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");    
        
        Connection connection = connectionFactory.createConnection();    
        connection.start();  
        
        final Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);    
        Destination destination = session.createQueue("Test.foo");  
          
        MessageConsumer consumer = session.createConsumer(destination);  
        //listener 方式   
        consumer.setMessageListener(new MessageListener() {   
       
            public void onMessage(Message msg) {   
                ObjectMessage message = (ObjectMessage) msg;   
                //TODO something....   
                try {  
                    User user = (User) message.getObject();  
                    System.out.println("收到消息:"+user);  
                } catch (JMSException e1) {  
                    // TODO Auto-generated catch block  
                    e1.printStackTrace();  
                }   
                try {  
                    session.commit();  
                } catch (JMSException e) {  
                    // TODO Auto-generated catch block  
                    e.printStackTrace();  
                }   
            }   
       
        });   
        TimeUnit.MINUTES.sleep(1);   
        
        session.close();    
        connection.close();  
	}
}