Search in sources :

Example 1 with ActiveMQTopic

use of org.apache.activemq.artemis.jms.client.ActiveMQTopic in project activemq-artemis by apache.

the class TopicDestinationsResource method createJmsTopic.

@POST
@Consumes("application/activemq.jms.topic+xml")
public Response createJmsTopic(@Context UriInfo uriInfo, Document document) {
    ActiveMQRestLogger.LOGGER.debug("Handling POST request for \"" + uriInfo.getPath() + "\"");
    try {
        TopicConfiguration topic = FileJMSConfiguration.parseTopicConfiguration(document.getDocumentElement());
        ActiveMQTopic activeMQTopic = ActiveMQDestination.createTopic(topic.getName());
        String topicName = activeMQTopic.getAddress();
        ClientSession session = manager.getSessionFactory().createSession(false, false, false);
        try {
            ClientSession.AddressQuery query = session.addressQuery(new SimpleString(topicName));
            if (!query.isExists()) {
                session.createAddress(SimpleString.toSimpleString(topicName), RoutingType.MULTICAST, true);
            } else {
                throw new WebApplicationException(Response.status(412).type("text/plain").entity("Queue already exists.").build());
            }
        } finally {
            try {
                session.close();
            } catch (Exception ignored) {
            }
        }
        URI uri = uriInfo.getRequestUriBuilder().path(topicName).build();
        return Response.created(uri).build();
    } catch (Exception e) {
        if (e instanceof WebApplicationException)
            throw (WebApplicationException) e;
        throw new WebApplicationException(e, Response.serverError().type("text/plain").entity("Failed to create queue.").build());
    }
}
Also used : ActiveMQTopic(org.apache.activemq.artemis.jms.client.ActiveMQTopic) WebApplicationException(javax.ws.rs.WebApplicationException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) TopicConfiguration(org.apache.activemq.artemis.jms.server.config.TopicConfiguration) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) URI(java.net.URI) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) WebApplicationException(javax.ws.rs.WebApplicationException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 2 with ActiveMQTopic

use of org.apache.activemq.artemis.jms.client.ActiveMQTopic in project activemq-artemis by apache.

the class JMSServerManagerImpl method internalCreateTopic.

private synchronized boolean internalCreateTopic(final String address, final String topicName, final boolean autoCreated) throws Exception {
    if (topics.get(address) != null) {
        return false;
    } else {
        // Create the JMS topic with topicName as the logical name of the topic *and* address as its address
        ActiveMQTopic activeMQTopic = ActiveMQDestination.createTopic(address, topicName);
        server.addOrUpdateAddressInfo(new AddressInfo(SimpleString.toSimpleString(activeMQTopic.getAddress()), RoutingType.MULTICAST));
        topics.put(address, activeMQTopic);
        this.recoverregistryBindings(topicName, PersistedType.Topic);
        return true;
    }
}
Also used : ActiveMQTopic(org.apache.activemq.artemis.jms.client.ActiveMQTopic) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo)

Example 3 with ActiveMQTopic

use of org.apache.activemq.artemis.jms.client.ActiveMQTopic in project activemq-artemis by apache.

the class JMSServerManagerImpl method addTopicToBindingRegistry.

@Override
public boolean addTopicToBindingRegistry(final String topicName, final String registryBinding) throws Exception {
    checkInitialised();
    checkBindings(registryBinding);
    ActiveMQTopic destination = topics.get(topicName);
    if (destination == null) {
        throw new IllegalArgumentException("Topic does not exist");
    }
    if (destination.getTopicName() == null) {
        throw new IllegalArgumentException(topicName + " is not a topic");
    }
    boolean added = bindToBindings(registryBinding, destination);
    if (added) {
        addToBindings(topicBindings, topicName, registryBinding);
        storage.addBindings(PersistedType.Topic, topicName, registryBinding);
    }
    return added;
}
Also used : ActiveMQTopic(org.apache.activemq.artemis.jms.client.ActiveMQTopic)

Example 4 with ActiveMQTopic

use of org.apache.activemq.artemis.jms.client.ActiveMQTopic in project activemq-artemis by apache.

the class TopicCleanupTest method testWildcardSubscriber.

@Test
public void testWildcardSubscriber() throws Exception {
    ActiveMQTopic topic = (ActiveMQTopic) createTopic("topic.A");
    Connection conn = cf.createConnection();
    conn.start();
    try {
        Session consumerStarSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumerStar = consumerStarSession.createConsumer(ActiveMQJMSClient.createTopic("topic.*"));
        Session consumerASession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer consumerA = consumerASession.createConsumer(topic);
        Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer producerA = producerSession.createProducer(topic);
        TextMessage msg1 = producerSession.createTextMessage("text");
        producerA.send(msg1);
        consumerStar.close();
        consumerA.close();
        producerA.send(msg1);
        conn.close();
        boolean foundStrayRoutingBinding = false;
        Bindings bindings = server.getPostOffice().getBindingsForAddress(new SimpleString(topic.getAddress()));
        Map<SimpleString, List<Binding>> routingNames = ((BindingsImpl) bindings).getRoutingNameBindingMap();
        for (SimpleString key : routingNames.keySet()) {
            if (!key.toString().equals(topic.getAddress())) {
                foundStrayRoutingBinding = true;
                assertEquals(0, ((LocalQueueBinding) routingNames.get(key).get(0)).getQueue().getMessageCount());
            }
        }
        assertFalse(foundStrayRoutingBinding);
    } finally {
        jmsServer.stop();
        jmsServer.start();
        try {
            conn.close();
        } catch (Throwable igonred) {
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ActiveMQTopic(org.apache.activemq.artemis.jms.client.ActiveMQTopic) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) BindingsImpl(org.apache.activemq.artemis.core.postoffice.impl.BindingsImpl) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) List(java.util.List) MessageProducer(javax.jms.MessageProducer) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 5 with ActiveMQTopic

use of org.apache.activemq.artemis.jms.client.ActiveMQTopic in project pentaho-kettle by pentaho.

the class ActiveMQProvider method getDestination.

@Override
public Destination getDestination(JmsDelegate delegate) {
    checkNotNull(delegate.destinationName, getString(PKG, "JmsWebsphereMQ.DestinationNameRequired"));
    String destName = delegate.destinationName;
    return isQueue(delegate) ? new ActiveMQQueue(destName) : new ActiveMQTopic(destName);
}
Also used : ActiveMQTopic(org.apache.activemq.artemis.jms.client.ActiveMQTopic) ActiveMQQueue(org.apache.activemq.artemis.jms.client.ActiveMQQueue) BaseMessages.getString(org.pentaho.di.i18n.BaseMessages.getString)

Aggregations

ActiveMQTopic (org.apache.activemq.artemis.jms.client.ActiveMQTopic)8 Test (org.junit.Test)3 Reference (javax.naming.Reference)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ActiveMQQueue (org.apache.activemq.artemis.jms.client.ActiveMQQueue)2 BaseMessages.getString (org.pentaho.di.i18n.BaseMessages.getString)2 URI (java.net.URI)1 List (java.util.List)1 Properties (java.util.Properties)1 Connection (javax.jms.Connection)1 MessageConsumer (javax.jms.MessageConsumer)1 MessageProducer (javax.jms.MessageProducer)1 Session (javax.jms.Session)1 TextMessage (javax.jms.TextMessage)1 Referenceable (javax.naming.Referenceable)1 ObjectFactory (javax.naming.spi.ObjectFactory)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1