Search in sources :

Example 56 with ActiveMQConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class RedeployTest method testRedeploy.

@Test
public void testRedeploy() throws Exception {
    Path brokerXML = getTestDirfile().toPath().resolve("broker.xml");
    URL url1 = RedeployTest.class.getClassLoader().getResource("reload-test-jms.xml");
    URL url2 = RedeployTest.class.getClassLoader().getResource("reload-test-updated-jms.xml");
    Files.copy(url1.openStream(), brokerXML);
    EmbeddedJMS embeddedJMS = new EmbeddedJMS();
    embeddedJMS.setConfigResourcePath(brokerXML.toUri().toString());
    embeddedJMS.start();
    final ReusableLatch latch = new ReusableLatch(1);
    Runnable tick = new Runnable() {

        @Override
        public void run() {
            latch.countDown();
        }
    };
    embeddedJMS.getActiveMQServer().getReloadManager().setTick(tick);
    try {
        latch.await(10, TimeUnit.SECONDS);
        Assert.assertEquals("DLQ", embeddedJMS.getActiveMQServer().getAddressSettingsRepository().getMatch("jms").getDeadLetterAddress().toString());
        Assert.assertEquals("ExpiryQueue", embeddedJMS.getActiveMQServer().getAddressSettingsRepository().getMatch("jms").getExpiryAddress().toString());
        Assert.assertFalse(tryConsume());
        Files.copy(url2.openStream(), brokerXML, StandardCopyOption.REPLACE_EXISTING);
        brokerXML.toFile().setLastModified(System.currentTimeMillis() + 1000);
        latch.setCount(1);
        embeddedJMS.getActiveMQServer().getReloadManager().setTick(tick);
        latch.await(10, TimeUnit.SECONDS);
        Assert.assertTrue(tryConsume());
        Assert.assertEquals("NewQueue", embeddedJMS.getActiveMQServer().getAddressSettingsRepository().getMatch("jms").getDeadLetterAddress().toString());
        Assert.assertEquals("NewQueue", embeddedJMS.getActiveMQServer().getAddressSettingsRepository().getMatch("jms").getExpiryAddress().toString());
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
        try (Connection connection = factory.createConnection()) {
            Session session = connection.createSession();
            Queue queue = session.createQueue("DivertQueue");
            MessageProducer producer = session.createProducer(queue);
            producer.send(session.createTextMessage("text"));
            connection.start();
            MessageConsumer consumer = session.createConsumer(session.createQueue("NewQueue"));
            Assert.assertNotNull("Divert wasn't redeployed accordingly", consumer.receive(5000));
        }
    } finally {
        embeddedJMS.stop();
    }
}
Also used : Path(java.nio.file.Path) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) EmbeddedJMS(org.apache.activemq.artemis.jms.server.embedded.EmbeddedJMS) MessageConsumer(javax.jms.MessageConsumer) ReusableLatch(org.apache.activemq.artemis.utils.ReusableLatch) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) Queue(javax.jms.Queue) URL(java.net.URL) Session(javax.jms.Session) Test(org.junit.Test)

Example 57 with ActiveMQConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class ShutdownOnCriticalIOErrorMoveNextTest method testSimplyDownAfterError.

