Java Code Examples for javax.jms.Session#createTemporaryTopic()

The following examples show how to use javax.jms.Session#createTemporaryTopic() . 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: JmsPoolConnectionTemporaryDestinationTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testNoTemporaryTopicLeaksAfterConnectionClose() throws Exception {
    JmsPoolConnection connection = null;
    MockJMSConnection pooledConnection = null;

    Session session = null;
    Topic tempTopic = null;

    for (int i = 0; i < 10; i++) {
        connection = (JmsPoolConnection) cf.createConnection();
        pooledConnection = (MockJMSConnection) connection.getConnection();
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        tempTopic = session.createTemporaryTopic();
        LOG.info("Created queue named: " + tempTopic.getTopicName());
        connection.close();
        assertEquals(0, pooledConnection.getConnectionStats().getActiveTemporaryTopicCount());
    }

    assertEquals(10, pooledConnection.getConnectionStats().getTotalTemporaryTopicsCreated());
}
 
Example 2
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 3
Source File: JMSConnectionWithSecurityTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 30000)
public void testCreateTemporaryTopicNotAuthorized() throws JMSException {
   Connection connection = createConnection(guestUser, guestPass);

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

      try {
         session.createTemporaryTopic();
      } catch (JMSSecurityException jmsse) {
         instanceLog.debug("Client should have thrown a JMSSecurityException but only threw JMSException");
      }

      // Should not be fatal
      assertNotNull(connection.createSession(false, Session.AUTO_ACKNOWLEDGE));
   } finally {
      connection.close();
   }
}
 
Example 4
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 5
Source File: MessagingTopic.java    From chipster with MIT License 6 votes vote down vote up
public MessagingTopic(Session session, String topicName, Type type, AccessMode accessMode, MessagingEndpoint endpoint) throws JMSException {
	this.session = session;
	
	switch (type) {
	case NORMAL:
		this.topic = session.createTopic(topicName);
		break;
	case TEMPORARY:
		this.topic = session.createTemporaryTopic();
		break;
	case MOCK:
		// initialise nothing
		break;
	default:
		throw new RuntimeException("unknown type " + type);
	}
	
	// create consumer only if we need to read from the topic
	if (accessMode == AccessMode.READ || accessMode == AccessMode.READ_WRITE) {
		this.consumer = session.createConsumer(topic);	
	}
	this.endpoint = endpoint;
}
 
Example 6
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 7
Source File: JmsTemporaryTopicTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testCantSendToTemporaryTopicFromClosedConnection() throws Exception {
    connection = createAmqpConnection();
    connection.start();

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

    Connection connection2 = createAmqpConnection();
    try {
        Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Message msg = session2.createMessage();
        MessageProducer producer = session2.createProducer(tempTopic);

        // Close the original connection
        connection.close();

        try {
            producer.send(msg);
            fail("should not be able to send to temporary topic from closed connection");
        } catch (IllegalStateException ide) {
            // expected
        }
    } finally {
        connection2.close();
    }
}
 
Example 8
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 9
Source File: JmsTemporaryTopicTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testCreateTemporaryTopic() throws Exception {
    connection = createAmqpConnection();
    connection.start();

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

    assertEquals(1, brokerService.getAdminView().getTemporaryTopics().length);
}
 
Example 10
Source File: CreateTemporaryQueueBeforeStartTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testCreateTemporaryQueue() throws Exception {
   connection = createConnection();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue queue = session.createTemporaryQueue();
   assertTrue("No queue created!", queue != null);
   Topic topic = session.createTemporaryTopic();
   assertTrue("No topic created!", topic != null);
}
 
Example 11
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 12
Source File: JmsPoolSessionTest.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testCreateTemporaryTopic() throws Exception {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryTopic topic = session.createTemporaryTopic();
    assertNotNull(topic);
    assertTrue(topic instanceof MockJMSTemporaryTopic);
}
 
Example 13
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 14
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 15
Source File: TemporaryDestinationToFromNameTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testCreateTemporaryTopicThenCreateATopicFromItsName() throws Exception {
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

   Topic tempTopic = session.createTemporaryTopic();
   String name = tempTopic.getTopicName();
   LOG.info("Created topic named: " + name);

   Topic createdTopic = session.createTopic(name);

   assertEquals("created topic not equal to temporary topic", tempTopic, createdTopic);
}
 
