use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class ArtemisAMQPClientFeatureIT method testArtemisAMQPClient.
@Test
public void testArtemisAMQPClient() throws Exception {
// setup connection
ConnectionFactory connectionFactory = new JmsConnectionFactory("amqp://localhost:5672");
try (Connection connection = connectionFactory.createConnection()) {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// send message
Queue queue = session.createQueue("artemisAMPQClientFeatureITQueue");
MessageProducer sender = session.createProducer(queue);
String message = "Hello world ";
sender.send(session.createTextMessage(message));
// receive message and assert
connection.start();
MessageConsumer consumer = session.createConsumer(queue);
TextMessage m = (TextMessage) consumer.receive(5000);
assertEquals(message, m.getText());
}
}
use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class ArtemisFeatureTest method test.
@Test(timeout = 5 * 60 * 1000)
public void test() throws Throwable {
executeCommand("bundle:list");
withinReason(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
assertTrue("artemis bundle installed", verifyBundleInstalled("artemis-server-osgi"));
return true;
}
});
Object service = waitForService("(objectClass=org.apache.activemq.artemis.core.server.ActiveMQServer)", 30000);
assertNotNull(service);
LOG.info("have service " + service);
executeCommand("service:list -n");
Connection connection = null;
try {
JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:5672");
connection = factory.createConnection(USER, PASSWORD);
connection.start();
QueueSession sess = (QueueSession) connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
Queue queue = sess.createQueue("exampleQueue");
MessageProducer producer = sess.createProducer(queue);
producer.send(sess.createTextMessage("TEST"));
// Test browsing
try (QueueBrowser browser = sess.createBrowser(queue)) {
Enumeration messages = browser.getEnumeration();
while (messages.hasMoreElements()) {
messages.nextElement();
}
}
// Test management
Queue managementQueue = sess.createQueue("activemq.management");
QueueRequestor requestor = new QueueRequestor(sess, managementQueue);
connection.start();
TextMessage m = sess.createTextMessage();
m.setStringProperty("_AMQ_ResourceName", "broker");
m.setStringProperty("_AMQ_OperationName", "getQueueNames");
m.setText("[\"ANYCAST\"]");
Message reply = requestor.request(m);
String json = ((TextMessage) reply).getText();
JsonArray array = Json.createReader(new StringReader(json)).readArray();
List<JsonString> queues = (List<JsonString>) array.get(0);
assertNotNull(queues);
assertFalse(queues.isEmpty());
MessageConsumer consumer = sess.createConsumer(queue);
Message msg = consumer.receive(5000);
assertNotNull(msg);
} finally {
if (connection != null) {
connection.close();
}
}
}
use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class PerfBase method init.
private void init() throws Exception {
if (perfParams.isOpenwire()) {
factory = new org.apache.activemq.ActiveMQConnectionFactory(perfParams.getUri());
destination = new org.apache.activemq.command.ActiveMQQueue(perfParams.getDestinationName());
connection = factory.createConnection();
} else if (perfParams.isCore()) {
factory = new org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory(perfParams.getUri());
destination = new org.apache.activemq.artemis.jms.client.ActiveMQQueue(perfParams.getDestinationName());
connection = factory.createConnection();
} else if (perfParams.isAMQP()) {
factory = new JmsConnectionFactory(perfParams.getUri());
destination = new org.apache.activemq.artemis.jms.client.ActiveMQQueue(perfParams.getDestinationName());
connection = factory.createConnection();
Session sessionX = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
destination = sessionX.createQueue(perfParams.getDestinationName());
sessionX.close();
}
session = connection.createSession(perfParams.isSessionTransacted(), perfParams.isDupsOK() ? Session.DUPS_OK_ACKNOWLEDGE : Session.AUTO_ACKNOWLEDGE);
}
use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class InterceptorExample method main.
public static void main(final String[] args) throws Exception {
JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:61616");
try (Connection connection = factory.createConnection()) {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue interceptorQueue = session.createQueue("interceptorQueue");
MessageProducer producer = session.createProducer(interceptorQueue);
TextMessage textMessage = session.createTextMessage("A text message");
textMessage.setStringProperty("SimpleAmqpInterceptor", "SimpleAmqpInterceptorValue");
producer.send(textMessage);
}
}
use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class BrokerPluginExample method sendConsumeAMQP.
private static void sendConsumeAMQP() throws JMSException {
Connection connection = null;
ConnectionFactory connectionFactory = new JmsConnectionFactory("amqp://localhost:5672");
try {
// Create an amqp qpid 1.0 connection
connection = connectionFactory.createConnection();
// Create a session
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create a sender
Queue queue = session.createQueue("exampleQueue");
MessageProducer sender = session.createProducer(queue);
// send a few simple message
sender.send(session.createTextMessage("Hello world "));
connection.start();
// create a moving receiver, this means the message will be removed from the queue
MessageConsumer consumer = session.createConsumer(queue);
// receive the simple message
TextMessage m = (TextMessage) consumer.receive(5000);
if (m.getStringProperty("count") == null) {
throw new RuntimeException(("missed property count"));
}
System.out.println("message = " + m.getText() + " property count (added by interceptor = " + m.getStringProperty("count") + ")");
} finally {
if (connection != null) {
// close the connection
connection.close();
}
}
}
Aggregations