org.apache.activemq.broker.TransportConnector Java Examples

The following examples show how to use org.apache.activemq.broker.TransportConnector. 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: JMSBroker.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Stopping ActiveMQ embedded broker
 *
 * @return true if broker is successfully stopped
 */
public boolean stop() {
    try {
        log.info(" ************* Stopping **************");
        if (broker.isStarted()) {
            broker.stop();
            for (TransportConnector transportConnector : transportConnectors) {
                transportConnector.stop();
            }
            setBrokerStatus(false);
        }
        return true;
    } catch (Exception e) {
        log.error("Error while shutting down the broker", e);
        return false;
    }
}
 
Example #2
Source File: ConnectorXBeanConfigTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void testConnectorConfiguredCorrectly() throws Exception {

      TransportConnector connector = brokerService.getTransportConnectors().get(0);

      assertEquals(new URI("tcp://localhost:61636"), connector.getUri());
      assertTrue(connector.getTaskRunnerFactory() == brokerService.getTaskRunnerFactory());

      NetworkConnector netConnector = brokerService.getNetworkConnectors().get(0);
      List<ActiveMQDestination> excludedDestinations = netConnector.getExcludedDestinations();
      assertEquals(new ActiveMQQueue("exclude.test.foo"), excludedDestinations.get(0));
      assertEquals(new ActiveMQTopic("exclude.test.bar"), excludedDestinations.get(1));

      List<ActiveMQDestination> dynamicallyIncludedDestinations = netConnector.getDynamicallyIncludedDestinations();
      assertEquals(new ActiveMQQueue("include.test.foo"), dynamicallyIncludedDestinations.get(0));
      assertEquals(new ActiveMQTopic("include.test.bar"), dynamicallyIncludedDestinations.get(1));
   }
 
Example #3
Source File: JmsMultipleBrokersTestSupport.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void bridgeAllBrokers(String groupName,
                                int ttl,
                                boolean suppressduplicateQueueSubs,
                                boolean decreasePriority) throws Exception {
   Collection<BrokerItem> brokerList = brokers.values();
   for (Iterator<BrokerItem> i = brokerList.iterator(); i.hasNext(); ) {
      BrokerService broker = i.next().broker;
      List<TransportConnector> transportConnectors = broker.getTransportConnectors();

      if (transportConnectors.isEmpty()) {
         broker.addConnector(new URI(AUTO_ASSIGN_TRANSPORT));
         transportConnectors = broker.getTransportConnectors();
      }

      TransportConnector transport = transportConnectors.get(0);
      transport.setDiscoveryUri(new URI("multicast://default?group=" + groupName));
      NetworkConnector nc = broker.addNetworkConnector("multicast://default?group=" + groupName);
      nc.setNetworkTTL(ttl);
      nc.setSuppressDuplicateQueueSubscriptions(suppressduplicateQueueSubs);
      nc.setDecreaseNetworkConsumerPriority(decreasePriority);
   }

   // Multicasting may take longer to setup
   maxSetupTime = 8000;
}
 
Example #4
Source File: QueueBrowsingTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Before
public void startBroker() throws Exception {
   broker = createBroker();
   TransportConnector connector = broker.addConnector("tcp://0.0.0.0:0");
   broker.deleteAllMessages();
   broker.start();
   broker.waitUntilStarted();

   PolicyEntry policy = new PolicyEntry();
   policy.setMaxPageSize(maxPageSize);
   broker.setDestinationPolicy(new PolicyMap());
   broker.getDestinationPolicy().setDefaultEntry(policy);

   connectUri = connector.getConnectUri();
   factory = new ActiveMQConnectionFactory(connectUri);
}
 
Example #5
Source File: ActiveMQConnectionFactoryTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void assertCreateConnection(String uri) throws Exception {
   // Start up a broker with a tcp connector.
   broker = new BrokerService();
   broker.setPersistent(false);
   broker.setUseJmx(false);
   TransportConnector connector = broker.addConnector(uri);
   broker.start();

   URI temp = new URI(uri);
   // URI connectURI = connector.getServer().getConnectURI();
   // TODO this sometimes fails when using the actual local host name
   URI currentURI = new URI(connector.getPublishableConnectString());

   // sometimes the actual host name doesn't work in this test case
   // e.g. on OS X so lets use the original details but just use the actual
   // port
   URI connectURI = new URI(temp.getScheme(), temp.getUserInfo(), temp.getHost(), currentURI.getPort(), temp.getPath(), temp.getQuery(), temp.getFragment());

   LOG.info("connection URI is: " + connectURI);

   // This should create the connection.
   ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(connectURI);
   connection = (ActiveMQConnection) cf.createConnection();
   assertNotNull(connection);
}
 
