javax.jms.TemporaryTopic Java Examples

The following examples show how to use javax.jms.TemporaryTopic. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TemporaryDestinationTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * https://jira.jboss.org/jira/browse/JBMESSAGING-1566
 */
@Test
public void testCanNotCreateConsumerFromAnotherCnnectionForTemporaryTopic() throws Exception {
   Connection conn = createConnection();

   Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

   TemporaryTopic tempTopic = sess.createTemporaryTopic();

   Connection anotherConn = createConnection();

   Session sessFromAnotherConn = anotherConn.createSession(false, Session.AUTO_ACKNOWLEDGE);

   try {
      sessFromAnotherConn.createConsumer(tempTopic);
      ProxyAssertSupport.fail("Only temporary destination's own connection is allowed to create MessageConsumers for them.");
   } catch (JMSException e) {
   }
}
 
Example #2
Source File: MessageIntegrationTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
/**
 * Tests that a connection with a 'prefixes' set on its does not alter the
 * address for a temporary queue in the to/reply-to fields for incoming messages.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test(timeout = 20000)
public void testReceivedMessageWithTemporaryTopicDestinationsOnConnectionWithPrefixes() throws Exception {
    Class<? extends Destination> destType = TemporaryTopic.class;
    String destPrefix = "q12321-";
    String destName = "temp-topic://myTempTopic";
    String replyName = "temp-topic://myReplyTempTopic";
    String destAddress = destName; // We won't manipulate the temporary addresses generated by the broker
    String replyAddress = replyName; // We won't manipulate the temporary addresses generated by the broker
    String annotationName = AmqpDestinationHelper.JMS_DEST_TYPE_MSG_ANNOTATION_SYMBOL.toString();
    Byte annotationValue = AmqpDestinationHelper.TEMP_TOPIC_TYPE;
    String replyAnnotationName = AmqpDestinationHelper.JMS_REPLY_TO_TYPE_MSG_ANNOTATION_SYMBOL.toString();
    Byte replyAnnotationValue = AmqpDestinationHelper.TEMP_TOPIC_TYPE;

    doReceivedMessageOnConnectionWithPrefixTestImpl(destType, destPrefix, destName, replyName,
                                                    destAddress, replyAddress, annotationName,
                                                    annotationValue, replyAnnotationName, replyAnnotationValue);
}
 
Example #3
Source File: TemporaryDestinationTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testTemporaryTopicShouldNotBeInJNDI() throws Exception {
   Connection producerConnection = createConnection();

   Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);

   TemporaryTopic tempTopic = producerSession.createTemporaryTopic();
   String topicName = tempTopic.getTopicName();

   try {
      ic.lookup("/topic/" + topicName);
      ProxyAssertSupport.fail("The temporary queue should not be bound to JNDI");
   } catch (NamingException e) {
      // Expected
   }
}
 
Example #4
Source File: SessionIntegrationTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 20000)
public void testCreateAndDeleteTemporaryTopic() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection = testFixture.establishConnecton(testPeer);
        connection.start();

        testPeer.expectBegin();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        String dynamicAddress = "myTempTopicAddress";
        testPeer.expectTempTopicCreationAttach(dynamicAddress);
        TemporaryTopic tempTopic = session.createTemporaryTopic();

        // Deleting the TemporaryTopic will be achieved by closing its creating link.
        testPeer.expectDetach(true, true, true);
        tempTopic.delete();

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example #5
Source File: AMQPMessageSupport.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static byte destinationType(Destination destination) {
   if (destination instanceof Queue) {
      if (destination instanceof TemporaryQueue) {
         return TEMP_QUEUE_TYPE;
      } else {
         return QUEUE_TYPE;
      }
   } else if (destination instanceof Topic) {
      if (destination instanceof TemporaryTopic) {
         return TEMP_TOPIC_TYPE;
      } else {
         return TOPIC_TYPE;
      }
   }

   return QUEUE_TYPE;
}
 
Example #6
Source File: TempDestLoadTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void testLoadTempAdvisoryTopics() throws Exception {
   for (int i = 0; i < MESSAGE_COUNT; i++) {
      TemporaryTopic tempTopic = session.createTemporaryTopic();
      MessageConsumer consumer = session.createConsumer(tempTopic);
      MessageProducer producer = session.createProducer(tempTopic);
      consumer.close();
      producer.close();
      tempTopic.delete();
   }

   AdvisoryBroker ab = (AdvisoryBroker) broker.getBroker().getAdaptor(AdvisoryBroker.class);
   assertTrue(ab.getAdvisoryDestinations().size() == 0);
   assertTrue(ab.getAdvisoryConsumers().size() == 0);
   assertTrue(ab.getAdvisoryProducers().size() == 0);
   RegionBroker rb = (RegionBroker) broker.getBroker().getAdaptor(RegionBroker.class);

   for (Destination dest : rb.getDestinationMap().values()) {
      LOG.debug("Destination: {}", dest);
   }

   // there should be at least 2 destinations - advisories -
   // 1 for the connection + 1 generic ones
   assertTrue("Should be at least 2 destinations", rb.getDestinationMap().size() > 2);
}
 
Example #7
Source File: JmsTemporaryTopicTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testCantDeleteTemporaryTopicWithConsumers() throws Exception {
    connection = createAmqpConnection();
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryTopic tempTopic = session.createTemporaryTopic();
    MessageConsumer consumer = session.createConsumer(tempTopic);

    try {
        tempTopic.delete();
        fail("should not be able to delete temporary topic with active consumers");
    } catch (IllegalStateException ide) {
        // expected
    }

    consumer.close();

    // Now it should be allowed
    tempTopic.delete();
}
 
Example #8
Source File: MessagingACLTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublishToTempTopicSuccess() throws Exception
{
    configureACL(String.format("ACL ALLOW-LOG %s ACCESS VIRTUALHOST", USER1),
                 isLegacyClient() ? String.format("ACL ALLOW-LOG %s PUBLISH EXCHANGE name=\"amq.topic\"", USER1) :
                         String.format("ACL ALLOW-LOG %s PUBLISH EXCHANGE temporary=\"true\"", USER1));

    Connection connection = getConnectionBuilder().setUsername(USER1).setPassword(USER1_PASSWORD).build();
    try
    {
        Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
        connection.start();

        TemporaryTopic temporaryTopic = session.createTemporaryTopic();
        MessageProducer producer = session.createProducer(temporaryTopic);
        producer.send(session.createMessage());
        session.commit();
    }
    finally
    {
        connection.close();
    }
}
 
Example #9
Source File: MessagingACLTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTempTopicSuccess() throws Exception
{
    configureACL(String.format("ACL ALLOW-LOG %s ACCESS VIRTUALHOST", USER1));
    Connection connection = getConnectionBuilder().setUsername(USER1).setPassword(USER1_PASSWORD).build();
    try
    {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        TemporaryTopic temporaryTopic = session.createTemporaryTopic();
        assertNotNull(temporaryTopic);
    }
    finally
    {
        connection.close();
    }
}
 
Example #10
Source File: JmsTemporaryTopicTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #11
Source File: MessagingACLTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testConsumeFromTempTopicSuccess() throws Exception
{
    configureACL(String.format("ACL ALLOW-LOG %s ACCESS VIRTUALHOST", USER1),
                 String.format("ACL ALLOW-LOG %s CREATE QUEUE temporary=\"true\"", USER1),
                 String.format("ACL ALLOW-LOG %s CONSUME QUEUE temporary=\"true\"", USER1),
                 String.format(isLegacyClient()
                                       ? "ACL ALLOW-LOG %s BIND EXCHANGE name=\"amq.topic\""
                                       : "ACL ALLOW-LOG %s BIND EXCHANGE temporary=\"true\"", USER1));

    Connection connection = getConnectionBuilder().setUsername(USER1).setPassword(USER1_PASSWORD).build();
    try
    {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        connection.start();
        TemporaryTopic temporaryTopic = session.createTemporaryTopic();
        session.createConsumer(temporaryTopic);
    }
    finally
    {
        connection.close();
    }
}
 
Example #12
Source File: JmsConnectionTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout=30000)
public void testDeleteOfTempTopicOnClosedConnection() throws JMSException, IOException {
    connection = new JmsConnection(connectionInfo, provider);
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryTopic tempTopic = session.createTemporaryTopic();
    assertNotNull(tempTopic);

    connection.close();
    try {
        tempTopic.delete();
        fail("Should have thrown an IllegalStateException");
    } catch (IllegalStateException ex) {
    }
}
 
Example #13
Source File: SessionIntegrationTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 20000)
public void testCreateTemporaryTopic() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection = testFixture.establishConnecton(testPeer);
        connection.start();

        testPeer.expectBegin();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        String dynamicAddress = "myTempTopicAddress";
        testPeer.expectTempTopicCreationAttach(dynamicAddress);

        TemporaryTopic tempTopic = session.createTemporaryTopic();
        assertNotNull("TemporaryTopic object was null", tempTopic);
        assertNotNull("TemporaryTopic name was null", tempTopic.getTopicName());
        assertEquals("TemporaryTopic name not as expected", dynamicAddress, tempTopic.getTopicName());

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example #14
Source File: JmsConnection.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
/**
 * @return a newly initialized TemporaryTopic instance.
 */
