use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.
the class EmbeddedJMSResource method getDestinationQueue.
/**
* Get the Queue corresponding to a JMS Destination.
* <p>
* The full name of the JMS destination including the prefix should be provided - i.e. queue://myQueue
* or topic://myTopic. If the destination type prefix is not included in the destination name, a prefix
* of "queue://" is assumed.
*
* @param destinationName the full name of the JMS Destination
* @return the number of messages in the JMS Destination
*/
public Queue getDestinationQueue(String destinationName) {
Queue queue = null;
ActiveMQDestination destination = ActiveMQDestination.createDestination(destinationName, ActiveMQDestination.TYPE.QUEUE);
String address = destination.getAddress();
String name = destination.getName();
if (destination.isQueue()) {
queue = jmsServer.getActiveMQServer().locateQueue(destination.getSimpleAddress());
} else {
BindingQueryResult bindingQueryResult = null;
try {
bindingQueryResult = jmsServer.getActiveMQServer().bindingQuery(destination.getSimpleAddress());
} catch (Exception ex) {
log.error(String.format("getDestinationQueue( %s ) - bindingQuery for %s failed", destinationName, destination.getAddress()), ex);
return null;
}
if (bindingQueryResult.isExists()) {
List<SimpleString> queueNames = bindingQueryResult.getQueueNames();
if (queueNames.size() > 0) {
queue = jmsServer.getActiveMQServer().locateQueue(queueNames.get(0));
}
}
}
return queue;
}
use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.
the class JMSTest method createDestination.
public static Destination createDestination(String dest) {
ActiveMQDestination destination = (ActiveMQDestination) ActiveMQDestination.fromPrefixedName(dest);
System.out.println("SimpleAddress: " + destination.getSimpleAddress());
return destination;
}
use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.
the class SelectorTest method createDestination.
public static Destination createDestination(String dest) {
ActiveMQDestination destination = (ActiveMQDestination) ActiveMQDestination.fromPrefixedName(dest);
System.out.println("SimpleAddress: " + destination.getSimpleAddress());
return destination;
}
use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.
the class ActiveMQActivation method setupDestination.
protected void setupDestination() throws Exception {
String destinationName = spec.getDestination();
if (spec.isUseJNDI()) {
Context ctx;
if (spec.getParsedJndiParams() == null) {
ctx = new InitialContext();
} else {
ctx = new InitialContext(spec.getParsedJndiParams());
}
logger.debug("Using context " + ctx.getEnvironment() + " for " + spec);
if (logger.isTraceEnabled()) {
logger.trace("setupDestination(" + ctx + ")");
}
String destinationTypeString = spec.getDestinationType();
if (destinationTypeString != null && !destinationTypeString.trim().equals("")) {
logger.debug("Destination type defined as " + destinationTypeString);
Class<?> destinationType;
if (Topic.class.getName().equals(destinationTypeString)) {
destinationType = Topic.class;
isTopic = true;
} else {
destinationType = Queue.class;
}
logger.debug("Retrieving " + destinationType.getName() + " \"" + destinationName + "\" from JNDI");
try {
destination = (ActiveMQDestination) ActiveMQRaUtils.lookup(ctx, destinationName, destinationType);
} catch (Exception e) {
if (destinationName == null) {
throw ActiveMQRABundle.BUNDLE.noDestinationName();
}
String calculatedDestinationName = destinationName.substring(destinationName.lastIndexOf('/') + 1);
if (isTopic && spec.getTopicPrefix() != null) {
calculatedDestinationName = spec.getTopicPrefix() + calculatedDestinationName;
} else if (!isTopic && spec.getQueuePrefix() != null) {
calculatedDestinationName = spec.getQueuePrefix() + calculatedDestinationName;
}
logger.debug("Unable to retrieve " + destinationName + " from JNDI. Creating a new " + destinationType.getName() + " named " + calculatedDestinationName + " to be used by the MDB.");
// If there is no binding on naming, we will just create a new instance
if (isTopic) {
destination = (ActiveMQDestination) ActiveMQJMSClient.createTopic(calculatedDestinationName);
} else {
destination = (ActiveMQDestination) ActiveMQJMSClient.createQueue(calculatedDestinationName);
}
}
} else {
logger.debug("Destination type not defined in MDB activation configuration.");
logger.debug("Retrieving " + Destination.class.getName() + " \"" + destinationName + "\" from JNDI");
destination = (ActiveMQDestination) ActiveMQRaUtils.lookup(ctx, destinationName, Destination.class);
if (destination instanceof Topic) {
isTopic = true;
}
}
} else {
ActiveMQRALogger.LOGGER.instantiatingDestination(spec.getDestinationType(), spec.getDestination());
if (Topic.class.getName().equals(spec.getDestinationType())) {
destination = (ActiveMQDestination) ActiveMQJMSClient.createTopic(spec.getDestination());
isTopic = true;
} else {
destination = (ActiveMQDestination) ActiveMQJMSClient.createQueue(spec.getDestination());
}
}
}
use of org.apache.activemq.artemis.jms.client.ActiveMQDestination in project activemq-artemis by apache.
the class LVQTest method testLastValueQueueUsingAddressQueueParameters.
@Test
public void testLastValueQueueUsingAddressQueueParameters() throws Exception {
ActiveMQConnectionFactory fact = (ActiveMQConnectionFactory) getCF();
// Set the consumer window size to 0 to not buffer any messages client side.
fact.setConsumerWindowSize(0);
Connection connection = fact.createConnection();
try {
Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
Queue queue = session.createQueue("random?last-value=true");
assertEquals("random", queue.getQueueName());
ActiveMQDestination a = (ActiveMQDestination) queue;
assertTrue(a.getQueueAttributes().getLastValue());
MessageProducer producer = session.createProducer(queue);
MessageConsumer consumer1 = session.createConsumer(queue);
connection.start();
for (int j = 0; j < 100; j++) {
TextMessage message = session.createTextMessage();
message.setText("Message" + j);
message.setStringProperty(Message.HDR_LAST_VALUE_NAME.toString(), "key");
producer.send(message);
}
// Last message only should go to the consumer
TextMessage tm = (TextMessage) consumer1.receive(10000);
assertNotNull(tm);
assertEquals("Message99", tm.getText());
} finally {
connection.close();
}
}
Aggregations