@Override public Connection createConnection() throws JMSException { return createConnection(user, password); }
@Override public Connection createConnection() throws JMSException { return createConnection(user, password); }
@Override public Connection createConnection() throws JMSException { return createConnection(user, password); }
@Override public Connection createConnection() throws JMSException { return createConnection(user, password); }
@Override public Connection createConnection() throws JMSException { return createConnection(user, password); }
public static void waitForServerToStart(String uri, long timeout) throws InterruptedException { long realTimeout = System.currentTimeMillis() + timeout; while (System.currentTimeMillis() < realTimeout) { try (ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory(uri, null)) { cf.createConnection().close(); System.out.println("server " + uri + " started"); } catch (Exception e) { System.out.println("awaiting server " + uri + " start at "); Thread.sleep(500); continue; } break; } }
public static void waitForServerToStart(String uri, long timeout) throws InterruptedException { long realTimeout = System.currentTimeMillis() + timeout; while (System.currentTimeMillis() < realTimeout) { try (ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory(uri, null)) { cf.createConnection().close(); System.out.println("server " + uri + " started"); } catch (Exception e) { System.out.println("awaiting server " + uri + " start at "); Thread.sleep(500); continue; } break; } }
private boolean tryConsume() throws JMSException { try (ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(); Connection connection = factory.createConnection(); Session session = connection.createSession(Session.AUTO_ACKNOWLEDGE)) { Queue queue = session.createQueue("NewQueue"); MessageConsumer consumer = session.createConsumer(queue); return true; } catch (JMSException e) { return false; } }
@Test public void testTwoConnectionsSameIDThroughCF() throws Exception { ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616?clientID=myid"); conn = connectionFactory.createConnection(); try { conn2 = connectionFactory.createConnection(); Assert.fail("Exception expected"); } catch (InvalidClientIDException expected) { // expected } Session session1 = conn.createSession(); Session session2 = conn.createSession(); session1.close(); session2.close(); }
private void sendObjectMessage(String qname, Serializable obj) throws Exception { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://0"); Connection connection = factory.createConnection(); try { Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue q = session.createQueue(qname); MessageProducer producer = session.createProducer(q); ObjectMessage objMessage = session.createObjectMessage(); objMessage.setObject(obj); producer.send(objMessage); } finally { connection.close(); } }
public static ActiveMQConnection createConnectionAndWaitForTopology(ActiveMQConnectionFactory factory, int topologyMembers, int timeout) throws Exception { ActiveMQConnection conn; CountDownLatch countDownLatch = new CountDownLatch(topologyMembers); ServerLocator locator = factory.getServerLocator(); locator.addClusterTopologyListener(new FailoverTestBase.LatchClusterTopologyListener(countDownLatch)); conn = (ActiveMQConnection) factory.createConnection(); boolean ok = countDownLatch.await(timeout, TimeUnit.SECONDS); if (!ok) { throw new IllegalStateException("timed out waiting for topology"); } return conn; }
@Test public void testSetClientIdAfterGetExceptionListener() throws Exception { Connection conn = cf.createConnection(); conn.getExceptionListener(); conn.setClientID("clientId"); conn.close(); }
@Test public void testDefaultConstructorAndSetConnectorPairs() throws Exception { ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC); assertFactoryParams(cf, new TransportConfiguration[]{liveTC}, null, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS); Connection conn = cf.createConnection(); conn.createSession(false, Session.AUTO_ACKNOWLEDGE); testSettersThrowException(cf); conn.close(); }
@Test public void testStaticConnectorListConstructor() throws Exception { ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC); assertFactoryParams(cf, new TransportConfiguration[]{liveTC}, null, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS); Connection conn = cf.createConnection(); conn.createSession(false, Session.AUTO_ACKNOWLEDGE); testSettersThrowException(cf); conn.close(); }
@Test public void testStaticConnectorLiveConstructor() throws Exception { ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC); assertFactoryParams(cf, new TransportConfiguration[]{liveTC}, null, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS); Connection conn = cf.createConnection(); conn.createSession(false, Session.AUTO_ACKNOWLEDGE); testSettersThrowException(cf); cf.close(); conn.close(); }
@Test public void testNoReconnectCloseAfterFailToReconnectWithTempQueue() throws Exception { ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY)); jbcf.setReconnectAttempts(0); Connection conn = jbcf.createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); sess.createTemporaryQueue(); Thread.sleep(2000); this.server.stop(); this.server.start(); sess.close(); conn.close(); }
@Test public void testListenerCalledForOneConnection() throws Exception { Connection conn = cf.createConnection(); CountDownLatch latch = new CountDownLatch(1); MyExceptionListener listener = new MyExceptionListener(latch); conn.setExceptionListener(listener); ClientSessionInternal coreSession = (ClientSessionInternal) ((ActiveMQConnection) conn).getInitialSession(); coreSession.getConnection().fail(new ActiveMQInternalErrorException("blah")); latch.await(5, TimeUnit.SECONDS); Assert.assertEquals(1, listener.numCalls); conn.close(); }
@Test public void testCloseConnectionAfterServerIsShutdown() throws Exception { server.start(); jbcf = createConnectionFactory(); jbcf.setBlockOnDurableSend(true); jbcf.setBlockOnNonDurableSend(true); jbcf.setReconnectAttempts(-1); conn = jbcf.createConnection(); server.stop(); conn.close(); }
@Test public void testDiscoveryConstructor() throws Exception { DiscoveryGroupConfiguration groupConfiguration = new DiscoveryGroupConfiguration().setBroadcastEndpointFactory(new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress).setGroupPort(groupPort)); ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(groupConfiguration, JMSFactoryType.CF); assertFactoryParams(cf, null, groupConfiguration, null, ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, ActiveMQClient.DEFAULT_CONNECTION_TTL, ActiveMQClient.DEFAULT_CALL_TIMEOUT, ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT, ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE, ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE, ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE, ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE, ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE, ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE, ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND, ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND, ActiveMQClient.DEFAULT_AUTO_GROUP, ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE, ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE, ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT, ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS, ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE, ActiveMQClient.DEFAULT_RETRY_INTERVAL, ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS); Connection conn = cf.createConnection(); conn.createSession(false, Session.AUTO_ACKNOWLEDGE); testSettersThrowException(cf); conn.close(); }
private void testThroughNewConnectionFactory(ActiveMQConnectionFactory factory) throws Exception { Connection conn = factory.createConnection(); conn.close(); try (JMSContext ctx = factory.createContext()) { ctx.createProducer().send(ctx.createQueue("queue"), "Test"); } try (JMSContext ctx = factory.createContext()) { Assert.assertNotNull(ctx.createConsumer(ctx.createQueue("queue")).receiveNoWait()); Assert.assertNull(ctx.createConsumer(ctx.createQueue("queue")).receiveNoWait()); } factory.close(); }