Example #6
Source File: MultiBrokersMultiClientsUsingTcpTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker) throws Exception {
   List<TransportConnector> remoteTransports = remoteBroker.getTransportConnectors();
   List<TransportConnector> localTransports = localBroker.getTransportConnectors();

   URI remoteURI;
   URI localURI;
   if (!remoteTransports.isEmpty() && !localTransports.isEmpty()) {
      remoteURI = remoteTransports.get(0).getConnectUri();
      localURI = localTransports.get(0).getConnectUri();

      // Ensure that we are connecting using tcp
      if (remoteURI.toString().startsWith("tcp:") && localURI.toString().startsWith("tcp:")) {
         NetworkBridgeConfiguration config = new NetworkBridgeConfiguration();
         config.setBrokerName(localBroker.getBrokerName());
         DemandForwardingBridge bridge = new DemandForwardingBridge(config, TransportFactory.connect(localURI), TransportFactory.connect(remoteURI));
         bridge.setBrokerService(localBroker);
         bridges.add(bridge);

         bridge.start();
      } else {
         throw new Exception("Remote broker or local broker is not using tcp connectors");
      }
   } else {
      throw new Exception("Remote broker or local broker has no registered connectors.");
   }
}
 
Example #7
Source File: TestBroker.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
public TestBroker build() throws Exception {
    if (this.connectors.isEmpty()) {
        this.connectors.add(DEFAULT_BROKER_URL);
    }
    BrokerService brokerService = new BrokerService();
    brokerService.setBrokerName(this.brokerName);
    brokerService.setPersistent(false);
    brokerService.setUseJmx(false);
    Map<String, ActiveMQConnectionFactory> connectionFactories = new HashMap<String, ActiveMQConnectionFactory>();
    for (String bindAddress : this.connectors) {
        TransportConnector connector = brokerService.addConnector(bindAddress);
        connectionFactories.put(bindAddress, new ActiveMQConnectionFactory(connector.getConnectUri()));
    }
    for (String discoveryAddress : this.networkConnectors) {
        brokerService.addNetworkConnector(discoveryAddress);
    }
    return new TestBroker(this.brokerName, brokerService, connectionFactories);
}
 
Example #8
Source File: ThreeBrokerStompTemporaryQueueTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected NetworkConnector bridgeBrokers(BrokerService localBroker,
                                         BrokerService remoteBroker,
                                         boolean dynamicOnly,
                                         int networkTTL,
                                         boolean conduit,
                                         boolean failover) throws Exception {
   List<TransportConnector> transportConnectors = remoteBroker.getTransportConnectors();
   URI remoteURI;
   if (!transportConnectors.isEmpty()) {
      remoteURI = transportConnectors.get(0).getConnectUri();
      NetworkConnector connector = new DiscoveryNetworkConnector(new URI("static:" + remoteURI));
      connector.setName(localBroker.getBrokerName() + remoteBroker.getBrokerName());
      localBroker.addNetworkConnector(connector);
      maxSetupTime = 2000;
      return connector;
   } else {
      throw new Exception("Remote broker has no registered connectors.");
   }
}
 
Example #9
Source File: QueueMasterSlaveSingleUrlTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void createSlave() throws Exception {
   new Thread(new Runnable() {
      @Override
      public void run() {
         try {
            BrokerService broker = new BrokerService();
            broker.setBrokerName("shared-slave");
            configureSharedPersistenceAdapter(broker);
            // add transport as a service so that it is bound on start, after store started
            final TransportConnector tConnector = new TransportConnector();
            tConnector.setUri(new URI(brokerUrl));
            broker.addConnector(tConnector);

            broker.start();
            slave.set(broker);
            slaveStarted.countDown();
         } catch (Exception e) {
            e.printStackTrace();
         }
      }

   }).start();
}
 
