ActiveMQ学习之路 一
程序员文章站
2022-07-15 09:43:12
...
安装
http://activemq.apache.org/components/classic/
启动
apache-activemq-5.15.13\bin\win64
activemq.bat
测试代码
package com.test.activemq;
import org.apache.activemq.ActiveMQConnectionFactory;
import javax.jms.*;
public class ActiveMQTest {
public static void main(String[] args) throws JMSException {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616?connectionTimeout=3000&persistent=false&useJmx=true");
Connection connection = null;
try {
connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination test = session.createQueue("test");
TextMessage textMessage = session.createTextMessage("收到了没");
MessageProducer producer = session.createProducer(test);
producer.send(textMessage);
} catch (JMSException e) {
e.printStackTrace();
}finally {
if(connection != null){
connection.close();
}
}
}
}
javax.jms.JMSException: Could not create Transport. Reason: java.lang.IllegalArgumentException: Invalid connect parameters: {useJmx=true, persistent=false}
persistent=false&useJmx=true 去掉后是可以运行的
web程序broker地址是tcp
vm方式可以用来playback, 模拟消息同步