org.apache.activemq.artemis.rest.topic.PushTopicRegistration

Here are the examples of the java api class org.apache.activemq.artemis.rest.topic.PushTopicRegistration taken from open source projects.

1. SelectorTest#testPush()

Project: activemq-artemis
Source File: SelectorTest.java
View license
@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(topicName, order, null, "1");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.oneOrder);
    order.setName("2");
    publish(topicName, order, null, "2");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.twoOrder);
    order.setName("3");
    publish(topicName, order, null, "2");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.twoOrder);
    order.setName("4");
    publish(topicName, order, null, "1");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.oneOrder);
    order.setName("5");
    publish(topicName, order, null, "1");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.oneOrder);
    order.setName("6");
    publish(topicName, order, null, "1");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.oneOrder);
    response = oneSubscription.request().delete();
    response.releaseConnection();
    response = twoSubscription.request().delete();
    response.releaseConnection();
}

2. PushTopicConsumerTest#testUriWithMultipleSessions()

View license
@Test
public void testUriWithMultipleSessions() throws Exception {
    final int CONCURRENT = 10;
    TopicDeployment deployment = new TopicDeployment();
    deployment.setDuplicatesAllowed(true);
    deployment.setDurableSend(false);
    deployment.setName("testUriWithMultipleSessions");
    manager.getTopicManager().deploy(deployment);
    ClientRequest request = new ClientRequest(generateURL("/topics/testUriWithMultipleSessions"));
    server.getJaxrsServer().getDeployment().getRegistry().addPerRequestResource(MyConcurrentResource.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("/myConcurrent"));
    reg.setTarget(target);
    reg.setSessionCount(CONCURRENT);
    response = pushSubscriptions.request().body("application/xml", reg).post();
    Assert.assertEquals(201, response.getStatus());
    Link pushSubscription = response.getLocationLink();
    response.releaseConnection();
    for (int i = 0; i < CONCURRENT; i++) {
        response = sender.request().body("text/plain", Integer.toString(1)).post();
        response.releaseConnection();
        Assert.assertEquals(201, response.getStatus());
    }
    // wait until all the invocations have completed
    while (MyConcurrentResource.concurrentInvocations.get() > 0) {
        Thread.sleep(100);
    }
    Assert.assertEquals(CONCURRENT, MyConcurrentResource.maxConcurrentInvocations.get());
    response = pushSubscription.request().delete();
    response.releaseConnection();
    Assert.assertEquals(204, response.getStatus());
}

3. PushTopicConsumerTest#testBridge()

View license
@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());
}

4. PushTopicConsumerTest#testClass()

View license
@Test
public void testClass() throws Exception {
    TopicDeployment deployment = new TopicDeployment();
    deployment.setDuplicatesAllowed(true);
    deployment.setDurableSend(false);
    deployment.setName("testClass");
    manager.getTopicManager().deploy(deployment);
    QueueDeployment deployment2 = new QueueDeployment();
    deployment2.setDuplicatesAllowed(true);
    deployment2.setDurableSend(false);
    deployment2.setName("testClassForwardQueue");
    manager.getQueueManager().deploy(deployment2);
    ClientRequest request = new ClientRequest(generateURL("/topics/testClass"));
    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/testClassForwardQueue"));
    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/testClassForwardQueue"));
    target.setClassName(ActiveMQPushStrategy.class.getName());
    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());
    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());
}

5. PushTopicConsumerTest#testTemplate()

View license
@Test
public void testTemplate() throws Exception {
    TopicDeployment deployment = new TopicDeployment();
    deployment.setDuplicatesAllowed(true);
    deployment.setDurableSend(false);
    deployment.setName("testTemplate");
    manager.getTopicManager().deploy(deployment);
    QueueDeployment deployment2 = new QueueDeployment();
    deployment2.setDuplicatesAllowed(true);
    deployment2.setDurableSend(false);
    deployment2.setName("testTemplateForwardQueue");
    manager.getQueueManager().deploy(deployment2);
    ClientRequest request = new ClientRequest(generateURL("/topics/testTemplate"));
    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/testTemplateForwardQueue"));
    response = request.head();
    response.releaseConnection();
    Assert.assertEquals(200, response.getStatus());
    Link consumers = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "pull-consumers");
    Link createWithId = getLinkByTitle(manager.getQueueManager().getLinkStrategy(), response, "create-with-id");
    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.setRelationship("template");
    target.setHref(createWithId.getHref());
    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());
    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());
}

6. PushTopicConsumerTest#testUri()

View license
@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());
}