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());
}
}
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;
}
}
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;
}
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) {
}
}
}
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);
}
Aggregations