Example #10
Source File: JmsWSConnectionTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    brokerService = new BrokerService();
    brokerService.setPersistent(false);
    brokerService.setAdvisorySupport(false);
    brokerService.setDeleteAllMessagesOnStartup(true);
    brokerService.setUseJmx(false);

    TransportConnector connector = brokerService.addConnector(
            "ws://0.0.0.0:" + getProxyPort() + "?websocket.maxBinaryMessageSize=1048576");
    connectionURI = connector.getPublishableConnectURI();
    LOG.debug("Using amqp+ws connection: {}", connectionURI);

    brokerService.start();
    brokerService.waitUntilStarted();
}
 
Example #11
Source File: CheckDuplicateMessagesOnDuplexTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void createLocalBroker() throws Exception {
   localBroker = new BrokerService();
   localBroker.setBrokerName("LOCAL");
   localBroker.setUseJmx(true);
   localBroker.setSchedulePeriodForDestinationPurge(5000);
   ManagementContext managementContext = new ManagementContext();
   managementContext.setCreateConnector(false);
   localBroker.setManagementContext(managementContext);
   PersistenceAdapter persistenceAdapter = persistenceAdapterFactory("target/local");
   localBroker.setPersistenceAdapter(persistenceAdapter);
   List<TransportConnector> transportConnectors = new ArrayList<>();
   DebugTransportFactory tf = new DebugTransportFactory();
   TransportServer transport = tf.doBind(URI.create("nio://127.0.0.1:23539"));
   TransportConnector transportConnector = new TransportConnector(transport);
   transportConnector.setName("tc");
   transportConnector.setAuditNetworkProducers(true);
   transportConnectors.add(transportConnector);
   localBroker.setTransportConnectors(transportConnectors);
}
 
Example #12
Source File: NIOSSLLoadTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
   System.setProperty("javax.net.ssl.trustStore", TRUST_KEYSTORE);
   System.setProperty("javax.net.ssl.trustStorePassword", PASSWORD);
   System.setProperty("javax.net.ssl.trustStoreType", KEYSTORE_TYPE);
   System.setProperty("javax.net.ssl.keyStore", SERVER_KEYSTORE);
   System.setProperty("javax.net.ssl.keyStoreType", KEYSTORE_TYPE);
   System.setProperty("javax.net.ssl.keyStorePassword", PASSWORD);

   broker = new BrokerService();
   broker.setPersistent(false);
   broker.setUseJmx(false);
   TransportConnector connector = broker.addConnector("nio+ssl://localhost:0?transport.needClientAuth=true&transport.enabledCipherSuites=SSL_RSA_WITH_RC4_128_SHA,SSL_DH_anon_WITH_3DES_EDE_CBC_SHA");
   broker.start();
   broker.waitUntilStarted();

   ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("nio+ssl://localhost:" + connector.getConnectUri().getPort());
   connection = factory.createConnection();
   session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   connection.start();
}
 
Example #13
Source File: QueueBrowsingLimitTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Before
public void startBroker() throws Exception {
   broker = createBroker();
   TransportConnector connector = broker.addConnector("tcp://0.0.0.0:0");
   broker.deleteAllMessages();
   broker.start();
   broker.waitUntilStarted();

   PolicyEntry policy = new PolicyEntry();
   policy.setMaxBrowsePageSize(browserLimit);
   broker.setDestinationPolicy(new PolicyMap());
   broker.getDestinationPolicy().setDefaultEntry(policy);

   connectUri = connector.getConnectUri();
   factory = new ActiveMQConnectionFactory(connectUri);

}
 
Example #14
Source File: FailoverClusterTestSupport.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void addTransportConnector(BrokerService brokerService,
                                     String connectorName,
                                     String uri,
                                     boolean clustered) throws Exception {
   TransportConnector connector = brokerService.addConnector(uri);
   connector.setName(connectorName);
   if (clustered) {
      connector.setRebalanceClusterClients(true);
      connector.setUpdateClusterClients(true);
      connector.setUpdateClusterClientsOnRemove(true);
   } else {
      connector.setRebalanceClusterClients(false);
      connector.setUpdateClusterClients(false);
      connector.setUpdateClusterClientsOnRemove(false);
   }
}
 
