Search in sources :

Example 1 with PushRegistration

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

the class PushQueueConsumerTest method createPushRegistration.

private Link createPushRegistration(String queueToPushTo, Link pushSubscriptions, PushRegistrationType pushRegistrationType, int sessionCount) throws Exception {
    PushRegistration reg = new PushRegistration();
    reg.setDurable(false);
    XmlLink target = new XmlLink();
    if (pushRegistrationType == PushRegistrationType.CLASS) {
        target.setHref(generateURL(Util.getUrlPath(queueToPushTo)));
        target.setClassName(ActiveMQPushStrategy.class.getName());
    } else if (pushRegistrationType == PushRegistrationType.BRIDGE) {
        target.setHref(generateURL(Util.getUrlPath(queueToPushTo)));
        target.setRelationship("destination");
    } else if (pushRegistrationType == PushRegistrationType.TEMPLATE) {
        target.setHref(queueToPushTo);
        target.setRelationship("template");
    } else if (pushRegistrationType == PushRegistrationType.URI) {
        target.setMethod("put");
        target.setHref(queueToPushTo);
    }
    reg.setTarget(target);
    reg.setSessionCount(sessionCount);
    ClientResponse pushRegistrationResponse = pushSubscriptions.request().body("application/xml", reg).post();
    pushRegistrationResponse.releaseConnection();
    Assert.assertEquals(201, pushRegistrationResponse.getStatus());
    Link pushSubscription = pushRegistrationResponse.getLocationLink();
    return pushSubscription;
}
Also used : ActiveMQPushStrategy(org.apache.activemq.artemis.rest.queue.push.ActiveMQPushStrategy) 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) XmlLink(org.apache.activemq.artemis.rest.queue.push.xml.XmlLink) Link(org.jboss.resteasy.spi.Link)

Example 2 with PushRegistration

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

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

the class XmlTest method testPush.

@Test
public void testPush() throws Exception {
    String xml = "<push-registration id=\"111\">\n" + "   <destination>bar</destination>\n" + "   <durable>true</durable>\n" + "   <session-count>10</session-count>\n" + "   <link rel=\"template\" href=\"http://somewhere.com/resources/{id}/messages\" method=\"PUT\"/>\n" + "   <authentication>\n" + "      <basic-auth><username>guest</username><password>geheim</password></basic-auth>" + "   </authentication>\n" + "   <header name=\"foo\">bar</header>" + "</push-registration>";
    JAXBContext ctx = JAXBContext.newInstance(PushRegistration.class);
    PushRegistration reg = (PushRegistration) ctx.createUnmarshaller().unmarshal(new StringReader(xml));
    System.out.println(reg);
}
Also used : StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) PushRegistration(org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration) Test(org.junit.Test)

Example 4 with PushRegistration

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

the class QueueDestinationsResource method createQueueResource.

public QueueResource createQueueResource(String queueName, boolean defaultDurable, int timeoutSeconds, boolean duplicates) throws Exception {
    QueueResource queueResource = new QueueResource();
    queueResource.setQueueDestinationsResource(this);
    queueResource.setDestination(queueName);
    queueResource.setServiceManager(manager);
    ConsumersResource consumers = new ConsumersResource();
    consumers.setConsumerTimeoutSeconds(timeoutSeconds);
    consumers.setDestination(queueName);
    consumers.setSessionFactory(manager.getConsumerSessionFactory());
    consumers.setServiceManager(manager);
    queueResource.setConsumers(consumers);
    PushConsumerResource push = new PushConsumerResource();
    push.setDestination(queueName);
    push.setSessionFactory(manager.getConsumerSessionFactory());
    push.setJmsOptions(manager.getJmsOptions());
    queueResource.setPushConsumers(push);
    PostMessage sender = null;
    if (duplicates) {
        sender = new PostMessageDupsOk();
    } else {
        sender = new PostMessageNoDups();
    }
    sender.setServiceManager(manager);
    sender.setDefaultDurable(defaultDurable);
    sender.setDestination(queueName);
    sender.setSessionFactory(manager.getSessionFactory());
    sender.setPoolSize(manager.getProducerPoolSize());
    sender.setProducerTimeToLive(manager.getProducerTimeToLive());
    sender.init();
    queueResource.setSender(sender);
    if (manager.getPushStore() != null) {
        push.setPushStore(manager.getPushStore());
        List<PushRegistration> regs = manager.getPushStore().getByDestination(queueName);
        for (PushRegistration reg : regs) {
            push.addRegistration(reg);
        }
    }
    queueResource.start();
    getQueues().put(queueName, queueResource);
    return queueResource;
}
Also used : PushConsumerResource(org.apache.activemq.artemis.rest.queue.push.PushConsumerResource) PushRegistration(org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration)

Example 5 with PushRegistration

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

the class FilePushStore method removeAll.

@Override
public synchronized void removeAll() throws Exception {
    ArrayList<PushRegistration> copy = new ArrayList<>(map.values());
    for (PushRegistration reg : copy) remove(reg);
    this.dir.delete();
}
Also used : ArrayList(java.util.ArrayList) PushRegistration(org.apache.activemq.artemis.rest.queue.push.xml.PushRegistration)

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