Search in sources :

Example 6 with PushRegistration

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

use of org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration 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)

Aggregations

PushRegistration (org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration)7 XmlLink (org.apache.activemq.artemis.rest.queue.push.xml.XmlLink)4 Link (org.jboss.resteasy.spi.Link)4 ClientRequest (org.jboss.resteasy.client.ClientRequest)3 Test (org.junit.Test)3 ClientResponse (org.jboss.resteasy.client.ClientResponse)2 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 JAXBContext (javax.xml.bind.JAXBContext)1 QueueDeployment (org.apache.activemq.artemis.rest.queue.QueueDeployment)1 ActiveMQPushStrategy (org.apache.activemq.artemis.rest.queue.push.ActiveMQPushStrategy)1 PushConsumerResource (org.apache.activemq.artemis.rest.queue.push.PushConsumerResource)1