Example #15
Source File: SslBrokerServiceTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void makeSSLConnection(SSLContext context,
                               String enabledSuites[],
                               TransportConnector connector) throws Exception, UnknownHostException, SocketException {
   SSLSocket sslSocket = (SSLSocket) context.getSocketFactory().createSocket("localhost", connector.getUri().getPort());

   if (enabledSuites != null) {
      sslSocket.setEnabledCipherSuites(enabledSuites);
   }
   sslSocket.setSoTimeout(5000);

   SSLSession session = sslSocket.getSession();
   sslSocket.startHandshake();
   LOG.info("cyphersuite: " + session.getCipherSuite());
   LOG.info("peer port: " + session.getPeerPort());
   LOG.info("peer cert: " + session.getPeerCertificateChain()[0].toString());
}
 
Example #16
Source File: JMSBroker.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Stopping ActiveMQ embedded broker
 *
 * @return true if broker is successfully stopped
 */
public boolean stop() {
    try {
        log.info(" ************* Stopping **************");
        if (broker.isStarted()) {
            broker.stop();
            for (TransportConnector transportConnector : transportConnectors) {
                transportConnector.stop();
            }
            setBrokerStatus(false);
        }
        return true;
    } catch (Exception e) {
        log.error("Error while shutting down the broker", e);
        return false;
    }
}
 
Example #17
Source File: MulticastDiscoveryOnFaultyNetworkTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected NetworkConnector bridgeBrokers(BrokerService localBroker,
                                         BrokerService remoteBroker,
                                         boolean dynamicOnly,
                                         int networkTTL,
                                         boolean conduit,
                                         boolean failover) throws Exception {
   String networkDisoveryUrlString = useStaticDiscovery ? "static:(" + remoteBroker.getTransportConnectors().get(0).getPublishableConnectString() + ")?useExponentialBackOff=false" : "multicast://default?group=TESTERIC&useLocalHost=false";

   DiscoveryNetworkConnector connector = new DiscoveryNetworkConnector(new URI(networkDisoveryUrlString));
   connector.setDynamicOnly(dynamicOnly);
   connector.setNetworkTTL(networkTTL);
   connector.setDuplex(useDuplexNetworkBridge);
   maxSetupTime = 2000;
   if (!useStaticDiscovery) {
      List<TransportConnector> transportConnectors = remoteBroker.getTransportConnectors();
      if (!transportConnectors.isEmpty()) {
         TransportConnector mCastTrpConnector = (transportConnectors.get(0));
         mCastTrpConnector.setDiscoveryUri(new URI("multicast://default?group=TESTERIC"));
      }
   }
   localBroker.addNetworkConnector(connector);
   return connector;
}
 
Example #18
Source File: ActiveMQAdmin.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Override
public void startServer() throws Exception {
    if (broker != null) {
        stopServer();
    }
    if (System.getProperty("basedir") == null) {
        File file = new File(".");
        System.setProperty("basedir", file.getAbsolutePath());
    }
    broker = createBroker();
    TransportConnector connector = broker.addConnector(getConnectorURI());
    broker.start();
    port = connector.getConnectUri().getPort();
}
 
Example #19
Source File: JmsWSSConnectionTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    brokerService = new BrokerService();
    brokerService.setPersistent(false);
    brokerService.setAdvisorySupport(false);
    brokerService.setDeleteAllMessagesOnStartup(true);
    brokerService.setUseJmx(false);

    // Setup broker SSL context...
    TransportOptions sslOptions = new TransportOptions();
    sslOptions.setKeyStoreLocation(KEYSTORE);
    sslOptions.setKeyStorePassword(PASSWORD);
    sslOptions.setVerifyHost(false);

    SSLContext sslContext = TransportSupport.createJdkSslContext(sslOptions);

    final SslContext brokerContext = new SslContext();
    brokerContext.setSSLContext(sslContext);

    brokerService.setSslContext(brokerContext);

    TransportConnector connector = brokerService.addConnector("wss://0.0.0.0:" + getProxyPort());
    connectionURI = connector.getPublishableConnectURI();
    LOG.debug("Using amqp+wss connection: {}", connectionURI);

    brokerService.start();
    brokerService.waitUntilStarted();

    connectionURI = connector.getPublishableConnectURI();
}
 
Example #20
Source File: OpenEjbBrokerFactoryTest.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void stopBroker(final BrokerService broker) throws Exception {
    if (broker == null) return;

    if (broker.getJmsBridgeConnectors() != null) {
        for (final JmsConnector connector : broker.getJmsBridgeConnectors()) {
            connector.stop();
        }
    }
    for (final Object o : broker.getTransportConnectors()) {
        final TransportConnector tc = (TransportConnector) o;
        tc.stop();

    }
    broker.stop();
}
 