protected TemporaryTopic createTemporaryTopic() throws JMSException {
    String destinationName = connectionInfo.getId() + ":" + tempDestIdGenerator.incrementAndGet();
    JmsTemporaryTopic topic = new JmsTemporaryTopic(destinationName);
    createResource(topic);
    tempDestinations.put(topic, topic);
    topic.setConnection(this);
    return topic;
}
 
Example #15
Source File: ActiveMQJMSContext.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public TemporaryTopic createTemporaryTopic() {
   checkSession();
   try {
      return session.createTemporaryTopic();
   } catch (JMSException e) {
      throw JmsExceptionUtils.convertToRuntimeException(e);
   }
}
 
Example #16
Source File: TemporaryTopicTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testUseFromAnotherConnectionProhibited() throws Exception
{
    final Connection connection = getConnection();
    try
    {
        final Connection connection2 = getConnection();
        try
        {
            final Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            final Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
            final TemporaryTopic topic = session1.createTemporaryTopic();

            try
            {
                session2.createConsumer(topic);
                fail("Expected a JMSException when subscribing to a temporary topic created on a different connection");
            }
            catch (JMSException je)
            {
                // pass
            }
        }
        finally
        {
            connection2.close();
        }
    }
    finally
    {
        connection.close();
    }
}
 
Example #17
Source File: MessagingTopic.java    From chipster with MIT License 5 votes vote down vote up
/**
 * 
 * 
 * @throws JMSException
 */
