Java Code Examples for javax.jms.Connection#getClientID()

The following examples show how to use javax.jms.Connection#getClientID() . 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: SpringConsumer.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void start() throws JMSException {
   String selector = "next = '" + myId + "'";

   try {
      ConnectionFactory factory = template.getConnectionFactory();
      final Connection c = connection = factory.createConnection();

      // we might be a reusable connection in spring
      // so lets only set the client ID once if its not set
      synchronized (c) {
         if (c.getClientID() == null) {
            c.setClientID(myId);
         }
      }

      connection.start();

      session = connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
      consumer = session.createConsumer(destination, selector, false);
      consumer.setMessageListener(this);
   } catch (JMSException ex) {
      LOG.error("", ex);
      throw ex;
   }
}
 
Example 2
Source File: SecurityTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * user/pwd with preconfigured clientID, should return preconf
 */
@Test
public void testPreConfClientID() throws Exception {
   Connection conn = null;
   try {
      ActiveMQServerTestCase.deployConnectionFactory("dilbert-id", "preConfcf", "preConfcf");
      ConnectionFactory cf = (ConnectionFactory) getInitialContext().lookup("preConfcf");
      conn = cf.createConnection("guest", "guest");
      String clientID = conn.getClientID();
      ProxyAssertSupport.assertEquals("Invalid ClientID", "dilbert-id", clientID);
   } finally {
      if (conn != null) {
         conn.close();
      }
      ActiveMQServerTestCase.undeployConnectionFactory("preConfcf");
   }
}
 
Example 3
Source File: JMSConnectionFactoryTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Test cached connection when the transport.jms.CacheLevel is 1
 *
 * @throws Exception
 */
@Test
public void testCacheLevelOne() throws Exception {
    String queueName = "testCaching1";
    Properties jmsProperties = JMSTestsUtils.getJMSPropertiesForDestination(queueName, PROVIDER_URL, true);
    JMSBrokerController brokerController = new JMSBrokerController(PROVIDER_URL, jmsProperties);
    jmsProperties.put(JMSConstants.PARAM_CACHE_LEVEL, "1");
    try {
        brokerController.startProcess();
        Queue queue = brokerController.connect(queueName, true);
        CachedJMSConnectionFactory cachedJMSConnectionFactory = new CachedJMSConnectionFactory(jmsProperties);
        Connection connection1 = cachedJMSConnectionFactory.getConnection(null, null);
        String clientID1 = connection1.getClientID();
        Session session1 = cachedJMSConnectionFactory.getSession(connection1);
        MessageConsumer consumer1 = cachedJMSConnectionFactory.getMessageConsumer(session1, queue);
        Connection connection2 = cachedJMSConnectionFactory.getConnection(null, null);
        Session session2 = cachedJMSConnectionFactory.getSession(connection2);
        MessageConsumer consumer2 = cachedJMSConnectionFactory.getMessageConsumer(session2, queue);
        Assert.assertEquals("Connection should be cached", clientID1, connection2.getClientID());
        Assert.assertNotSame("Session should not be cached", session1, session2);
        Assert.assertNotSame("Message Consumer should not be cached", ((ActiveMQMessageConsumer) consumer1).
                getConsumerId().toString(), ((ActiveMQMessageConsumer) consumer2).getConsumerId().toString());
        cachedJMSConnectionFactory.closeConnection();
        Connection connection3 = cachedJMSConnectionFactory.getConnection(null, null);
        Assert.assertNotSame("Connection should be closed", clientID1, connection3.getClientID());
    } finally {
        brokerController.disconnect();
        brokerController.stopProcess();
    }
}
 
Example 4
Source File: ConnectionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetClientID() throws Exception {
   Connection connection = createConnection();
   String clientID = connection.getClientID();

   // We don't currently set client ids on the server, so this should be null.
   // In the future we may provide connection factories that set a specific client id
   // so this may change
   ProxyAssertSupport.assertNull(clientID);

   connection.close();
}
 
Example 5
Source File: SecurityTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Try setting client ID
 */
@Test
public void testSetClientID() throws Exception {
   Connection conn = createConnection();
   conn.setClientID("myID");
   String clientID = conn.getClientID();
   ProxyAssertSupport.assertEquals("Invalid ClientID", "myID", clientID);
}