Example #21
Source File: QpidJmsTestSupport.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
public BrokerService restartBroker(BrokerService brokerService) throws Exception {
    String name = brokerService.getBrokerName();
    Map<String, Integer> portMap = new HashMap<String, Integer>();
    for (TransportConnector connector : brokerService.getTransportConnectors()) {
        portMap.put(connector.getName(), connector.getPublishableConnectURI().getPort());
    }

    stopBroker(brokerService);
    BrokerService broker = createBroker(name, false, portMap);
    broker.start();
    broker.waitUntilStarted();
    return broker;
}
 
Example #22
Source File: AmqpTestSupport.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Override
protected void addAdditionalConnectors(BrokerService brokerService, Map<String, Integer> portMap) throws Exception {
    int port = PORT;
    if (portMap.containsKey("amqp")) {
        port = portMap.get("amqp");
    }
    TransportConnector connector = brokerService.addConnector(
        "amqp://127.0.0.1:" + port +
        "?transport.transformer=" + getAmqpTransformer() +
        "&transport.socketBufferSize=" + getSocketBufferSize() +
        "&transport.tcpNoDelay=true" +
        "&ioBufferSize=" + getIOBufferSize());
    connector.setName("amqp");
    if (isAmqpDiscovery()) {
        String uriString = "multicast://default";
        if(getDiscoveryNetworkInterface() != null) {
            uriString += "?networkInterface=" + getDiscoveryNetworkInterface();
        }
        connector.setDiscoveryUri(new URI(uriString));
    }
    port = connector.getPublishableConnectURI().getPort();
    LOG.debug("Using amqp port: {}", port);

    if (isAddOpenWireConnector()) {
        if (portMap.containsKey("openwire")) {
            port = portMap.get("openwire");
        } else {
            port = 0;
        }

        connector = brokerService.addConnector("tcp://0.0.0.0:" + port);
        connector.setName("openwire");

        LOG.debug("Using openwire port: {}", port);
    }
}
 
Example #23
Source File: BrokerQueueNetworkWithDisconnectTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected NetworkConnector bridgeBrokers(BrokerService localBroker,
                                         BrokerService remoteBroker,
                                         boolean dynamicOnly,
                                         int networkTTL,
                                         boolean conduit,
                                         boolean failover) throws Exception {
   List<TransportConnector> transportConnectors = remoteBroker.getTransportConnectors();
   URI remoteURI;
   if (!transportConnectors.isEmpty()) {
      remoteURI = transportConnectors.get(0).getConnectUri();
      if (useSocketProxy) {
         socketProxy = new SocketProxy(remoteURI);
         remoteURI = socketProxy.getUrl();
      }
      DiscoveryNetworkConnector connector = new DiscoveryNetworkConnector(new URI("static:(" + remoteURI + "?wireFormat.maxInactivityDuration=" + inactiveDuration + "&wireFormat.maxInactivityDurationInitalDelay=" + inactiveDuration + ")?useExponentialBackOff=false"));
      connector.setDynamicOnly(dynamicOnly);
      connector.setNetworkTTL(networkTTL);
      localBroker.addNetworkConnector(connector);
      maxSetupTime = 2000;
      if (useDuplexNetworkBridge) {
         connector.setDuplex(true);
      }
      return connector;
   } else {
      throw new Exception("Remote broker has no registered connectors.");
   }
}
 
Example #24
Source File: ThreeBrokerTopicNetworkUsingTcpTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void bridgeBrokers(BrokerService localBroker, BrokerService remoteBroker) throws Exception {
   List<TransportConnector> remoteTransports = remoteBroker.getTransportConnectors();
   List<TransportConnector> localTransports = localBroker.getTransportConnectors();

   URI remoteURI;
   URI localURI;
   if (!remoteTransports.isEmpty() && !localTransports.isEmpty()) {
      remoteURI = remoteTransports.get(0).getConnectUri();
      localURI = localTransports.get(0).getConnectUri();

      // Ensure that we are connecting using tcp
      if (remoteURI.toString().startsWith("tcp:") && localURI.toString().startsWith("tcp:")) {
         NetworkBridgeConfiguration config = new NetworkBridgeConfiguration();
         config.setBrokerName(localBroker.getBrokerName());
         DemandForwardingBridge bridge = new DemandForwardingBridge(config, TransportFactory.connect(localURI), TransportFactory.connect(remoteURI));
         bridge.setBrokerService(localBroker);
         bridges.add(bridge);

         bridge.start();
      } else {
         throw new Exception("Remote broker or local broker is not using tcp connectors");
      }
   } else {
      throw new Exception("Remote broker or local broker has no registered connectors.");
   }

   maxSetupTime = 2000;
}
 
