Search in sources :

Example 6 with XmlLink

use of org.apache.activemq.artemis.rest.queue.push.xml.XmlLink in project activemq-artemis by apache.

the class PersistentPushQueueConsumerTest method testBridge.

@Test
public void testBridge() throws Exception {
    try {
        startup();
        String testName = "testBridge";
        deployBridgeQueues(testName);
        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);
        request = new ClientRequest(generateURL("/queues/" + testName + "forwardQueue"));
        response = request.head();
        response.releaseConnection();
        Assert.assertEquals(200, response.getStatus());
        Link consumers = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
        System.out.println("pull: " + consumers);
        response = Util.setAutoAck(consumers, true);
        Link consumeNext = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
        System.out.println("poller: " + consumeNext);
        PushRegistration reg = new PushRegistration();
        reg.setDurable(true);
        reg.setDisableOnFailure(true);
        XmlLink target = new XmlLink();
        target.setHref(generateURL("/queues/" + testName + "forwardQueue"));
        target.setRelationship("destination");
        reg.setTarget(target);
        response = pushSubscriptions.request().body("application/xml", reg).post();
        response.releaseConnection();
        Assert.assertEquals(201, response.getStatus());
        shutdown();
        startup();
        deployBridgeQueues(testName);
        ClientResponse<?> res = sender.request().body("text/plain", Integer.toString(1)).post();
        res.releaseConnection();
        Assert.assertEquals(201, res.getStatus());
        res = consumeNext.request().header("Accept-Wait", "2").post(String.class);
        Assert.assertEquals(200, res.getStatus());
        Assert.assertEquals("1", res.getEntity(String.class));
        res.releaseConnection();
        Link session = MessageTestBase.getLinkByTitle(manager.getQueueManager().getLinkStrategy(), res, "consumer");
        res = session.request().delete();
        res.releaseConnection();
        Assert.assertEquals(204, res.getStatus());
        manager.getQueueManager().getPushStore().removeAll();
    } finally {
        shutdown();
    }
}
Also used : 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 7 with XmlLink

use of org.apache.activemq.artemis.rest.queue.push.xml.XmlLink in project activemq-artemis by apache.

the class SelectorTest method testPush.

@Test
public void testPush() throws Exception {
    server.getJaxrsServer().getDeployment().getRegistry().addPerRequestResource(PushReceiver.class);
    ClientRequest request = new ClientRequest(generateURL("/topics/" + topicName));
    ClientResponse<?> response = request.head();
    response.releaseConnection();
    Assert.assertEquals(200, response.getStatus());
    Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "push-subscriptions");
    System.out.println("push: " + consumers);
    PushTopicRegistration oneReg = new PushTopicRegistration();
    oneReg.setDurable(false);
    XmlLink target = new XmlLink();
    target.setMethod("post");
    target.setHref(generateURL("/push/one"));
    target.setType("application/xml");
    oneReg.setTarget(target);
    oneReg.setSelector("MyTag = '1'");
    response = consumers.request().body("application/xml", oneReg).post();
    response.releaseConnection();
    Link oneSubscription = response.getLocationLink();
    PushTopicRegistration twoReg = new PushTopicRegistration();
    twoReg.setDurable(false);
    target = new XmlLink();
    target.setMethod("post");
    target.setHref(generateURL("/push/two"));
    target.setType("application/xml");
    twoReg.setTarget(target);
    twoReg.setSelector("MyTag = '2'");
    response = consumers.request().body("application/xml", twoReg).post();
    response.releaseConnection();
    Link twoSubscription = response.getLocationLink();
    Order order = new Order();
    order.setName("1");
    order.setAmount("$5.00");
    publish(prefixedTopicName, order, null, "1");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.oneOrder);
    order.setName("2");
    publish(prefixedTopicName, order, null, "2");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.twoOrder);
    order.setName("3");
    publish(prefixedTopicName, order, null, "2");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.twoOrder);
    order.setName("4");
    publish(prefixedTopicName, order, null, "1");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.oneOrder);
    order.setName("5");
    publish(prefixedTopicName, order, null, "1");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.oneOrder);
    order.setName("6");
    publish(prefixedTopicName, order, null, "1");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.oneOrder);
    response = oneSubscription.request().delete();
    response.releaseConnection();
    response = twoSubscription.request().delete();
    response.releaseConnection();
}
Also used : PushTopicRegistration(org.apache.activemq.artemis.rest.topic.PushTopicRegistration) 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 8 with XmlLink

