Search in sources :

Example 86 with ActiveMQConnectionFactory

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();
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) Destination(javax.jms.Destination) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) Session(javax.jms.Session)

Example 87 with ActiveMQConnectionFactory

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();
        }
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) BytesMessage(javax.jms.BytesMessage) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) Session(javax.jms.Session)

Example 88 with ActiveMQConnectionFactory

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();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) URI(java.net.URI) Before(org.junit.Before)

Example 89 with ActiveMQConnectionFactory

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
        }
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) RecoveryManager(org.apache.activemq.artemis.ra.recovery.RecoveryManager) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) XARecoveryConfig(org.apache.activemq.artemis.service.extensions.xa.recovery.XARecoveryConfig) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 90 with ActiveMQConnectionFactory

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());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)221 Test (org.junit.Test)141 Connection (javax.jms.Connection)84 Session (javax.jms.Session)84 MessageProducer (javax.jms.MessageProducer)63 MessageConsumer (javax.jms.MessageConsumer)60 TextMessage (javax.jms.TextMessage)49 Queue (javax.jms.Queue)48 ConnectionFactory (javax.jms.ConnectionFactory)35 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)27 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)26 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)24 ActiveMQResourceAdapter (org.apache.activemq.artemis.ra.ActiveMQResourceAdapter)24 URI (java.net.URI)22 JMSException (javax.jms.JMSException)20 Message (javax.jms.Message)19 DiscoveryGroupConfiguration (org.apache.activemq.artemis.api.core.DiscoveryGroupConfiguration)19 InitialContext (javax.naming.InitialContext)16 Context (javax.naming.Context)15 Hashtable (java.util.Hashtable)14