Search in sources :

Example 6 with PushTopicRegistration

use of org.apache.activemq.artemis.rest.topic.PushTopicRegistration 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)

Example 7 with PushTopicRegistration

use of org.apache.activemq.artemis.rest.topic.PushTopicRegistration in project activemq-artemis by apache.

the class PushTopicConsumerTest method testBridge.

@Test
public void testBridge() throws Exception {
    TopicDeployment deployment = new TopicDeployment();
    deployment.setDuplicatesAllowed(true);
    deployment.setDurableSend(false);
    deployment.setName("testBridge");
    manager.getTopicManager().deploy(deployment);
    QueueDeployment deployment2 = new QueueDeployment();
    deployment2.setDuplicatesAllowed(true);
    deployment2.setDurableSend(false);
    deployment2.setName("testBridgeForwardQueue");
    manager.getQueueManager().deploy(deployment2);
    ClientRequest request = new ClientRequest(generateURL("/topics/testBridge"));
    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 pushSubscriptions = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "push-subscriptions");
    System.out.println("push subscriptions: " + pushSubscriptions);
    request = new ClientRequest(generateURL("/queues/testBridgeForwardQueue"));
    response = request.head();
    response.releaseConnection();
    Assert.assertEquals(200, response.getStatus());
    Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
    response = Util.setAutoAck(consumers, true);
    Link consumeNext = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consume-next");
    PushTopicRegistration reg = new PushTopicRegistration();
    reg.setDurable(false);
    XmlLink target = new XmlLink();
    target.setHref(generateURL("/queues/testBridgeForwardQueue"));
    target.setRelationship("destination");
    reg.setTarget(target);
    response = pushSubscriptions.request().body("application/xml", reg).post();
    response.releaseConnection();
    Assert.assertEquals(201, response.getStatus());
    Link pushSubscription = response.getLocationLink();
    response = sender.request().body("text/plain", Integer.toString(1)).post();
    response.releaseConnection();
    Assert.assertEquals(201, response.getStatus());
    response = consumeNext.request().header("Accept-Wait", "1").post(String.class);
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("1", response.getEntity(String.class));
    response.releaseConnection();
    Link session = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "consumer");
    response = session.request().delete();
    response.releaseConnection();
    Assert.assertEquals(204, response.getStatus());
    response = pushSubscription.request().delete();
    response.releaseConnection();
    Assert.assertEquals(204, response.getStatus());
}
Also used : PushTopicRegistration(org.apache.activemq.artemis.rest.topic.PushTopicRegistration) TopicDeployment(org.apache.activemq.artemis.rest.topic.TopicDeployment) QueueDeployment(org.apache.activemq.artemis.rest.queue.QueueDeployment) 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 PushTopicRegistration

use of org.apache.activemq.artemis.rest.topic.PushTopicRegistration in project activemq-artemis by apache.

the class PushTopicConsumerTest method testUri.

@Test
public void testUri() throws Exception {
    TopicDeployment deployment = new TopicDeployment();
    deployment.setDuplicatesAllowed(true);
    deployment.setDurableSend(false);
    deployment.setName("testUri");
    manager.getTopicManager().deploy(deployment);
    ClientRequest request = new ClientRequest(generateURL("/topics/testUri"));
    server.getJaxrsServer().getDeployment().getRegistry().addPerRequestResource(MyResource.class);
    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 pushSubscriptions = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "push-subscriptions");
    System.out.println("push subscriptions: " + pushSubscriptions);
    PushTopicRegistration reg = new PushTopicRegistration();
    reg.setDurable(false);
    XmlLink target = new XmlLink();
    target.setMethod("put");
    target.setHref(generateURL("/my"));
    reg.setTarget(target);
    response = pushSubscriptions.request().body("application/xml", reg).post();
    Assert.assertEquals(201, response.getStatus());
    Link pushSubscription = response.getLocationLink();
    response.releaseConnection();
    response = sender.request().body("text/plain", Integer.toString(1)).post();
    response.releaseConnection();
    Assert.assertEquals(201, response.getStatus());
    Thread.sleep(100);
    Assert.assertEquals("1", MyResource.gotit);
    response = pushSubscription.request().delete();
    response.releaseConnection();
    Assert.assertEquals(204, response.getStatus());
}
Also used : PushTopicRegistration(org.apache.activemq.artemis.rest.topic.PushTopicRegistration) TopicDeployment(org.apache.activemq.artemis.rest.topic.TopicDeployment) 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)8 PushTopicRegistration (org.apache.activemq.artemis.rest.topic.PushTopicRegistration)8 ClientRequest (org.jboss.resteasy.client.ClientRequest)8 Link (org.jboss.resteasy.spi.Link)8 Test (org.junit.Test)8 TopicDeployment (org.apache.activemq.artemis.rest.topic.TopicDeployment)5 QueueDeployment (org.apache.activemq.artemis.rest.queue.QueueDeployment)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)1 ActiveMQPushStrategy (org.apache.activemq.artemis.rest.queue.push.ActiveMQPushStrategy)1