Apache ActiveMQ 支持 Windows 操作系统,但目前官方文档没有明确指出其是否支持 Windows Server 2022。
如果需要在 Windows Server 2022 上运行 Apache ActiveMQ,可以通过以下步骤进行安装:
下载 Apache ActiveMQ 安装包,官方下载地址:http://activemq.apache.org/download.html;
解压缩安装包至指定目录;
配置 JAVA 环境变量,确保 JDK 已经正确安装并配置好 JAVA_HOME 环境变量;
打开命令行窗口,进入 Apache ActiveMQ 安装目录,执行以下命令启动 ActiveMQ 服务:
bin\activemq start
另外,如果还需要通过代码示例来运行 Apache ActiveMQ,可以参考以下示例进行操作:
import javax.jms.*;
public class ActiveMQTest { public static void main(String[] args) { ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection connection = null; try { // 创建连接 connection = connectionFactory.createConnection(); connection.start();
// 创建会话
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// 创建队列
Queue queue = session.createQueue("hello.queue");
// 创建生产者
MessageProducer producer = session.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// 发送消息
TextMessage message = session.createTextMessage();
message.setText("hello, world!");
producer.send(message);
System.out.println("Message sent successfully.");
} catch (JMSException e) {
e.printStackTrace();
} finally {
// 关闭连接
if (connection != null) {
try {
connection.close();
} catch (JMSException e) {
e.printStackTrace();
}
}
}
}
}
通过以上代码,可以成功发送指定消息至队列 hello.queue。