Example #25
Source File: DurableSubscriberNonPersistentMessageTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
   super.setUp();
   broker = new BrokerService();
   TransportConnector transportConnector = broker.addConnector("tcp://localhost:0");
   KahaDBStore store = new KahaDBStore();
   store.setDirectory(new File("data"));
   broker.setPersistenceAdapter(store);
   broker.start();

   brokerURL = "failover:(" + transportConnector.getPublishableConnectString() + ")";
   consumerBrokerURL = brokerURL + "?jms.prefetchPolicy.all=100";

   mbeanServer = ManagementFactory.getPlatformMBeanServer();
}
 
Example #26
Source File: NetworkOfTwentyBrokersTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void bridgeAllBrokers(String groupName,
                                int ttl,
                                boolean suppressduplicateQueueSubs,
                                boolean decreasePriority) throws Exception {
   Collection<BrokerItem> brokerList = brokers.values();
   for (Iterator<BrokerItem> i = brokerList.iterator(); i.hasNext(); ) {
      BrokerService broker = i.next().broker;
      List<TransportConnector> transportConnectors = broker.getTransportConnectors();

      if (transportConnectors.isEmpty()) {
         broker.addConnector(new URI(AUTO_ASSIGN_TRANSPORT));
         transportConnectors = broker.getTransportConnectors();
      }

      TransportConnector transport = transportConnectors.get(0);
      if (transport.getDiscoveryUri() == null) {
         transport.setDiscoveryUri(new URI("multicast://default?group=" + groupName));
      }

      List<NetworkConnector> networkConnectors = broker.getNetworkConnectors();
      if (networkConnectors.isEmpty()) {
         broker.addNetworkConnector("multicast://default?group=" + groupName);
         networkConnectors = broker.getNetworkConnectors();
      }

      NetworkConnector nc = networkConnectors.get(0);
      nc.setNetworkTTL(ttl);
      nc.setSuppressDuplicateQueueSubscriptions(suppressduplicateQueueSubs);
      nc.setDecreaseNetworkConsumerPriority(decreasePriority);
   }

   // Multicasting may take longer to setup
   maxSetupTime = 8000;
}
 
Example #27
Source File: NIOSSLBasicTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public BrokerService createBroker(String connectorName, String connectorString) throws Exception {
   BrokerService broker = new BrokerService();
   broker.setPersistent(false);
   broker.setUseJmx(false);
   TransportConnector connector = broker.addConnector(connectorString);
   connector.setName(connectorName);
   broker.start();
   broker.waitUntilStarted();
   return broker;
}
 
Example #28
Source File: NIOSSLConcurrencyTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
   System.setProperty("javax.net.ssl.trustStore", TRUST_KEYSTORE);
   System.setProperty("javax.net.ssl.trustStorePassword", PASSWORD);
   System.setProperty("javax.net.ssl.trustStoreType", KEYSTORE_TYPE);
   System.setProperty("javax.net.ssl.keyStore", SERVER_KEYSTORE);
   System.setProperty("javax.net.ssl.keyStoreType", KEYSTORE_TYPE);
   System.setProperty("javax.net.ssl.keyStorePassword", PASSWORD);

   broker = new BrokerService();
   broker.setPersistent(false);
   broker.setUseJmx(false);
   TransportConnector connector = broker.addConnector("nio+ssl://localhost:0?transport.needClientAuth=true&transport.enabledCipherSuites=SSL_RSA_WITH_RC4_128_SHA,SSL_DH_anon_WITH_3DES_EDE_CBC_SHA");
   broker.start();
   broker.waitUntilStarted();

   failed = false;
   messageData = new byte[MESSAGE_SIZE];
   for (int i = 0; i < MESSAGE_SIZE; i++) {
      messageData[i] = (byte) (i & 0xff);
   }

   ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("nio+ssl://localhost:" + connector.getConnectUri().getPort());
   connection = factory.createConnection();

   for (int i = 0; i < PRODUCER_COUNT; i++) {
      producerSessions[i] = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   }

   for (int i = 0; i < CONSUMER_COUNT; i++) {
      consumerSessions[i] = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   }

   connection.start();
}
 