public void delete() throws JMSException {
	if (this.topic instanceof TemporaryTopic) {
		this.consumer.close();
		((TemporaryTopic)topic).delete();
	}
}
 
Example #18
Source File: JMSContextImpl.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public TemporaryTopic createTemporaryTopic() {
    try {
        return session().createTemporaryTopic();
    } catch (final JMSException e) {
        throw toRuntimeException(e);
    }
}
 
Example #19
Source File: JmsPoolJMSContext.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@Override
public TemporaryTopic createTemporaryTopic() {
    try {
        return getSession().createTemporaryTopic();
    } catch (JMSException jmse) {
        throw JMSExceptionSupport.createRuntimeException(jmse);
    }
}
 
Example #20
Source File: MessageIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the a connection with 'destination prefixes' set on it does not add
 * the prefix to the content of the to/reply-to fields for TemporaryTopics.
 *
 * @throws Exception if an error occurs during the test.
 */
@Test(timeout = 20000)
public void testSendMessageWithTemporaryTopicDestinationsOnConnectionWithDestinationPrefixes() throws Exception {
    Class<? extends Destination> destType = TemporaryTopic.class;
    String destPrefix = "q12321-";
    String destName = null;
    String destAddress = "temp-topic://myTempTopic";
    Byte annotationValue = AmqpDestinationHelper.TEMP_TOPIC_TYPE;

    doSendMessageOnConnectionWithPrefixTestImpl(destType, destPrefix, destName, destAddress, annotationValue);
}
 
Example #21
Source File: JmsSessionTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout=30000)
public void testCreateTemporaryTopic() throws Exception {
    connection = createAmqpConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic topic = session.createTemporaryTopic();
    assertNotNull(topic);
    assertTrue(topic instanceof TemporaryTopic);

    final BrokerViewMBean broker = getProxyToBroker();
    assertEquals(1, broker.getTemporaryTopics().length);
}
 
Example #22
Source File: TemporaryTopicTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testMessageDeliveryUsingTemporaryTopic() throws Exception
{
    final Connection connection = getConnection();
    try
    {
        final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        final TemporaryTopic topic = session.createTemporaryTopic();
        assertNotNull("Temporary topic is null", topic);
        final MessageProducer producer = session.createProducer(topic);
        final MessageConsumer consumer1 = session.createConsumer(topic);
        final MessageConsumer consumer2 = session.createConsumer(topic);
        connection.start();
        producer.send(session.createTextMessage("hello"));

        final TextMessage tm1 = (TextMessage) consumer1.receive(getReceiveTimeout());
        final TextMessage tm2 = (TextMessage) consumer2.receive(getReceiveTimeout());

        assertNotNull("Message not received by subscriber1", tm1);
        assertEquals("hello", tm1.getText());
        assertNotNull("Message not received by subscriber2", tm2);
        assertEquals("hello", tm2.getText());
    }
    finally
    {
        connection.close();
    }
}
 
