use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class ActiveMQAMQPAdmin method createConnectionFactory.
@Override
public void createConnectionFactory(String name) {
try {
final JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:61616");
context.bind(name, factory);
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class TestSimpleExpire method testSendExpire.
@Test
public void testSendExpire() throws Exception {
ConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:61616");
Connection connection = factory.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
Queue queue = session.createQueue("q0");
MessageProducer producer = session.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
producer.setTimeToLive(1000);
for (int i = 0; i < 20000; i++) {
producer.send(session.createTextMessage("expired"));
if (i % 5000 == 0) {
session.commit();
System.out.println("Sent " + i + " + messages");
}
}
session.commit();
Thread.sleep(5000);
producer.setTimeToLive(0);
for (int i = 0; i < 500; i++) {
producer.send(session.createTextMessage("ok"));
}
session.commit();
MessageConsumer consumer = session.createConsumer(queue);
connection.start();
for (int i = 0; i < 500; i++) {
TextMessage txt = (TextMessage) consumer.receive(10000);
Assert.assertNotNull(txt);
Assert.assertEquals("ok", txt.getText());
}
session.commit();
}
use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class AmqpTransactionTest method testSendPersistentTX.
@Test(timeout = 120000)
public void testSendPersistentTX() throws Exception {
int MESSAGE_COUNT = 2000;
AtomicInteger errors = new AtomicInteger(0);
server.createQueue(SimpleString.toSimpleString("q1"), RoutingType.ANYCAST, SimpleString.toSimpleString("q1"), null, true, false, 1, false, true);
ConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:" + AMQP_PORT);
Connection sendConnection = factory.createConnection();
Connection consumerConnection = factory.createConnection();
try {
Thread receiverThread = new Thread() {
@Override
public void run() {
try {
consumerConnection.start();
Session consumerSession = consumerConnection.createSession(true, Session.SESSION_TRANSACTED);
javax.jms.Queue q1 = consumerSession.createQueue("q1");
MessageConsumer consumer = consumerSession.createConsumer(q1);
for (int i = 1; i <= MESSAGE_COUNT; i++) {
Message message = consumer.receive(5000);
if (message == null) {
throw new IOException("No message read in time.");
}
if (i % 100 == 0) {
if (i % 1000 == 0)
System.out.println("Read message " + i);
consumerSession.commit();
}
}
// Assure that all messages are consumed
consumerSession.commit();
} catch (Exception e) {
e.printStackTrace();
errors.incrementAndGet();
}
}
};
receiverThread.start();
Session sendingSession = sendConnection.createSession(true, Session.SESSION_TRANSACTED);
javax.jms.Queue q1 = sendingSession.createQueue("q1");
MessageProducer producer = sendingSession.createProducer(q1);
producer.setDeliveryDelay(DeliveryMode.NON_PERSISTENT);
for (int i = 0; i < MESSAGE_COUNT; i++) {
producer.send(sendingSession.createTextMessage("message " + i), DeliveryMode.PERSISTENT, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
if (i % 100 == 0) {
if (i % 1000 == 0)
System.out.println("Sending " + i);
sendingSession.commit();
}
}
sendingSession.commit();
receiverThread.join(50000);
Assert.assertFalse(receiverThread.isAlive());
Assert.assertEquals(0, errors.get());
} catch (Exception e) {
e.printStackTrace();
} finally {
sendConnection.close();
consumerConnection.close();
}
}
use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class AmqpFailoverEndpointDiscoveryTest method testFailoverListWithAMQP.
@Test(timeout = 120000)
public void testFailoverListWithAMQP() throws Exception {
JmsConnectionFactory factory = getJmsConnectionFactory();
try (Connection connection = factory.createConnection()) {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue(ADDRESS.toString());
MessageProducer producer = session.createProducer(queue);
producer.send(session.createTextMessage("hello before failover"));
liveServer.crash(true, true);
producer.send(session.createTextMessage("hello after failover"));
MessageConsumer consumer = session.createConsumer(queue);
connection.start();
TextMessage receive = (TextMessage) consumer.receive(5000);
Assert.assertNotNull(receive);
Assert.assertEquals("hello before failover", receive.getText());
receive = (TextMessage) consumer.receive(5000);
Assert.assertEquals("hello after failover", receive.getText());
Assert.assertNotNull(receive);
}
}
use of org.apache.qpid.jms.JmsConnectionFactory in project activemq-artemis by apache.
the class AmqpDescribedTypePayloadTest method testDescribedTypeMessageRoundTrips.
@Test(timeout = 60000)
public void testDescribedTypeMessageRoundTrips() throws Exception {
AmqpClient client = createAmqpClient();
AmqpConnection connection = addConnection(client.connect());
AmqpSession session = connection.createSession();
// Send with AMQP client.
AmqpSender sender = session.createSender(getQueueName());
AmqpMessage message = new AmqpMessage();
message.setDescribedType(new AmqpNoLocalFilter());
sender.send(message);
sender.close();
Queue queue = getProxyToQueue(getQueueName());
Wait.assertEquals(1, queue::getMessageCount);
// Receive and resend with Qpid JMS client
JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
Connection jmsConnection = factory.createConnection();
try {
Session jmsSession = jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = jmsSession.createQueue(getName());
MessageConsumer jmsConsumer = jmsSession.createConsumer(destination);
jmsConnection.start();
Message received = jmsConsumer.receive(5000);
assertNotNull(received);
assertTrue(received instanceof ObjectMessage);
MessageProducer jmsProducer = jmsSession.createProducer(destination);
jmsProducer.send(received);
} finally {
jmsConnection.close();
}
assertEquals(1, queue.getMessageCount());
// Now lets receive it with AMQP and see that we get back what we expected.
AmqpReceiver receiver = session.createReceiver(getQueueName());
receiver.flow(1);
AmqpMessage returned = receiver.receive(5, TimeUnit.SECONDS);
assertNotNull(returned);
assertNotNull(returned.getDescribedType());
receiver.close();
connection.close();
}
Aggregations