Search in sources :

Example 11 with QueueDeployment

use of org.apache.activemq.artemis.rest.queue.QueueDeployment in project activemq-artemis by apache.

the class ClientAckQueueTest method testReconnectX2.

@Test
public void testReconnectX2() throws Exception {
    String testName = "testReconnectX2";
    QueueDeployment queueDeployment = new QueueDeployment(testName, true);
    manager.getQueueManager().deploy(queueDeployment);
    manager.getQueueManager().setLinkStrategy(new LinkHeaderLinkStrategy());
    testReconnect(testName);
    manager.getQueueManager().setLinkStrategy(new CustomHeaderLinkStrategy());
    testReconnect(testName);
}
Also used : CustomHeaderLinkStrategy(org.apache.activemq.artemis.rest.util.CustomHeaderLinkStrategy) QueueDeployment(org.apache.activemq.artemis.rest.queue.QueueDeployment) LinkHeaderLinkStrategy(org.apache.activemq.artemis.rest.util.LinkHeaderLinkStrategy) Test(org.junit.Test)

Example 12 with QueueDeployment

use of org.apache.activemq.artemis.rest.queue.QueueDeployment in project activemq-artemis by apache.

the class JMSTest method testJmsConsumer.

@Test
public void testJmsConsumer() throws Exception {
    String queueName = "testQueue2";
    String prefixedQueueName = ActiveMQDestination.createQueueAddressFromName(queueName).toString();
    System.out.println("Queue name: " + prefixedQueueName);
    QueueDeployment deployment = new QueueDeployment();
    deployment.setDuplicatesAllowed(true);
    deployment.setDurableSend(false);
    deployment.setName(queueName);
    manager.getQueueManager().deploy(deployment);
    Connection conn = connectionFactory.createConnection();
    try {
        Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination destination = createDestination(prefixedQueueName);
        MessageConsumer consumer = session.createConsumer(destination);
        consumer.setMessageListener(new Listener());
        conn.start();
        ClientRequest request = new ClientRequest(generateURL(Util.getUrlPath(queueName)));
        ClientResponse<?> response = request.head();
        response.releaseConnection();
        Assert.assertEquals(200, response.getStatus());
        Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
        System.out.println("create: " + sender);
        Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
        System.out.println("consume-next: " + consumeNext);
        // test that Accept header is used to set content-type
        {
            Order order = new Order();
            order.setName("1");
            order.setAmount("$5.00");
            response = sender.request().body("application/xml", order).post();
            response.releaseConnection();
            Assert.assertEquals(201, response.getStatus());
            Listener.latch.await(1, TimeUnit.SECONDS);
            Assert.assertNotNull(Listener.order);
            Assert.assertEquals(order, Listener.order);
            Assert.assertNotNull(Listener.messageID);
        }
    } finally {
        conn.close();
    }
}
Also used : ActiveMQDestination(org.apache.activemq.artemis.jms.client.ActiveMQDestination) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) MessageListener(javax.jms.MessageListener) QueueDeployment(org.apache.activemq.artemis.rest.queue.QueueDeployment) Connection(javax.jms.Connection) ClientRequest(org.jboss.resteasy.client.ClientRequest) Link(org.jboss.resteasy.spi.Link) Session(javax.jms.Session) Test(org.junit.Test)

Example 13 with QueueDeployment

use of org.apache.activemq.artemis.rest.queue.QueueDeployment in project activemq-artemis by apache.

the class PersistentPushQueueConsumerTest method testFailure.

@Test
public void testFailure() throws Exception {
    try {
        startup();
        String testName = "testFailure";
        QueueDeployment deployment = new QueueDeployment();
        deployment.setDuplicatesAllowed(true);
        deployment.setDurableSend(false);
        deployment.setName(testName);
        manager.getQueueManager().deploy(deployment);
        ClientRequest request = new ClientRequest(generateURL("/queues/" + testName));
        ClientResponse<?> response = request.head();
        response.releaseConnection();
        Assert.assertEquals(200, response.getStatus());
        Link sender = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
        System.out.println("create: " + sender);
        Link pushSubscriptions = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "push-consumers");
        System.out.println("push subscriptions: " + pushSubscriptions);
        PushRegistration reg = new PushRegistration();
        reg.setDurable(true);
        XmlLink target = new XmlLink();
        target.setHref("http://localhost:3333/error");
        target.setRelationship("uri");
        reg.setTarget(target);
        reg.setDisableOnFailure(true);
        reg.setMaxRetries(3);
        reg.setRetryWaitMillis(10);
        response = pushSubscriptions.request().body("application/xml", reg).post();
        Assert.assertEquals(201, response.getStatus());
        Link pushSubscription = response.getLocationLink();
        response.releaseConnection();
        ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
        res.releaseConnection();
        Assert.assertEquals(201, res.getStatus());
        Thread.sleep(5000);
        response = pushSubscription.request().get();
        PushRegistration reg2 = response.getEntity(PushRegistration.class);
        Assert.assertEquals(reg.isDurable(), reg2.isDurable());
        Assert.assertEquals(reg.getTarget().getHref(), reg2.getTarget().getHref());
        // make sure the failure disables the PushRegistration
        Assert.assertFalse(reg2.isEnabled());
        response.releaseConnection();
        manager.getQueueManager().getPushStore().removeAll();
    } finally {
        shutdown();
    }
}
Also used : QueueDeployment(org.apache.activemq.artemis.rest.queue.QueueDeployment) PushRegistration(org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration) XmlLink(org.apache.activemq.artemis.rest.queue.push.xml.XmlLink) ClientRequest(org.jboss.resteasy.client.ClientRequest) XmlLink(org.apache.activemq.artemis.rest.queue.push.xml.XmlLink) Link(org.jboss.resteasy.spi.Link) Test(org.junit.Test)

