connectionFactoryAddresses= tcp://127.0.0.1:61616 connectionFactoryUsername=guest connectionFactoryPassword=guest
以下是使用Java编写的ActiveMQ Artemis client示例代码:
package org.apache.activemq.artemis.example;
import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage;
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
public class ArtemisProducer { public static void main(String[] args) throws Exception { Connection connection = null; try { // Step 1. Create an initial context to perform JNDI operations String brokerURL = "tcp://localhost:61616"; String userName = "username"; String password = "password"; ConnectionFactory cf = new ActiveMQConnectionFactory(brokerURL, userName, password);
// Step 2. Get a JMS connection from the connection factory
connection = cf.createConnection();
// Step 3. Open a session on the connection
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Step 4. Create a producer for the queue
MessageProducer producer = session.createProducer(session.createQueue("exampleQueue"));
// Step 5. Create a text message
TextMessage message = session.createTextMessage("Hello, Artemis!");
// Step 6. Send the message using the producer
producer.send(message);
System.out.println("Message sent successfully!");