Example #29
Source File: NIOSSLWindowSizeTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
   System.setProperty("javax.net.ssl.trustStore", TRUST_KEYSTORE);
   System.setProperty("javax.net.ssl.trustStorePassword", PASSWORD);
   System.setProperty("javax.net.ssl.trustStoreType", KEYSTORE_TYPE);
   System.setProperty("javax.net.ssl.keyStore", SERVER_KEYSTORE);
   System.setProperty("javax.net.ssl.keyStoreType", KEYSTORE_TYPE);
   System.setProperty("javax.net.ssl.keyStorePassword", PASSWORD);

   broker = new BrokerService();
   broker.setPersistent(false);
   broker.setUseJmx(false);
   TransportConnector connector = broker.addConnector("nio+ssl://localhost:0?transport.needClientAuth=true");
   broker.start();
   broker.waitUntilStarted();

   messageData = new byte[MESSAGE_SIZE];
   for (int i = 0; i < MESSAGE_SIZE; i++) {
      messageData[i] = (byte) (i & 0xff);
   }

   ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("nio+ssl://localhost:" + connector.getConnectUri().getPort());
   connection = factory.createConnection();
   session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   connection.start();
}
 
Example #30
Source File: SslBrokerServiceTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected BrokerService createBroker() throws Exception {

   // http://java.sun.com/javase/javaseforbusiness/docs/TLSReadme.html
   // work around: javax.net.ssl.SSLHandshakeException: renegotiation is not allowed
   System.setProperty("sun.security.ssl.allowUnsafeRenegotiation", "true");

   SslBrokerService service = new SslBrokerService();
   service.setPersistent(false);

   String baseUri = getBindLocation();
   String uri0 = baseUri + "?" + TransportConstants.SSL_ENABLED_PROP_NAME + "=true&" + TransportConstants.KEYSTORE_PATH_PROP_NAME + "=" + SslTransportBrokerTest.SERVER_KEYSTORE + "&" + TransportConstants.KEYSTORE_PASSWORD_PROP_NAME + "=" + SslTransportBrokerTest.PASSWORD + "&" + TransportConstants.KEYSTORE_PROVIDER_PROP_NAME + "=" + SslTransportBrokerTest.KEYSTORE_TYPE;
   String uri1 = uri0 + "&" + TransportConstants.ENABLED_CIPHER_SUITES_PROP_NAME + "=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,SSL_DH_anon_WITH_3DES_EDE_CBC_SHA";
   String uri2 = uri0 + "&" + TransportConstants.NEED_CLIENT_AUTH_PROP_NAME + "=true&" + TransportConstants.TRUSTSTORE_PATH_PROP_NAME + "=" + SslTransportBrokerTest.TRUST_KEYSTORE + "&" + TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME + "=" + SslTransportBrokerTest.PASSWORD + "&" + TransportConstants.TRUSTSTORE_PROVIDER_PROP_NAME + "=" + SslTransportBrokerTest.KEYSTORE_TYPE;

   //broker side
   TransportConnector serverConnector0 = service.addConnector(new URI(uri0));
   connector = new FakeTransportConnector(new URI("ssl://localhost:" + serverConnector0.getUri().getPort()));
   TransportConnector serverConnector1 = service.addConnector(new URI(uri1));
   limitedCipherSuites = new FakeTransportConnector(new URI("ssl://localhost:" + serverConnector1.getUri().getPort() + "?transport.enabledCipherSuites=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,SSL_DH_anon_WITH_3DES_EDE_CBC_SHA"));
   TransportConnector serverConnector2 = service.addConnector(new URI(uri2));
   needClientAuthConnector = new FakeTransportConnector(new URI("ssl://localhost:" + serverConnector2.getUri().getPort() + "?transport.needClientAuth=true"));

   KeyManager[] km = getKeyManager();
   TrustManager[] tm = getTrustManager();

   // for client side
   SslTransportFactory sslFactory = new SslTransportFactory();
   SslContext ctx = new SslContext(km, tm, null);
   SslContext.setCurrentSslContext(ctx);
   TransportFactory.registerTransportFactory("ssl", sslFactory);

   return service;
}