Example 14 with QueueDeployment

use of org.apache.activemq.artemis.rest.queue.QueueDeployment in project activemq-artemis by apache.

the class PersistentPushQueueConsumerTest method deployBridgeQueues.

private void deployBridgeQueues(String testName) throws Exception {
    QueueDeployment deployment = new QueueDeployment();
    deployment.setDuplicatesAllowed(true);
    deployment.setDurableSend(false);
    deployment.setName(testName);
    manager.getQueueManager().deploy(deployment);
    QueueDeployment deployment2 = new QueueDeployment();
    deployment2.setDuplicatesAllowed(true);
    deployment2.setDurableSend(false);
    deployment2.setName(testName + "forwardQueue");
    manager.getQueueManager().deploy(deployment2);
}
Also used : QueueDeployment(org.apache.activemq.artemis.rest.queue.QueueDeployment)

Example 15 with QueueDeployment

use of org.apache.activemq.artemis.rest.queue.QueueDeployment in project activemq-artemis by apache.

the class DupQueueTest method testDup.

@Test
public void testDup() throws Exception {
    String testName = "testDup";
    QueueDeployment deployment = new QueueDeployment();
    deployment.setDuplicatesAllowed(false);
    deployment.setDurableSend(false);
    deployment.setName(testName);
    manager.getQueueManager().deploy(deployment);
    ClientRequest request = new ClientRequest(generateURL("/queues/" + testName));
    ClientResponse<?> response = request.head();
    Assert.assertEquals(200, response.getStatus());
    Link sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create");
    System.out.println("create: " + sender);
    Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
    System.out.println("pull: " + consumers);
    response = Util.setAutoAck(consumers, true);
    Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
    System.out.println("poller: " + consumeNext);
    ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
    Assert.assertEquals(307, res.getStatus());
    sender = res.getLocationLink();
    res.releaseConnection();
    System.out.println("create-next: " + sender);
    Assert.assertNotNull(sender);
    res = sender.request().body("text/plain", Integer.toString(1)).post();
    res.releaseConnection();
    Assert.assertEquals(201, res.getStatus());
    res = sender.request().body("text/plain", Integer.toString(1)).post();
    res.releaseConnection();
    Assert.assertEquals(201, res.getStatus());
    sender = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "create-next");
    res = sender.request().body("text/plain", Integer.toString(2)).post();
    res.releaseConnection();
    Assert.assertEquals(201, res.getStatus());
    res = consumeNext.request().post(String.class);
    Assert.assertEquals(200, res.getStatus());
    Assert.assertEquals("1", res.getEntity(String.class));
    res.releaseConnection();
    Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
    System.out.println("session: " + session);
    consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
    System.out.println("consumeNext: " + consumeNext);
    res = consumeNext.request().header(Constants.WAIT_HEADER, "10").post(String.class);
    Assert.assertEquals(200, res.getStatus());
    Assert.assertEquals("2", res.getEntity(String.class));
    res.releaseConnection();
    session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
    System.out.println("session: " + session);
    consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consume-next");
    System.out.println("consumeNext: " + consumeNext);
    res = consumeNext.request().post(String.class);
    res.releaseConnection();
    Assert.assertEquals(503, res.getStatus());
    res = session.request().delete();
    res.releaseConnection();
    Assert.assertEquals(204, res.getStatus());
}
Also used : QueueDeployment(org.apache.activemq.artemis.rest.queue.QueueDeployment) ClientRequest(org.jboss.resteasy.client.ClientRequest) Link(org.jboss.resteasy.spi.Link) Test(org.junit.Test)

Aggregations

QueueDeployment (org.apache.activemq.artemis.rest.queue.QueueDeployment)21 Test (org.junit.Test)15 ClientRequest (org.jboss.resteasy.client.ClientRequest)11 Link (org.jboss.resteasy.spi.Link)11 XmlLink (org.apache.activemq.artemis.rest.queue.push.xml.XmlLink)4 TopicDeployment (org.apache.activemq.artemis.rest.topic.TopicDeployment)4 CustomHeaderLinkStrategy (org.apache.activemq.artemis.rest.util.CustomHeaderLinkStrategy)4 LinkHeaderLinkStrategy (org.apache.activemq.artemis.rest.util.LinkHeaderLinkStrategy)4 BeforeClass (org.junit.BeforeClass)4 PushTopicRegistration (org.apache.activemq.artemis.rest.topic.PushTopicRegistration)3 Connection (javax.jms.Connection)1 Destination (javax.jms.Destination)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageListener (javax.jms.MessageListener)1 Session (javax.jms.Session)1 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ActiveMQDestination (org.apache.activemq.artemis.jms.client.ActiveMQDestination)1 ActiveMQPushStrategy (org.apache.activemq.artemis.rest.queue.push.ActiveMQPushStrategy)1 PushRegistration (org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration)1 ClientResponse (org.jboss.resteasy.client.ClientResponse)1