use of org.apache.activemq.artemis.rest.queue.push.xml.XmlLink in project activemq-artemis by apache.

the class PushReg method main.

public static void main(String[] args) throws Exception {
    // get the push consumers factory resource
    ClientRequest request = new ClientRequest("http://localhost:8080/queues/orders");
    ClientResponse res = request.head();
    Link pushConsumers = res.getHeaderAsLink("msg-push-consumers");
    // next create the XML document that represents the registration
    // Really, just create a link with the shipping URL and the type you want posted
    PushRegistration reg = new PushRegistration();
    XmlLink target = new XmlLink();
    target.setHref("http://localhost:8080/queues/shipping");
    target.setType("application/xml");
    target.setRelationship("destination");
    reg.setTarget(target);
    res = pushConsumers.request().body("application/xml", reg).post();
    System.out.println("Create push registration.  Resource URL: " + res.getLocationLink().getHref());
}
Also used : ClientResponse(org.jboss.resteasy.client.ClientResponse) 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) Link(org.jboss.resteasy.spi.Link) XmlLink(org.apache.activemq.artemis.rest.queue.push.xml.XmlLink)

Example 9 with XmlLink

use of org.apache.activemq.artemis.rest.queue.push.xml.XmlLink 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 10 with XmlLink

use of org.apache.activemq.artemis.rest.queue.push.xml.XmlLink in project activemq-artemis by apache.

the class PersistentPushTopicConsumerTest method testFailure.

@Test
public void testFailure() throws Exception {
    try {
        String testName = "testFailure";
        startup();
        deployTopic(testName);
        ClientRequest request = new ClientRequest(generateURL("/topics/" + 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-subscriptions");
        System.out.println("push subscriptions: " + pushSubscriptions);
        PushTopicRegistration reg = new PushTopicRegistration();
        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();
        PushTopicRegistration reg2 = response.getEntity(PushTopicRegistration.class);
        response.releaseConnection();
        Assert.assertEquals(reg.isDurable(), reg2.isDurable());
        Assert.assertEquals(reg.getTarget().getHref(), reg2.getTarget().getHref());
        Assert.assertFalse(reg2.isEnabled());
        response.releaseConnection();
        String destination = reg2.getDestination();
        ClientSession session = manager.getQueueManager().getSessionFactory().createSession(false, false, false);
        ClientSession.QueueQuery query = session.queueQuery(new SimpleString(destination));
        Assert.assertFalse(query.isExists());
        manager.getQueueManager().getPushStore().removeAll();
    } finally {
        shutdown();
    }
}
Also used : PushTopicRegistration(org.apache.activemq.artemis.rest.topic.PushTopicRegistration) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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)

Aggregations

XmlLink (org.apache.activemq.artemis.rest.queue.push.xml.XmlLink)12 Link (org.jboss.resteasy.spi.Link)12 ClientRequest (org.jboss.resteasy.client.ClientRequest)11 Test (org.junit.Test)10 PushTopicRegistration (org.apache.activemq.artemis.rest.topic.PushTopicRegistration)8 TopicDeployment (org.apache.activemq.artemis.rest.topic.TopicDeployment)5 QueueDeployment (org.apache.activemq.artemis.rest.queue.QueueDeployment)4 PushRegistration (org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ActiveMQPushStrategy (org.apache.activemq.artemis.rest.queue.push.ActiveMQPushStrategy)2 ClientResponse (org.jboss.resteasy.client.ClientResponse)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1