ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("user", "password", "brokerUrl");
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer messageProducer = session.createProducer(session.createTopic("topic"));
MapMessage mapMessage= session.createMapMessage();
mapMessage.setInt("field0", 0);
mapMessage.setString("field1", "field1");
messageProducer.send(mapMessage);
session.close();
connection.close();
在pom.xml加入依赖
<dependency>
<groupId>org.apache.activemq</groupId> <artifactId>activemq-core</artifactId> <version>5.7.0</version> </dependency>