use of org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException in project activemq-artemis by apache.
the class ActiveMQMessageProducer method doSendx.
private void doSendx(ActiveMQDestination destination, final Message jmsMessage, final int deliveryMode, final int priority, final long timeToLive, CompletionListener completionListener) throws JMSException {
jmsMessage.setJMSDeliveryMode(deliveryMode);
jmsMessage.setJMSPriority(priority);
if (timeToLive == 0) {
jmsMessage.setJMSExpiration(0);
} else {
jmsMessage.setJMSExpiration(System.currentTimeMillis() + timeToLive);
}
if (!disableMessageTimestamp) {
jmsMessage.setJMSTimestamp(System.currentTimeMillis());
} else {
jmsMessage.setJMSTimestamp(0);
}
SimpleString address = null;
if (destination == null) {
if (defaultDestination == null) {
throw new UnsupportedOperationException("Destination must be specified on send with an anonymous producer");
}
destination = defaultDestination;
} else {
if (defaultDestination != null) {
if (!destination.equals(defaultDestination)) {
throw new UnsupportedOperationException("Where a default destination is specified " + "for the sender and a destination is " + "specified in the arguments to the send, " + "these destinations must be equal");
}
}
address = destination.getSimpleAddress();
if (!connection.containsKnownDestination(address)) {
try {
ClientSession.AddressQuery query = clientSession.addressQuery(address);
if (!query.isExists()) {
if (destination.isQueue() && query.isAutoCreateQueues()) {
clientSession.createAddress(address, RoutingType.ANYCAST, true);
if (destination.isTemporary()) {
// TODO is it right to use the address for the queue name here?
clientSession.createTemporaryQueue(address, RoutingType.ANYCAST, address);
} else {
createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query.getDefaultMaxConsumers(), query.isDefaultPurgeOnNoConsumers(), query.isDefaultExclusive(), query.isDefaultLastValueQueue());
}
} else if (!destination.isQueue() && query.isAutoCreateAddresses()) {
clientSession.createAddress(address, RoutingType.MULTICAST, true);
} else if ((destination.isQueue() && !query.isAutoCreateQueues()) || (!destination.isQueue() && !query.isAutoCreateAddresses())) {
throw new InvalidDestinationException("Destination " + address + " does not exist");
}
} else {
ClientSession.QueueQuery queueQuery = clientSession.queueQuery(address);
if (queueQuery.isExists()) {
connection.addKnownDestination(address);
} else if (destination.isQueue() && query.isAutoCreateQueues()) {
if (destination.isTemporary()) {
clientSession.createTemporaryQueue(address, RoutingType.ANYCAST, address);
} else {
createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query.getDefaultMaxConsumers(), query.isDefaultPurgeOnNoConsumers(), query.isDefaultExclusive(), query.isDefaultLastValueQueue());
}
}
}
} catch (ActiveMQQueueExistsException e) {
// The queue was created by another client/admin between the query check and send create queue packet
} catch (ActiveMQException e) {
throw JMSExceptionHelper.convertFromActiveMQException(e);
}
}
}
ActiveMQMessage activeMQJmsMessage;
boolean foreign = false;
// First convert from foreign message if appropriate
if (!(jmsMessage instanceof ActiveMQMessage)) {
if (jmsMessage instanceof BytesMessage) {
activeMQJmsMessage = new ActiveMQBytesMessage((BytesMessage) jmsMessage, clientSession);
} else if (jmsMessage instanceof MapMessage) {
activeMQJmsMessage = new ActiveMQMapMessage((MapMessage) jmsMessage, clientSession);
} else if (jmsMessage instanceof ObjectMessage) {
activeMQJmsMessage = new ActiveMQObjectMessage((ObjectMessage) jmsMessage, clientSession, options);
} else if (jmsMessage instanceof StreamMessage) {
activeMQJmsMessage = new ActiveMQStreamMessage((StreamMessage) jmsMessage, clientSession);
} else if (jmsMessage instanceof TextMessage) {
activeMQJmsMessage = new ActiveMQTextMessage((TextMessage) jmsMessage, clientSession);
} else {
activeMQJmsMessage = new ActiveMQMessage(jmsMessage, clientSession);
}
// Set the destination on the original message
jmsMessage.setJMSDestination(destination);
foreign = true;
} else {
activeMQJmsMessage = (ActiveMQMessage) jmsMessage;
}
if (!disableMessageID) {
// Generate a JMS id
UUID uid = UUIDGenerator.getInstance().generateUUID();
activeMQJmsMessage.getCoreMessage().setUserID(uid);
activeMQJmsMessage.resetMessageID(null);
}
if (foreign) {
jmsMessage.setJMSMessageID(activeMQJmsMessage.getJMSMessageID());
}
activeMQJmsMessage.setJMSDestination(destination);
try {
activeMQJmsMessage.doBeforeSend();
} catch (Exception e) {
JMSException je = new JMSException(e.getMessage());
je.initCause(e);
throw je;
}
if (defaultDeliveryDelay > 0) {
activeMQJmsMessage.setJMSDeliveryTime(System.currentTimeMillis() + defaultDeliveryDelay);
}
ClientMessage coreMessage = activeMQJmsMessage.getCoreMessage();
coreMessage.putStringProperty(ActiveMQConnection.CONNECTION_ID_PROPERTY_NAME, connID);
coreMessage.setRoutingType(destination.isQueue() ? RoutingType.ANYCAST : RoutingType.MULTICAST);
try {
/**
* Using a completionListener requires wrapping using a {@link CompletionListenerWrapper},
* so we avoid it if we can.
*/
if (completionListener != null) {
clientProducer.send(address, coreMessage, new CompletionListenerWrapper(completionListener, jmsMessage, this));
} else {
clientProducer.send(address, coreMessage);
}
} catch (ActiveMQInterruptedException e) {
JMSException jmsException = new JMSException(e.getMessage());
jmsException.initCause(e);
throw jmsException;
} catch (ActiveMQException e) {
throw JMSExceptionHelper.convertFromActiveMQException(e);
} catch (java.lang.IllegalStateException e) {
JMSException je = new IllegalStateException(e.getMessage());
je.setStackTrace(e.getStackTrace());
je.initCause(e);
throw je;
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException in project activemq-artemis by apache.
the class CreateQueueIdempotentTest method testSequentialCreateQueueIdempotency.
@Test
public void testSequentialCreateQueueIdempotency() throws Exception {
final SimpleString QUEUE = new SimpleString("SequentialCreateQueueIdempotency");
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
ClientSession session = sf.createSession(false, true, true);
session.createQueue(QUEUE, QUEUE, null, true);
try {
session.createQueue(QUEUE, QUEUE, null, true);
fail("Expected exception, queue already exists");
} catch (ActiveMQQueueExistsException qee) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException in project activemq-artemis by apache.
the class PredefinedQueueTest method testFailOnCreatePredefinedQueues.
@Test
public void testFailOnCreatePredefinedQueues() throws Exception {
final String testAddress = "testAddress";
final String queueName1 = "queue1";
final String queueName2 = "queue2";
final String queueName3 = "queue3";
CoreQueueConfiguration queue1 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName1);
CoreQueueConfiguration queue2 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName2);
CoreQueueConfiguration queue3 = new CoreQueueConfiguration().setAddress(testAddress).setName(queueName3);
List<CoreQueueConfiguration> queueConfs = new ArrayList<>();
queueConfs.add(queue1);
queueConfs.add(queue2);
queueConfs.add(queue3);
configuration.setQueueConfigurations(queueConfs);
ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(configuration, false));
server.start();
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = addClientSession(sf.createSession(false, true, true));
try {
session.createQueue(testAddress, queueName1, "", false);
Assert.fail("Should throw exception");
} catch (ActiveMQQueueExistsException se) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
try {
session.createQueue(testAddress, queueName2, null, false);
Assert.fail("Should throw exception");
} catch (ActiveMQQueueExistsException se) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
try {
session.createQueue(testAddress, queueName3, null, false);
Assert.fail("Should throw exception");
} catch (ActiveMQQueueExistsException se) {
// ok
} catch (ActiveMQException e) {
fail("Invalid Exception type:" + e.getType());
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException in project activemq-artemis by apache.
the class ArtemisBrokerWrapper method makeSureQueueExists.
public void makeSureQueueExists(String qname) throws Exception {
synchronized (testQueues) {
SimpleString coreQ = testQueues.get(qname);
if (coreQ == null) {
coreQ = new SimpleString(qname);
try {
this.server.createQueue(coreQ, RoutingType.MULTICAST, coreQ, null, false, false);
testQueues.put(qname, coreQ);
} catch (ActiveMQQueueExistsException e) {
// ignore
}
}
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException in project activemq-artemis by apache.
the class MQTTSubscriptionManager method findOrCreateQueue.
private Queue findOrCreateQueue(BindingQueryResult bindingQueryResult, AddressInfo addressInfo, SimpleString queue, int qos) throws Exception {
if (addressInfo.getRoutingTypes().contains(RoutingType.MULTICAST)) {
return session.getServerSession().createQueue(addressInfo.getName(), queue, RoutingType.MULTICAST, managementFilter, false, MQTTUtil.DURABLE_MESSAGES && qos >= 0, false);
}
if (addressInfo.getRoutingTypes().contains(RoutingType.ANYCAST)) {
if (!bindingQueryResult.getQueueNames().isEmpty()) {
SimpleString name = null;
for (SimpleString qName : bindingQueryResult.getQueueNames()) {
if (name == null) {
name = qName;
} else if (qName.equals(addressInfo.getName())) {
name = qName;
}
}
return session.getServer().locateQueue(name);
} else {
try {
return session.getServerSession().createQueue(addressInfo.getName(), addressInfo.getName(), RoutingType.ANYCAST, managementFilter, false, MQTTUtil.DURABLE_MESSAGES && qos >= 0, false);
} catch (ActiveMQQueueExistsException e) {
return session.getServer().locateQueue(addressInfo.getName());
}
}
}
Set<RoutingType> routingTypeSet = new HashSet();
routingTypeSet.add(RoutingType.MULTICAST);
routingTypeSet.add(RoutingType.ANYCAST);
throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeForAddress(addressInfo.getRoutingType(), addressInfo.getName().toString(), routingTypeSet);
}
Aggregations