Java 类javax.jms.InvalidDestinationException 实例源码
项目:amq-kahadb-tool
文件:MqttConsumer.java
public void connect(String clientId) throws InvalidObjectException {
String serverUri = null;
try {
InetAddress inet = InetAddress.getLocalHost();
InetAddress[] ips = InetAddress.getAllByName(inet.getCanonicalHostName());
if (ips != null && ips.length != 0) {
serverUri = "tcp://" + ips[0].getHostAddress();
}
else {
throw new InvalidDestinationException("Not network device.");
}
}
catch (Throwable throwable) {
showException(throwable);
}
if(serverUri != null) {
connect(clientId, serverUri);
}
}
项目:activemq-artemis
文件:AmqpFullyQualifiedNameTest.java
@Test
public void testFQQNTopicWhenQueueDoesNotExist() throws Exception {
Exception e = null;
String queueName = "testQueue";
Connection connection = createConnection(false);
try {
connection.setClientID("FQQNconn");
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(multicastAddress.toString() + "::" + queueName);
session.createConsumer(topic);
} catch (InvalidDestinationException ide) {
e = ide;
} finally {
connection.close();
}
assertNotNull(e);
assertTrue(e.getMessage().contains("Queue: '" + queueName + "' does not exist"));
}
项目:activemq-artemis
文件:AmqpFullyQualifiedNameTest.java
/**
* Broker should return exception if no address is passed in FQQN.
* @throws Exception
*/
@Test
public void testQueueSpecial() throws Exception {
server.createQueue(anycastAddress, RoutingType.ANYCAST, anycastQ1, null, true, false, -1, false, true);
Connection connection = createConnection();
Exception expectedException = null;
try {
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
//::queue ok!
String specialName = CompositeAddress.toFullQN(new SimpleString(""), anycastQ1).toString();
javax.jms.Queue q1 = session.createQueue(specialName);
session.createConsumer(q1);
} catch (InvalidDestinationException e) {
expectedException = e;
}
assertNotNull(expectedException);
assertTrue(expectedException.getMessage().contains("Queue: 'q1' does not exist for address ''"));
}
项目:activemq-artemis
文件:MessageConsumerTest.java
@Test
public void testCreateConsumerOnNonExistentTopic() throws Exception {
Connection pconn = null;
try {
pconn = createConnection();
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
try {
ps.createConsumer(new Topic() {
@Override
public String getTopicName() throws JMSException {
return "NoSuchTopic";
}
});
ProxyAssertSupport.fail("should throw exception");
} catch (InvalidDestinationException e) {
// OK
}
} finally {
if (pconn != null) {
pconn.close();
}
}
}
项目:activemq-artemis
文件:MessageConsumerTest.java
@Test
public void testCreateConsumerOnNonExistentQueue() throws Exception {
Connection pconn = null;
try {
pconn = createConnection();
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
try {
ps.createConsumer(new Queue() {
@Override
public String getQueueName() throws JMSException {
return "NoSuchQueue";
}
});
ProxyAssertSupport.fail("should throw exception");
} catch (InvalidDestinationException e) {
// OK
}
} finally {
if (pconn != null) {
pconn.close();
}
}
}
项目:activemq-artemis
文件:DurableSubscriptionTest.java
@Test
public void testDurableSubscriptionOnTemporaryTopic() throws Exception {
Connection conn = null;
conn = createConnection();
try {
conn.setClientID("doesn't actually matter");
Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic temporaryTopic = s.createTemporaryTopic();
try {
s.createDurableSubscriber(temporaryTopic, "mySubscription");
ProxyAssertSupport.fail("this should throw exception");
} catch (InvalidDestinationException e) {
// OK
}
} finally {
if (conn != null) {
conn.close();
}
}
}
项目:activemq-artemis
文件:MessageProducerTest.java
@Test
public void testCreateProducerOnInexistentDestination() throws Exception {
getJmsServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateQueues(false));
getJmsServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateAddresses(false));
Connection pconn = createConnection();
try {
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
try {
ps.createProducer(ActiveMQJMSClient.createTopic("NoSuchTopic"));
ProxyAssertSupport.fail("should throw exception");
} catch (InvalidDestinationException e) {
// OK
}
} finally {
pconn.close();
}
}
项目:activemq-artemis
文件:BrowserTest.java
@Test
public void testCreateBrowserOnNonExistentQueue() throws Exception {
Connection pconn = getConnectionFactory().createConnection();
try {
Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
try {
ps.createBrowser(new Queue() {
@Override
public String getQueueName() throws JMSException {
return "NoSuchQueue";
}
});
ProxyAssertSupport.fail("should throw exception");
} catch (InvalidDestinationException e) {
// OK
}
} finally {
if (pconn != null) {
pconn.close();
}
}
}
项目:activemq-artemis
文件:ActiveMQSession.java
@Override
public MessageConsumer createConsumer(final Destination destination,
final String messageSelector,
final boolean noLocal) throws JMSException {
if (destination == null) {
throw new InvalidDestinationException("Cannot create a consumer with a null destination");
}
if (!(destination instanceof ActiveMQDestination)) {
throw new InvalidDestinationException("Not an ActiveMQDestination:" + destination);
}
ActiveMQDestination jbdest = (ActiveMQDestination) destination;
if (jbdest.isTemporary() && !connection.containsTemporaryQueue(jbdest.getSimpleAddress())) {
throw new JMSException("Can not create consumer for temporary destination " + destination +
" from another JMS connection");
}
return createConsumer(jbdest, null, messageSelector, noLocal, ConsumerDurability.NON_DURABLE);
}
项目:activemq-artemis
文件:ActiveMQSession.java
@Override
public TopicSubscriber createDurableSubscriber(final Topic topic,
final String name,
String messageSelector,
final boolean noLocal) throws JMSException {
// As per spec. section 4.11
if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) {
throw new IllegalStateException("Cannot create a durable subscriber on a QueueSession");
}
checkTopic(topic);
if (!(topic instanceof ActiveMQDestination)) {
throw new InvalidDestinationException("Not an ActiveMQTopic:" + topic);
}
if ("".equals(messageSelector)) {
messageSelector = null;
}
ActiveMQDestination jbdest = (ActiveMQDestination) topic;
if (jbdest.isQueue()) {
throw new InvalidDestinationException("Cannot create a subscriber on a queue");
}
return createConsumer(jbdest, name, messageSelector, noLocal, ConsumerDurability.DURABLE);
}
项目:activemq-artemis
文件:ActiveMQSession.java
public void deleteTemporaryQueue(final ActiveMQDestination tempQueue) throws JMSException {
if (!tempQueue.isTemporary()) {
throw new InvalidDestinationException("Not a temporary queue " + tempQueue);
}
try {
QueueQuery response = session.queueQuery(tempQueue.getSimpleAddress());
if (!response.isExists()) {
throw new InvalidDestinationException("Cannot delete temporary queue " + tempQueue.getName() +
" does not exist");
}
if (response.getConsumerCount() > 0) {
throw new IllegalStateException("Cannot delete temporary queue " + tempQueue.getName() +
" since it has subscribers");
}
SimpleString address = tempQueue.getSimpleAddress();
session.deleteQueue(address);
connection.removeTemporaryQueue(address);
} catch (ActiveMQException e) {
throw JMSExceptionHelper.convertFromActiveMQException(e);
}
}
项目:ffmq
文件:LocalSession.java
private AbstractLocalDestination getLocalDestination( AbstractMessage message ) throws JMSException
{
Destination destination = message.getJMSDestination();
if (destination instanceof Queue)
{
Queue queueRef = (Queue)destination;
return engine.getLocalQueue(queueRef.getQueueName());
}
else
if (destination instanceof Topic)
{
Topic topicRef = (Topic)destination;
return engine.getLocalTopic(topicRef.getTopicName());
}
else
throw new InvalidDestinationException("Unsupported destination : "+destination);
}
项目:ffmq
文件:LocalMessageProducer.java
@Override
protected final void sendToDestination(Destination destination, boolean destinationOverride, Message srcMessage, int deliveryMode, int priority, long timeToLive) throws JMSException
{
// Check that the destination was specified
if (destination == null)
throw new InvalidDestinationException("Destination not specified"); // [JMS SPEC]
// Create an internal copy if necessary
AbstractMessage message = MessageTools.makeInternalCopy(srcMessage);
externalAccessLock.readLock().lock();
try
{
checkNotClosed();
// Dispatch to session
((LocalSession)session).dispatch(message);
}
finally
{
externalAccessLock.readLock().unlock();
}
}
项目:ffmq
文件:DestinationTools.java
/**
* Make sure the given destination is a light-weight serializable destination reference
*/
public static DestinationRef asRef( Destination destination ) throws JMSException
{
if (destination == null)
return null;
if (destination instanceof DestinationRef)
return (DestinationRef)destination;
if (destination instanceof Queue)
return new QueueRef(((Queue)destination).getQueueName());
if (destination instanceof Topic)
return new TopicRef(((Topic)destination).getTopicName());
throw new InvalidDestinationException("Unsupported destination type : "+destination,"INVALID_DESTINATION");
}
项目:andes
文件:TopicPublisherAdapter.java
private void checkTopic(Destination topic) throws InvalidDestinationException
{
if (topic == null)
{
throw new UnsupportedOperationException("Topic is null");
}
if (!(topic instanceof Topic))
{
throw new InvalidDestinationException("Destination " + topic + " is not a topic");
}
if(!(topic instanceof AMQDestination))
{
throw new InvalidDestinationException("Destination " + topic + " is not a Qpid topic");
}
}
项目:qpid-jms
文件:JmsSession.java
protected void send(JmsMessageProducer producer, Destination dest, Message msg, int deliveryMode, int priority, long timeToLive, boolean disableMsgId, boolean disableTimestamp, long deliveryDelay, CompletionListener listener) throws JMSException {
if (dest == null) {
throw new InvalidDestinationException("Destination must not be null");
}
if (msg == null) {
throw new MessageFormatException("Message must not be null");
}
JmsDestination destination = JmsMessageTransformation.transformDestination(connection, dest);
if (destination.isTemporary() && ((JmsTemporaryDestination) destination).isDeleted()) {
throw new IllegalStateException("Temporary destination has been deleted");
}
send(producer, destination, msg, deliveryMode, priority, timeToLive, disableMsgId, disableTimestamp, deliveryDelay, listener);
}
项目:qpid-jms
文件:JmsTopicPublisherTest.java
@Test(timeout = 10000)
public void testPublishMessageOnProvidedTopicWhenNotAnonymous() throws Exception {
Topic topic = session.createTopic(getTestName());
TopicPublisher publisher = session.createPublisher(topic);
Message message = session.createMessage();
try {
publisher.publish(session.createTopic(getTestName() + "1"), message);
fail("Should throw UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {}
try {
publisher.publish((Topic) null, message);
fail("Should throw InvalidDestinationException");
} catch (InvalidDestinationException ide) {}
}
项目:qpid-jms
文件:JmsTopicPublisherTest.java
@Test(timeout = 10000)
public void testPublishMessageWithOptionsOnProvidedTopicWhenNotAnonymous() throws Exception {
Topic topic = session.createTopic(getTestName());
TopicPublisher publisher = session.createPublisher(topic);
Message message = session.createMessage();
try {
publisher.publish(session.createTopic(getTestName() + "1"), message, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
fail("Should throw UnsupportedOperationException");
} catch (UnsupportedOperationException uoe) {}
try {
publisher.publish((Topic) null, message, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
fail("Should throw InvalidDestinationException");
} catch (InvalidDestinationException ide) {}
}
项目:qpid-jms
文件:FailedConnectionsIntegrationTest.java
@Test(timeout = 20000)
public void testConnectWithNotFoundErrorThrowsJMSEWhenInvalidContainerHintNotPresent() throws Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
testPeer.rejectConnect(AmqpError.NOT_FOUND, "Virtual Host does not exist", null);
try {
establishAnonymousConnecton(testPeer, true);
fail("Should have thrown JMSException");
} catch (InvalidDestinationException destEx) {
fail("Should not convert to destination exception for this case.");
} catch (JMSException jmsEx) {
LOG.info("Caught expected Exception: {}", jmsEx.getMessage(), jmsEx);
// Expected
} catch (Exception ex) {
fail("Should have thrown JMSException: " + ex);
}
testPeer.waitForAllHandlersToComplete(1000);
}
}
项目:qpid-jms
文件:JmsDurableSubscriberTest.java
@Test(timeout = 60000)
public void testDurableSubscriptionUnsubscribeNoExistingSubThrowsJMSEx() throws Exception {
connection = createAmqpConnection();
connection.setClientID("DURABLE-AMQP");
connection.start();
assertEquals(0, brokerService.getAdminView().getDurableTopicSubscribers().length);
assertEquals(0, brokerService.getAdminView().getInactiveDurableTopicSubscribers().length);
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
assertNotNull(session);
BrokerViewMBean broker = getProxyToBroker();
assertEquals(0, broker.getDurableTopicSubscribers().length);
assertEquals(0, broker.getInactiveDurableTopicSubscribers().length);
try {
session.unsubscribe(getSubscriptionName());
fail("Should have thrown an InvalidDestinationException");
} catch (InvalidDestinationException ide) {
}
}
项目:qpid-jms
文件:JmsTemporaryQueueTest.java
@Test(timeout = 60000)
public void testCantConsumeFromTemporaryQueueCreatedOnAnotherConnection() throws Exception {
connection = createAmqpConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue tempQueue = session.createTemporaryQueue();
session.createConsumer(tempQueue);
Connection connection2 = createAmqpConnection();
try {
Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
try {
session2.createConsumer(tempQueue);
fail("should not be able to consumer from temporary queue from another connection");
} catch (InvalidDestinationException ide) {
// expected
}
} finally {
connection2.close();
}
}
项目:qpid-jms
文件:JmsTemporaryTopicTest.java
@Test(timeout = 60000)
public void testCantConsumeFromTemporaryTopicCreatedOnAnotherConnection() throws Exception {
connection = createAmqpConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryTopic tempTopic = session.createTemporaryTopic();
session.createConsumer(tempTopic);
Connection connection2 = createAmqpConnection();
try {
Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
try {
session2.createConsumer(tempTopic);
fail("should not be able to consumer from temporary topic from another connection");
} catch (InvalidDestinationException ide) {
// expected
}
} finally {
connection2.close();
}
}
项目:cougar
文件:JmsEventTransportImpl.java
private Destination createDestination(Session session, String destinationName) throws JMSException {
try {
Destination destination = null;
switch (destinationType) {
case DurableTopic:
case Topic:
destination = session.createTopic(destinationName);
break;
case Queue:
destination = session.createQueue(destinationName);
break;
}
return destination;
}
catch (InvalidDestinationException ide) {
throw new CougarFrameworkException("Error creating "+destinationType+" for destination name '"+destinationName+"'",ide);
}
}
项目:iaf
文件:JMSFacade.java
public String send(Session session, Destination dest, Message message, boolean ignoreInvalidDestinationException)
throws NamingException, JMSException {
try {
if (useJms102()) {
if (dest instanceof Topic) {
return sendByTopic((TopicSession)session, (Topic)dest, message);
} else {
return sendByQueue((QueueSession)session, (Queue)dest, message);
}
} else {
MessageProducer mp = session.createProducer(dest);
mp.send(message);
mp.close();
return message.getJMSMessageID();
}
} catch (InvalidDestinationException e) {
if (ignoreInvalidDestinationException) {
log.warn("queue ["+dest+"] doesn't exist");
return null;
} else {
throw e;
}
}
}
项目:pooled-jms
文件:JmsPoolMessageProducerTest.java
@Test
public void testNullDestinationOnSendToAnonymousProducer() throws JMSException {
JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
Session session = connection.createSession();
MessageProducer producer = session.createProducer(null);
try {
producer.send(null, session.createMessage());
fail("Should not be able to send with null destination");
} catch (InvalidDestinationException ide) {}
}
项目:pooled-jms
文件:JmsPoolMessageProducerTest.java
@Test
public void testNullDestinationOnSendToTargetedProducer() throws JMSException {
JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
Session session = connection.createSession();
MessageProducer producer = session.createProducer(session.createTemporaryQueue());
try {
producer.send(null, session.createMessage());
fail("Should not be able to send with null destination");
} catch (InvalidDestinationException ide) {}
}
项目:org.ops4j.pax.transx
文件:Utils.java
public static JMSRuntimeException convertToRuntimeException(JMSException e) {
if (e instanceof javax.jms.IllegalStateException) {
return new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof InvalidClientIDException) {
return new InvalidClientIDRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof InvalidDestinationException) {
return new InvalidDestinationRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof InvalidSelectorException) {
return new InvalidSelectorRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof JMSSecurityException) {
return new JMSSecurityRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof MessageFormatException) {
return new MessageFormatRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof MessageNotWriteableException) {
return new MessageNotWriteableRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof ResourceAllocationException) {
return new ResourceAllocationRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof TransactionInProgressException) {
return new TransactionInProgressRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof TransactionRolledBackException) {
return new TransactionRolledBackRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
return new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
项目:spring4-understanding
文件:MessageListenerAdapterTests.java
@Test
public void testWithResponsiveMessageDelegateNoDefaultDestinationAndNoReplyToDestination_SendsReturnTextMessageWhenSessionSupplied() throws Exception {
final TextMessage sentTextMessage = mock(TextMessage.class);
// correlation ID is queried when response is being created...
given(sentTextMessage.getJMSCorrelationID()).willReturn(CORRELATION_ID);
// Reply-To is queried when response is being created...
given(sentTextMessage.getJMSReplyTo()).willReturn(null);
TextMessage responseTextMessage = mock(TextMessage.class);
final QueueSession session = mock(QueueSession.class);
given(session.createTextMessage(RESPONSE_TEXT)).willReturn(responseTextMessage);
ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
given(delegate.handleMessage(sentTextMessage)).willReturn(RESPONSE_TEXT);
final MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {
@Override
protected Object extractMessage(Message message) {
return message;
}
};
try {
adapter.onMessage(sentTextMessage, session);
fail("expected CouldNotSendReplyException with InvalidDestinationException");
} catch(ReplyFailureException ex) {
assertEquals(InvalidDestinationException.class, ex.getCause().getClass());
}
verify(responseTextMessage).setJMSCorrelationID(CORRELATION_ID);
verify(delegate).handleMessage(sentTextMessage);
}
项目:spring4-understanding
文件:MethodJmsListenerEndpointTests.java
@Test
public void emptySendTo() throws JMSException {
MessagingMessageListenerAdapter listener = createDefaultInstance(String.class);
TextMessage reply = mock(TextMessage.class);
Session session = mock(Session.class);
given(session.createTextMessage("content")).willReturn(reply);
thrown.expect(ReplyFailureException.class);
thrown.expectCause(Matchers.isA(InvalidDestinationException.class));
listener.onMessage(createSimpleJmsTextMessage("content"), session);
}
项目:pubsub
文件:PubSubMessageProducer.java
protected Publisher createPublisher(final Destination destination) throws JMSException {
final Publisher result;
if (destination instanceof Topic) {
result = createPublisher((Topic) destination);
} else {
throw new InvalidDestinationException("Unsupported destination.");
}
return result;
}
项目:daq-eclipse
文件:ActiveMQTopicSession.java
/**
* @param destination
* @return
* @throws JMSException
*/
public MessageConsumer createConsumer(Destination destination) throws JMSException {
if (destination instanceof Queue) {
throw new InvalidDestinationException("Queues are not supported by a TopicSession");
}
return next.createConsumer(destination);
}
项目:daq-eclipse
文件:ActiveMQTopicSession.java
/**
* @param destination
* @param messageSelector
* @return
* @throws JMSException
*/
public MessageConsumer createConsumer(Destination destination, String messageSelector) throws JMSException {
if (destination instanceof Queue) {
throw new InvalidDestinationException("Queues are not supported by a TopicSession");
}
return next.createConsumer(destination, messageSelector);
}
项目:daq-eclipse
文件:ActiveMQTopicSession.java
/**
* @param destination
* @return
* @throws JMSException
*/
public MessageProducer createProducer(Destination destination) throws JMSException {
if (destination instanceof Queue) {
throw new InvalidDestinationException("Queues are not supported by a TopicSession");
}
return next.createProducer(destination);
}
项目:daq-eclipse
文件:TopicRegion.java
@Override
public void removeSubscription(ConnectionContext context, RemoveSubscriptionInfo info) throws Exception {
SubscriptionKey key = new SubscriptionKey(info.getClientId(), info.getSubscriptionName());
DurableTopicSubscription sub = durableSubscriptions.get(key);
if (sub == null) {
throw new InvalidDestinationException("No durable subscription exists for: " + info.getSubscriptionName());
}
if (sub.isActive()) {
throw new JMSException("Durable consumer is in use");
} else {
durableSubscriptions.remove(key);
}
destinationsLock.readLock().lock();
try {
for (Destination dest : destinations.values()) {
if (dest instanceof Topic){
Topic topic = (Topic)dest;
topic.deleteSubscription(context, key);
} else if (dest instanceof DestinationFilter) {
DestinationFilter filter = (DestinationFilter) dest;
filter.deleteSubscription(context, key);
}
}
} finally {
destinationsLock.readLock().unlock();
}
if (subscriptions.get(sub.getConsumerInfo().getConsumerId()) != null) {
super.removeConsumer(context, sub.getConsumerInfo());
} else {
// try destroying inactive subscriptions
destroySubscription(sub);
}
}
项目:daq-eclipse
文件:ActiveMQQueueSession.java
/**
* @param destination
* @return
* @throws JMSException
*/
public MessageConsumer createConsumer(Destination destination) throws JMSException {
if (destination instanceof Topic) {
throw new InvalidDestinationException("Topics are not supported by a QueueSession");
}
return next.createConsumer(destination);
}
项目:daq-eclipse
文件:ActiveMQQueueSession.java
/**
* @param destination
* @param messageSelector
* @return
* @throws JMSException
*/
public MessageConsumer createConsumer(Destination destination, String messageSelector) throws JMSException {
if (destination instanceof Topic) {
throw new InvalidDestinationException("Topics are not supported by a QueueSession");
}
return next.createConsumer(destination, messageSelector);
}
项目:daq-eclipse
文件:ActiveMQQueueSession.java
/**
* @param destination
* @return
* @throws JMSException
*/
public MessageProducer createProducer(Destination destination) throws JMSException {
if (destination instanceof Topic) {
throw new InvalidDestinationException("Topics are not supported by a QueueSession");
}
return next.createProducer(destination);
}
项目:activemq-artemis
文件:AmqpFullyQualifiedNameTest.java
@Test
public void testConsumeQueueToFQQNWrongQueueAttachedToAnotherAddress() throws Exception {
// Create 2 Queues: address1::queue1, address2::queue2
String address1 = "a1";
String address2 = "a2";
String queue1 = "q1";
String queue2 = "q2";
server.createQueue(SimpleString.toSimpleString(address1), RoutingType.ANYCAST, SimpleString.toSimpleString(queue1), null, true, false, -1, false, true);
server.createQueue(SimpleString.toSimpleString(address2), RoutingType.ANYCAST, SimpleString.toSimpleString(queue2), null, true, false, -1, false, true);
Exception e = null;
// Wrong FQQN. Attempt to subscribe to a queue belonging to a different address than given in the FQQN.
String wrongFQQN = address1 + "::" + queue2;
Connection connection = createConnection(false);
try {
connection.setClientID("FQQNconn");
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
javax.jms.Queue queue = session.createQueue(wrongFQQN);
session.createConsumer(queue);
} catch (InvalidDestinationException ide) {
e = ide;
} finally {
connection.close();
}
assertNotNull(e);
assertTrue(e.getMessage().contains("Queue: '" + queue2 + "' does not exist for address '" + address1 + "'"));
}
项目:activemq-artemis
文件:AmqpFullyQualifiedNameTest.java
@Test
public void testSubscribeTopicToFQQNWrongQueueAttachedToAnotherAddress() throws Exception {
// Create 2 Queues: address1::queue1, address2::queue2
String address1 = "a1";
String address2 = "a2";
String queue1 = "q1";
String queue2 = "q2";
server.createQueue(SimpleString.toSimpleString(address1), RoutingType.MULTICAST, SimpleString.toSimpleString(queue1), null, true, false, -1, false, true);
server.createQueue(SimpleString.toSimpleString(address2), RoutingType.MULTICAST, SimpleString.toSimpleString(queue2), null, true, false, -1, false, true);
Exception e = null;
// Wrong FQQN. Attempt to subscribe to a queue belonging to a different address than given in the FQQN.
String wrongFQQN = address1 + "::" + queue2;
Connection connection = createConnection(false);
try {
connection.setClientID("FQQNconn");
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(wrongFQQN);
session.createConsumer(topic);
} catch (InvalidDestinationException ide) {
e = ide;
} finally {
connection.close();
}
assertNotNull(e);
assertTrue(e.getMessage().contains("Queue: '" + queue2 + "' does not exist for address '" + address1 + "'"));
}
项目:activemq-artemis
文件:JmsTempDestinationTest.java
/**
* Make sure Temp destination can only be consumed by local connection
*
* @throws JMSException
*/
@Test
public void testTempDestOnlyConsumedByLocalConn() throws JMSException {
connection.start();
Session tempSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue queue = tempSession.createTemporaryQueue();
MessageProducer producer = tempSession.createProducer(queue);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage message = tempSession.createTextMessage("First");
producer.send(message);
// temp destination should not be consume when using another connection
Connection otherConnection = factory.createConnection();
connections.add(otherConnection);
Session otherSession = otherConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue otherQueue = otherSession.createTemporaryQueue();
MessageConsumer consumer = otherSession.createConsumer(otherQueue);
Message msg = consumer.receive(3000);
Assert.assertNull(msg);
// should throw InvalidDestinationException when consuming a temp
// destination from another connection
try {
consumer = otherSession.createConsumer(queue);
Assert.fail("Send should fail since temp destination should be used from another connection");
} catch (InvalidDestinationException e) {
Assert.assertTrue("failed to throw an exception", true);
}
// should be able to consume temp destination from the same connection
consumer = tempSession.createConsumer(queue);
msg = consumer.receive(3000);
Assert.assertNotNull(msg);
}