Example #23
Source File: SessionIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 20000)
public void testDeleteTemporaryTopicTimesOut() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer);
        connection.setCloseTimeout(500);

        connection.start();

        testPeer.expectBegin();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        String dynamicAddress = "myTempTopicAddress";
        testPeer.expectTempTopicCreationAttach(dynamicAddress);
        TemporaryTopic tempTopic = session.createTemporaryTopic();

        // Deleting the TemporaryTopic will be achieved by closing its creating link.
        testPeer.expectDetach(true, false, true);

        try {
            tempTopic.delete();
            fail("Should have timed out waiting to delete.");
        } catch (JmsOperationTimedOutException jmsEx) {
            LOG.info("Caught expected exception: {}", jmsEx.getMessage());
        }

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example #24
Source File: SimpleOpenWireTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testTempTopicDelete() throws Exception {
   connection.start();
   TopicSession topicSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

   TemporaryTopic tempTopic = topicSession.createTemporaryTopic();

   ActiveMQConnection newConn = (ActiveMQConnection) factory.createConnection();

   try {
      TopicSession newTopicSession = newConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
      TopicPublisher publisher = newTopicSession.createPublisher(tempTopic);

      // need to wait here because the ActiveMQ client's temp destination map is updated asynchronously, not waiting can introduce a race
      assertTrue(Wait.waitFor(() -> newConn.activeTempDestinations.size() == 1, 2000, 100));

      TextMessage msg = newTopicSession.createTextMessage("Test Message");

      publisher.publish(msg);

      try {
         TopicSubscriber consumer = newTopicSession.createSubscriber(tempTopic);
         fail("should have gotten exception but got consumer: " + consumer);
      } catch (JMSException ex) {
         //correct
      }

      connection.close();

      try {
         Message newMsg = newTopicSession.createMessage();
         publisher.publish(newMsg);
      } catch (JMSException e) {
         //ok
      }

   } finally {
      newConn.close();
   }
}
 
Example #25
Source File: AdvisoryOpenWireTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testTempTopicLeak() throws Exception {
   Connection connection = null;

   try {
      connection = factory.createConnection();
      connection.start();

      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

      TemporaryTopic temporaryTopic = session.createTemporaryTopic();
      temporaryTopic.delete();

      Object[] queueResources = server.getManagementService().getResources(QueueControl.class);

      for (Object queueResource : queueResources) {

         if (((QueueControl) queueResource).getAddress().equals("ActiveMQ.Advisory.TempTopic")) {
            QueueControl queueControl = (QueueControl) queueResource;
            Wait.waitFor(() -> queueControl.getMessageCount() == 0);
            assertNotNull("addressControl for temp advisory", queueControl);

            Wait.assertEquals(0, queueControl::getMessageCount);
            Wait.assertEquals(2, queueControl::getMessagesAdded);
         }
      }
   } finally {
      if (connection != null) {
         connection.close();
      }
   }
}
 
Example #26
Source File: JmsTopicRequestReplyTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void deleteTemporaryDestination(Destination dest) throws JMSException {
   if (topic) {
      ((TemporaryTopic) dest).delete();
   } else {
      ((TemporaryQueue) dest).delete();
   }
}
 
Example #27
Source File: JMSTemporaryDestinationTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 30000)
public void testDeleteTemporaryTopic() throws Exception {
   Connection connection = createConnection();

   try {
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      final javax.jms.Topic topic = session.createTemporaryTopic();
      assertNotNull(topic);
      assertTrue(topic instanceof TemporaryTopic);

      Queue queueView = getProxyToQueue(topic.getTopicName());
      assertNotNull(queueView);

      TemporaryTopic tempTopic = (TemporaryTopic) topic;
      tempTopic.delete();

      assertTrue("Temp Queue should be deleted.", Wait.waitFor(new Wait.Condition() {

         @Override
         public boolean isSatisfied() throws Exception {
            return getProxyToQueue(topic.getTopicName()) == null;
         }
      }, TimeUnit.SECONDS.toMillis(30), TimeUnit.MILLISECONDS.toMillis(50)));
   } finally {
      connection.close();
   }
}
 
Example #28
Source File: JmsTopicRequestReplyTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void deleteTemporaryDestination(Destination dest) throws JMSException {
   if (topic) {
      ((TemporaryTopic) dest).delete();
   } else {
      ((TemporaryQueue) dest).delete();
   }
}
 
Example #29
Source File: TemporaryDestinationTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testTemporaryTopicDeleteWithConsumer() throws Exception {
   Connection conn = null;

   try {
      conn = createConnection();

      Session producerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Session consumerSession = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      TemporaryTopic tempTopic = producerSession.createTemporaryTopic();

      MessageConsumer consumer = consumerSession.createConsumer(tempTopic);

      try {
         tempTopic.delete();

         ProxyAssertSupport.fail("Should throw JMSException");
      } catch (JMSException e) {
         // Should fail - you can't delete a temp topic if it has active consumers
      }

      consumer.close();
   } finally {
      if (conn != null) {
         conn.close();
      }
   }
}
 
Example #30
Source File: ActiveMQRASessionFactoryImpl.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Add temporary topic
 *
 * @param temp The temporary topic
 */
@Override
public void addTemporaryTopic(final TemporaryTopic temp) {
   if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
      ActiveMQRALogger.LOGGER.trace("addTemporaryTopic(" + temp + ")");
   }

   synchronized (tempTopics) {
      tempTopics.add(temp);
   }
}