Example 16
Source File: JobSchedulerManagementTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testBrowseWithSelector() throws Exception {
   Connection connection = createConnection();

   // Setup the scheduled Message
   scheduleMessage(connection, TimeUnit.SECONDS.toMillis(9));
   scheduleMessage(connection, TimeUnit.SECONDS.toMillis(10));
   scheduleMessage(connection, TimeUnit.SECONDS.toMillis(5));
   scheduleMessage(connection, TimeUnit.SECONDS.toMillis(45));

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

   // Create the Browse Destination and the Reply To location
   Destination requestBrowse = session.createTopic(ScheduledMessage.AMQ_SCHEDULER_MANAGEMENT_DESTINATION);
   Destination browseDest = session.createTemporaryTopic();

   // Create the "Browser"
   MessageConsumer browser = session.createConsumer(browseDest, ScheduledMessage.AMQ_SCHEDULED_DELAY + " = 45000");

   connection.start();

   // Send the browse request
   MessageProducer producer = session.createProducer(requestBrowse);
   Message request = session.createMessage();
   request.setStringProperty(ScheduledMessage.AMQ_SCHEDULER_ACTION, ScheduledMessage.AMQ_SCHEDULER_ACTION_BROWSE);
   request.setJMSReplyTo(browseDest);
   producer.send(request);

   // Now try and receive the one we selected
   Message message = browser.receive(5000);
   assertNotNull(message);
   assertEquals(45000, message.getLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY));

   // Now check if there are anymore, there shouldn't be
   message = browser.receive(5000);
   assertNull(message);
}
 
Example 17
Source File: PooledConnectionFactoryWithTemporaryDestinationsTest.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testTemporaryTopicLeakAfterConnectionClose() throws Exception {
    Connection pooledConnection = null;
    Session session = null;
    Topic tempTopic = null;
    for (int i = 0; i < 2; i++) {
        pooledConnection = pooledFactory.createConnection();
        session = pooledConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        tempTopic = session.createTemporaryTopic();
        LOG.info("Created topic named: " + tempTopic.getTopicName());
        pooledConnection.close();
    }

    assertEquals(0, countBrokerTemporaryTopics());
}
 
Example 18
Source File: JmsTopicRequestReplyTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
protected Destination createTemporaryDestination(Session session) throws JMSException {
   if (topic) {
      return session.createTemporaryTopic();
   }
   return session.createTemporaryQueue();
}
 
Example 19
Source File: TemporaryDestinationTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testTemporaryTopicBasic() 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();

      final MessageProducer producer = producerSession.createProducer(tempTopic);

      MessageConsumer consumer = consumerSession.createConsumer(tempTopic);

      conn.start();

      final String messageText = "This is a message";

      final Message m = producerSession.createTextMessage(messageText);

      Thread t = new Thread(new Runnable() {
         @Override
         public void run() {
            try {
               // this is needed to make sure the main thread has enough time to block
               Thread.sleep(500);
               producer.send(m);
            } catch (Exception e) {
               log.error(e);
            }
         }
      }, "Producer");
      t.start();

      TextMessage m2 = (TextMessage) consumer.receive(3000);

      ProxyAssertSupport.assertNotNull(m2);

      ProxyAssertSupport.assertEquals(messageText, m2.getText());

      t.join();
   } finally {
      if (conn != null) {
         conn.close();
      }
   }
}
 
Example 20
Source File: JmsPoolConnectionTest.java    From pooled-jms with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 60000)
public void testConnectionDeletesOnlyItsOwnTempTopicsOnClose() throws JMSException {
    JmsPoolConnection connection1 = (JmsPoolConnection) cf.createConnection();
    JmsPoolConnection connection2 = (JmsPoolConnection) cf.createConnection();

    assertSame(connection1.getConnection(), connection2.getConnection());

    final Set<TemporaryTopic> deleted = new HashSet<>();

    MockJMSConnection mockConnection = (MockJMSConnection) connection1.getConnection();
    mockConnection.addConnectionListener(new MockJMSDefaultConnectionListener() {

        @Override
        public void onDeleteTemporaryTopic(MockJMSTemporaryTopic queue) throws JMSException {
            deleted.add(queue);
        }
    });

    Session session1 = connection1.createSession();
    Session session2 = connection2.createSession();

    TemporaryTopic tempTopic1 = session1.createTemporaryTopic();
    TemporaryTopic tempTopic2 = session1.createTemporaryTopic();

    TemporaryTopic tempTopic3 = session2.createTemporaryTopic();
    TemporaryTopic tempTopic4 = session2.createTemporaryTopic();

    connection1.close();

    assertEquals(2, deleted.size());
    assertTrue(deleted.contains(tempTopic1));
    assertTrue(deleted.contains(tempTopic2));
    assertFalse(deleted.contains(tempTopic3));
    assertFalse(deleted.contains(tempTopic4));

    connection2.close();
    assertEquals(4, deleted.size());
    assertTrue(deleted.contains(tempTopic1));
    assertTrue(deleted.contains(tempTopic2));
    assertTrue(deleted.contains(tempTopic3));
    assertTrue(deleted.contains(tempTopic4));
}