@Test
public void testSimplyDownAfterError() throws Exception {
    deleteDirectory(new File("./target/server"));
    ActiveMQServer server = createServer("./target/server");
    try {
        server.start();
        ConnectionFactory factory = new ActiveMQConnectionFactory();
        Connection connection = factory.createConnection();
        Session session = connection.createSession();
        MessageProducer producer = session.createProducer(session.createQueue("queue"));
        try {
            for (int i = 0; i < 500; i++) {
                producer.send(session.createTextMessage("text"));
            }
        } catch (JMSException expected) {
        }
        Wait.waitFor(() -> !server.isStarted());
        Assert.assertFalse(server.isStarted());
        System.out.println("Sent messages");
    } finally {
        server.stop();
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) MessageProducer(javax.jms.MessageProducer) File(java.io.File) Session(javax.jms.Session) Test(org.junit.Test)

Example 58 with ActiveMQConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class AMQPToJMSCoreTest method testMessageDestination.

@Test
public void testMessageDestination() throws Exception {
    System.out.println("foo");
    AmqpClient client = new AmqpClient(new URI("tcp://127.0.0.1:61616"), null, null);
    AmqpConnection amqpconnection = client.connect();
    try {
        AmqpSession session = amqpconnection.createSession();
        AmqpSender sender = session.createSender(queueName);
        AmqpMessage message = new AmqpMessage();
        message.setMessageId("MessageID:" + 0);
        // message.setApplicationProperty("_AMQ_ROUTING_TYPE", (byte) 1);
        message.getWrappedMessage().setHeader(new Header());
        message.getWrappedMessage().getHeader().setDeliveryCount(new UnsignedInteger(2));
        sender.send(message);
    } finally {
        amqpconnection.close();
    }
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
    Connection connection = null;
    try {
        connection = factory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumer = session.createConsumer(ActiveMQJMSClient.createQueue(queueName));
        connection.start();
        Message message = consumer.receive(2000);
        Assert.assertNotNull(message);
        ActiveMQDestination jmsDestination = (ActiveMQDestination) message.getJMSDestination();
        Assert.assertEquals(queueName, jmsDestination.getAddress());
    } finally {
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) MessageConsumer(javax.jms.MessageConsumer) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Message(javax.jms.Message) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) Connection(javax.jms.Connection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) URI(java.net.URI) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Header(org.apache.qpid.proton.amqp.messaging.Header) UnsignedInteger(org.apache.qpid.proton.amqp.UnsignedInteger) Session(javax.jms.Session) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Test(org.junit.Test)

Example 59 with ActiveMQConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class SessionMetadataAddExceptionTest method testInvalidClientIdSetFactory.

@Test(timeout = 5000, expected = JMSException.class)
public void testInvalidClientIdSetFactory() throws Exception {
    ActiveMQConnectionFactory activeMQConnectionFactory = (ActiveMQConnectionFactory) cf;
    activeMQConnectionFactory.setClientID("invalid");
    cf.createConnection();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) Test(org.junit.Test)

Example 60 with ActiveMQConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory in project activemq-artemis by apache.

the class SessionTest method testIllegalStateException.

@Test
public void testIllegalStateException() throws Exception {
    Connection defaultConn = null;
    QueueConnection qConn = null;
    Connection connClientID = null;
    ActiveMQConnectionFactory activeMQConnectionFactory = (ActiveMQConnectionFactory) cf;
    try {
        String clientID = "somethingElse" + name.getMethodName();
        defaultConn = cf.createConnection();
        qConn = activeMQConnectionFactory.createQueueConnection();
        connClientID = cf.createConnection();
        connClientID.setClientID(clientID);
        Topic topic = createTopic("topic");
        QueueSession qSess = qConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        try {
            qSess.createDurableConsumer(topic, "mySub1");
            fail("exception expected");
        } catch (javax.jms.IllegalStateException ex) {
        // ok expected.
        }
        try {
            qSess.createDurableConsumer(topic, "mySub1", "TEST = 'test'", false);
            fail("exception expected");
        } catch (javax.jms.IllegalStateException ex) {
        // ok expected.
        }
        try {
            qSess.createSharedConsumer(topic, "mySub1");
            fail("exception expected");
        } catch (javax.jms.IllegalStateException ex) {
        // ok expected.
        }
        try {
            qSess.createSharedConsumer(topic, "mySub1", "TEST = 'test'");
            fail("exception expected");
        } catch (javax.jms.IllegalStateException ex) {
        // ok expected.
        }
        try {
            qSess.createSharedDurableConsumer(topic, "mySub1");
            fail("exception expected");
        } catch (javax.jms.IllegalStateException ex) {
        // ok expected.
        }
        try {
            qSess.createSharedDurableConsumer(topic, "mySub1", "TEST = 'test'");
            fail("exception expected");
        } catch (javax.jms.IllegalStateException ex) {
        // ok expected.
        }
        Session defaultSess = defaultConn.createSession();
        try {
            defaultSess.createDurableSubscriber(topic, "mySub1");
            fail("exception expected");
        } catch (javax.jms.IllegalStateException ex) {
        // ok expected.
        }
        try {
            defaultSess.createDurableSubscriber(topic, "mySub1", "TEST = 'test'", true);
            fail("exception expected");
        } catch (javax.jms.IllegalStateException ex) {
        // ok expected.
        }
        try {
            defaultSess.createDurableConsumer(topic, "mySub1");
            fail("exception expected");
        } catch (javax.jms.IllegalStateException ex) {
        // ok expected.
        }
        try {
            defaultSess.createDurableConsumer(topic, "mySub1", "TEST = 'test'", true);
            fail("exception expected");
        } catch (javax.jms.IllegalStateException ex) {
        // ok expected.
        }
    } finally {
        if (defaultConn != null) {
            defaultConn.close();
        }
        if (qConn != null) {
            qConn.close();
        }
        if (connClientID != null) {
            connClientID.close();
        }
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) QueueConnection(javax.jms.QueueConnection) Connection(javax.jms.Connection) QueueConnection(javax.jms.QueueConnection) Topic(javax.jms.Topic) QueueSession(javax.jms.QueueSession) Session(javax.jms.Session) QueueSession(javax.jms.QueueSession) 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