use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class PendingDeliveriesTest method internalNoReconnect.
private void internalNoReconnect(String uriToUse, String destinationName) throws Exception {
startClient(uriToUse, destinationName, true, false);
ConnectionFactory cf = createCF(uriToUse);
Connection connection = cf.createConnection();
connection.start();
try {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(destinationName);
MessageConsumer consumer = session.createConsumer(destination);
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
// give more time to receive first message but do not wait so long for last as all message were most likely sent
Assert.assertNotNull("consumer.receive(...) returned null for " + i + "th message. Number of expected messages" + " to be received is " + NUMBER_OF_MESSAGES, i == NUMBER_OF_MESSAGES - 1 ? consumer.receive(500) : consumer.receive(5000));
}
} finally {
connection.stop();
connection.close();
}
if (cf instanceof ActiveMQConnectionFactory) {
((ActiveMQConnectionFactory) cf).close();
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class ReplicationFlowControlTest method internalTest.
private void internalTest(boolean failover) throws Exception {
int KILL_SERVER = failover ? 50_000 : -1;
Connection connection = null;
try {
server0 = startServer(SERVER_NAME_0, 0, 30000);
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
connection = connectionFactory.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
Queue queue = session.createQueue("exampleQueue");
MessageProducer producer = session.createProducer(queue);
BytesMessage bytesMessage = session.createBytesMessage();
bytesMessage.writeBytes(new byte[20 * 1024]);
for (int i = 0; i < NUM_MESSAGES; i++) {
producer.send(bytesMessage);
if (i % 1000 == 0) {
System.out.println("Sent " + i + " messages, consumed=" + totalConsumed.get());
session.commit();
}
if (i == START_CONSUMERS) {
System.out.println("Starting consumers");
// if failover, no AMQP
startConsumers(!failover);
}
if (KILL_SERVER >= 0 && i == KILL_SERVER) {
session.commit();
System.out.println("Killing server");
ServerUtil.killServer(server0);
Thread.sleep(2000);
connection.close();
connection = connectionFactory.createConnection();
session = connection.createSession(true, Session.SESSION_TRANSACTED);
queue = session.createQueue("exampleQueue");
producer = session.createProducer(queue);
}
if (i == START_SERVER) {
System.out.println("Starting extra server");
server1 = startServer(SERVER_NAME_1, 0, 30000);
}
}
session.commit();
System.out.println("Awaiting all consumers to finish");
while (!latch.await(10, TimeUnit.SECONDS)) {
fail("couldn't receive all messages");
}
running.set(false);
for (Consumer consumer : consumers) {
consumer.join(10000);
if (consumer.isAlive()) {
consumer.interrupt();
}
}
} finally {
running.set(false);
if (connection != null) {
connection.close();
}
for (Consumer consumer : consumers) {
consumer.interrupt();
consumer.join();
}
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class StompTestBase method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
uri = new URI(scheme + "://" + hostname + ":" + port);
server = createServer();
server.start();
waitForServerToStart(server.getActiveMQServer());
connectionFactory = createConnectionFactory();
((ActiveMQConnectionFactory) connectionFactory).setCompressLargeMessage(isCompressLargeMessages());
if (isSecurityEnabled()) {
connection = connectionFactory.createConnection("brianm", "wombats");
} else {
connection = connectionFactory.createConnection();
}
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
queue = session.createQueue(getQueueName());
topic = session.createTopic(getTopicName());
connection.start();
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class HornetQProtocolManagerTest method testLegacy.
@Test
public void testLegacy() throws Exception {
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616?protocolManagerFactoryStr=" + HornetQClientProtocolManagerFactory.class.getName());
connectionFactory.createConnection().close();
ActiveMQConnectionFactory connectionFactory2 = new ActiveMQConnectionFactory("tcp://localhost:61617");
connectionFactory2.createConnection().close();
RecoveryManager manager = new RecoveryManager();
manager.register(connectionFactory, null, null, new ConcurrentHashMap<String, String>());
manager.register(connectionFactory2, null, null, new ConcurrentHashMap<String, String>());
for (XARecoveryConfig resource : manager.getResources()) {
try (ServerLocator locator = resource.createServerLocator();
ClientSessionFactory factory = locator.createSessionFactory();
ClientSession session = factory.createSession()) {
// Nothing
}
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.
the class AmqpPurgeOnNoConsumersTest method testPurgeQueueCoreRollback.
// I'm adding the core test here to compare semantics between AMQP and core on this test.
@Test(timeout = 60000)
public void testPurgeQueueCoreRollback() throws Exception {
String queue = "purgeQueue";
SimpleString ssQueue = new SimpleString(queue);
server.addAddressInfo(new AddressInfo(ssQueue, RoutingType.ANYCAST));
server.createQueue(ssQueue, RoutingType.ANYCAST, ssQueue, null, true, false, 1, true, false);
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:5672");
Connection connection = cf.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
MessageProducer producer = session.createProducer(session.createQueue("purgeQueue"));
javax.jms.Queue jmsQueue = session.createQueue(queue);
MessageConsumer consumer = session.createConsumer(jmsQueue);
for (int i = 0; i < 10; i++) {
Message message = session.createTextMessage("hello " + i);
producer.send(message);
}
session.commit();
QueueImpl queueView = (QueueImpl) getProxyToQueue(queue);
Wait.assertEquals(10, queueView::getMessageCount);
connection.start();
for (int i = 0; i < 10; i++) {
TextMessage txt = (TextMessage) consumer.receive(1000);
assertNotNull(txt);
assertEquals("hello " + i, txt.getText());
}
consumer.close();
session.rollback();
connection.close();
Wait.assertEquals(0, queueView::getMessageCount);
server.stop();
server.start();
queueView = (QueueImpl) getProxyToQueue(queue);
assertEquals(0, queueView.getMessageCount());
assertEquals(0L, queueView.getPageSubscription().getPagingStore().getAddressSize());
}
Aggregations