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 ActiveMQConnectionFactory createConnectionFactory() throws Exception { Map<String, Object> params = new HashMap<>(); params.put(org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, "1"); final ActiveMQConnectionFactory activeMQConnectionFactory; if (configuration.getUrl() != null) { activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactory(configuration.getUrl(), null); } else { if (configuration.getHost() != null) { params.put(TransportConstants.HOST_PROP_NAME, configuration.getHost()); params.put(TransportConstants.PORT_PROP_NAME, configuration.getPort()); } if (configuration.isHa()) { activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, new TransportConfiguration(configuration.getConnectorFactory(), params)); } else { activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(configuration.getConnectorFactory(), params)); } } if (configuration.hasAuthentication()) { activeMQConnectionFactory.setUser(configuration.getUsername()); activeMQConnectionFactory.setPassword(configuration.getPassword()); } // The CF will probably be GCed since it was injected, so we disable the finalize check return activeMQConnectionFactory.disableFinalizeChecks(); } }
private ActiveMQConnectionFactory createConnectionFactory() throws Exception { Map<String, Object> params = new HashMap<>(); params.put(org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, "1"); final ActiveMQConnectionFactory activeMQConnectionFactory; if (configuration.getUrl() != null) { activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactory(configuration.getUrl(), null); } else { if (configuration.getHost() != null) { params.put(TransportConstants.HOST_PROP_NAME, configuration.getHost()); params.put(TransportConstants.PORT_PROP_NAME, configuration.getPort()); } if (configuration.isHa()) { activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, new TransportConfiguration(configuration.getConnectorFactory(), params)); } else { activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(configuration.getConnectorFactory(), params)); } } if (configuration.hasAuthentication()) { activeMQConnectionFactory.setUser(configuration.getUsername()); activeMQConnectionFactory.setPassword(configuration.getPassword()); } // The CF will probably be GCed since it was injected, so we disable the finalize check return activeMQConnectionFactory.disableFinalizeChecks(); } }
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; } }
break; case ArtemisCore: cf = ActiveMQJMSClient.createConnectionFactory(url, ""); break;
@Override @Before public void setUp() throws Exception { try { super.setUp(); CTSMiscellaneousTest.cf = ActiveMQJMSClient.createConnectionFactory("tcp://127.0.0.1:61616?blockOnAcknowledge=true&blockOnDurableSend=true&blockOnNonDurableSend=true", "StrictTCKConnectionFactory"); } catch (Exception e) { e.printStackTrace(); } }
protected void setupCF() throws Exception { if (spec.getConnectionFactoryLookup() != null) { Context ctx; if (spec.getParsedJndiParams() == null) { ctx = new InitialContext(); } else { ctx = new InitialContext(spec.getParsedJndiParams()); } Object fac = ctx.lookup(spec.getConnectionFactoryLookup()); if (fac instanceof ActiveMQConnectionFactory) { // This will clone the connection factory // to make sure we won't close anyone's connection factory when we stop the MDB factory = ActiveMQJMSClient.createConnectionFactory(((ActiveMQConnectionFactory) fac).toURI().toString(), "internalConnection"); factory.setEnableSharedClientID(true); factory.setEnable1xPrefixes(((ActiveMQConnectionFactory) fac).isEnable1xPrefixes()); } else { factory = ra.newConnectionFactory(spec); } } else { factory = ra.newConnectionFactory(spec); } }
protected void setupCF() throws Exception { if (spec.getConnectionFactoryLookup() != null) { Context ctx; if (spec.getParsedJndiParams() == null) { ctx = new InitialContext(); } else { ctx = new InitialContext(spec.getParsedJndiParams()); } Object fac = ctx.lookup(spec.getConnectionFactoryLookup()); if (fac instanceof ActiveMQConnectionFactory) { // This will clone the connection factory // to make sure we won't close anyone's connection factory when we stop the MDB factory = ActiveMQJMSClient.createConnectionFactory(((ActiveMQConnectionFactory) fac).toURI().toString(), "internalConnection"); factory.setEnableSharedClientID(true); factory.setEnable1xPrefixes(((ActiveMQConnectionFactory) fac).isEnable1xPrefixes()); } else { factory = ra.newConnectionFactory(spec); } } else { factory = ra.newConnectionFactory(spec); } }
private void createCamelContext() throws Exception { CamelContext camelContext = getContext(); ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactory( "(tcp://0.0.0.0:5672,tcp://0.0.0.0:61617)?ha=true;sslEnabled=true;enabledCipherSuites=TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,TLS_DHE_RSA_WITH_AES_128_CBC_SHA256,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256;enabledProtocols=TLSv1.1,TLSv1.2", "name"); factory.setRetryInterval(1000); factory.setRetryIntervalMultiplier(1.0); factory.setReconnectAttempts(-1); Sjms2Component sjms2 = new Sjms2Component(); ConnectionFactoryResource connectionResource = new ConnectionFactoryResource(1, factory, "admin", "admin"); sjms2.setConnectionResource(connectionResource); camelContext.addComponent("sjms2", sjms2); }
@Override @Before public void setUp() throws Exception { super.setUp(); executor = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory()); server = createServer(createBasicConfig() .setPersistenceEnabled(false) .setAddressesSettings(Collections.singletonMap("#", new AddressSettings() .setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE) .setPageSizeBytes(50000) .setMaxSizeBytes(404850))) .setAcceptorConfigurations(Collections.singleton(new TransportConfiguration(NettyAcceptorFactory.class.getName())))); server.start(); cf = ActiveMQJMSClient.createConnectionFactory("tcp://127.0.0.1:61616", "cf"); queue = ActiveMQJMSClient.createQueue("simple"); barrierLatch = new CyclicBarrier(PRODUCERS + 1); runnersLatch = new CountDownLatch(PRODUCERS + 1); msgReceived = new AtomicLong(0); msgSent = new AtomicLong(0); }
/** * Ensure no blocking calls in acknowledge flow when block on acknowledge = false. * This is done by checking the performance compared to blocking is much improved. */ @Test public void testNonBlockingAckPerf() throws Exception { ConnectionFactory cf1 = ActiveMQJMSClient.createConnectionFactory("tcp://127.0.0.1:61616?blockOnNonDurableSend=true&blockOnAcknowledge=false", "testsuitecf1"); ConnectionFactory cf2 = ActiveMQJMSClient.createConnectionFactory("tcp://127.0.0.1:61616?blockOnNonDurableSend=true&blockOnAcknowledge=true", "testsuitecf2"); int messageCount = 100; long sendT1 = send(cf1, queue1, messageCount); long sendT2 = send(cf2, queue2, messageCount); long time1 = consume(cf1, queue1, messageCount); long time2 = consume(cf2, queue2, messageCount); log.info("BlockOnAcknowledge=false MessageCount=" + messageCount + " TimeToConsume=" + time1); log.info("BlockOnAcknowledge=true MessageCount=" + messageCount + " TimeToConsume=" + time2); Assert.assertTrue(time1 < (time2 / 2)); }
@Test public void testLargeJmsTextMessage() throws Exception { basicSetUp(); ConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory("vm://0", "test"); Connection c = cf.createConnection(); Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
public void _testFlood() throws Exception { ConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory("tcp://127.0.0.1:61616?retryInterval=1000&retryIntervalMultiplier=1.0&reconnectAttempts=-1&callTimeout=30000&clientFailureCheckPeriod=1000&maxRetryInterval=1000&blockOnDurableSend=false&blockOnAcknowledge=false", "cf"); final int numProducers = 20; final int numConsumers = 20; final int numMessages = 10000; ProducerThread[] producers = new ProducerThread[numProducers]; for (int i = 0; i < numProducers; i++) { producers[i] = new ProducerThread(cf, numMessages); } ConsumerThread[] consumers = new ConsumerThread[numConsumers]; for (int i = 0; i < numConsumers; i++) { consumers[i] = new ConsumerThread(cf, numMessages); } for (int i = 0; i < numConsumers; i++) { consumers[i].start(); } for (int i = 0; i < numProducers; i++) { producers[i].start(); } for (int i = 0; i < numConsumers; i++) { consumers[i].join(); } for (int i = 0; i < numProducers; i++) { producers[i].join(); } }
@Test public void testListAllSessionsAsJSONWithJMS() throws Exception { SimpleString queueName = new SimpleString(UUID.randomUUID().toString()); server.addAddressInfo(new AddressInfo(queueName, RoutingType.ANYCAST)); server.createQueue(queueName, RoutingType.ANYCAST, queueName, null, false, false); ActiveMQServerControl serverControl = createManagementControl(); ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory("vm://0", "cf"); Connection con = cf.createConnection(); String clientID = UUID.randomUUID().toString(); con.setClientID(clientID); String jsonString = serverControl.listAllSessionsAsJSON(); IntegrationTestLogger.LOGGER.info(jsonString); Assert.assertNotNull(jsonString); JsonArray array = JsonUtil.readJsonArray(jsonString); Assert.assertEquals(1 + (usingCore() ? 1 : 0), array.size()); JsonObject obj = lookupSession(array, ((ActiveMQConnection)con).getInitialSession()); Assert.assertEquals(obj.getJsonObject("metadata").getJsonString(ActiveMQConnection.JMS_SESSION_CLIENT_ID_PROPERTY).getString(), clientID); Assert.assertNotNull(obj.getJsonObject("metadata").getJsonString(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY)); }
@Test public void testParseURIs() throws Throwable { ActiveMQConnectionFactory factory = ActiveMQJMSClient.createConnectionFactory("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false", "some name"); Assert.assertEquals(2, ((ServerLocatorImpl) factory.getServerLocator()).getInitialConnectors().length); ActiveMQConnectionFactory factory2 = new ActiveMQConnectionFactory("(tcp://localhost:61614,tcp://localhost:61616)?blockOnDurableSend=false"); Assert.assertEquals(2, ((ServerLocatorImpl) factory2.getServerLocator()).getInitialConnectors().length); ServerLocator locator = ServerLocatorImpl.newLocator("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false"); Assert.assertEquals(2, ((ServerLocatorImpl) locator).getInitialConnectors().length); ServerLocator locator2 = ActiveMQClient.createServerLocator("(tcp://localhost:61616,tcp://localhost:61617)?blockOnDurableSend=false"); Assert.assertEquals(2, ((ServerLocatorImpl) locator2).getInitialConnectors().length); }
server.start(); coreCf = ActiveMQJMSClient.createConnectionFactory("vm://0?reconnectAttempts=-1","cf"); System.out.println("debug: server started");