Search in sources :

Example 31 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project vcell by virtualcell.

the class ActiveMqTest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        BrokerService broker = new BrokerService();
        broker.setBrokerName("fred");
        broker.setUseShutdownHook(false);
        broker.setPersistent(false);
        // Add plugin
        // broker.setPlugins(new BrokerPlugin[]{new JaasAuthenticationPlugin()});
        // Add a network connection
        NetworkConnector connector = broker.addNetworkConnector("static://" + "tcp://localhost:61616");
        connector.setDuplex(true);
        TransportConnector transportConnector = broker.addConnector("tcp://localhost:61616");
        broker.start();
        // transportConnector.
        ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) TransportConnector(org.apache.activemq.broker.TransportConnector) NetworkConnector(org.apache.activemq.network.NetworkConnector) BrokerService(org.apache.activemq.broker.BrokerService)

Example 32 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class JmsMultipleBrokersTestSupport method bridgeAllBrokers.

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;
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) NetworkConnector(org.apache.activemq.network.NetworkConnector) DiscoveryNetworkConnector(org.apache.activemq.network.DiscoveryNetworkConnector) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI)

Example 33 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class FailoverStaticNetworkTest method createBroker.

protected BrokerService createBroker(String scheme, String listenPort, String[] networkToPorts, HashMap<String, String> networkProps) throws Exception {
    BrokerService broker = new BrokerService();
    broker.getManagementContext().setCreateConnector(false);
    broker.setSslContext(sslContext);
    broker.setDeleteAllMessagesOnStartup(true);
    broker.setBrokerName("Broker_" + listenPort);
    // lazy init listener on broker start
    TransportConnector transportConnector = new TransportConnector();
    transportConnector.setUri(new URI(scheme + "://localhost:" + listenPort));
    List<TransportConnector> transportConnectors = new ArrayList<>();
    transportConnectors.add(transportConnector);
    broker.setTransportConnectors(transportConnectors);
    if (networkToPorts != null && networkToPorts.length > 0) {
        StringBuilder builder = new StringBuilder("static:(failover:(" + scheme + "://localhost:");
        builder.append(networkToPorts[0]);
        for (int i = 1; i < networkToPorts.length; i++) {
            builder.append("," + scheme + "://localhost:" + networkToPorts[i]);
        }
        // limit the reconnects in case of initial random connection to slave
        // leaving randomize on verifies that this config is picked up
        builder.append(")?maxReconnectAttempts=0)?useExponentialBackOff=false");
        NetworkConnector nc = broker.addNetworkConnector(builder.toString());
        if (networkProps != null) {
            IntrospectionSupport.setProperties(nc, networkProps);
        }
    }
    return broker;
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) ArrayList(java.util.ArrayList) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI)

Example 34 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class FailoverStaticNetworkTest method createBroker.

private BrokerService createBroker(String listenPort, String dataDir) throws Exception {
    BrokerService broker = new BrokerService();
    broker.setUseJmx(false);
    broker.getManagementContext().setCreateConnector(false);
    broker.setBrokerName("Broker_Shared");
    // lazy create transport connector on start completion
    TransportConnector connector = new TransportConnector();
    connector.setUri(new URI("tcp://localhost:" + listenPort));
    broker.addConnector(connector);
    broker.setDataDirectory(dataDir);
    return broker;
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI)

Example 35 with TransportConnector

use of org.apache.activemq.broker.TransportConnector in project activemq-artemis by apache.

the class MQTTNetworkOfBrokersFailoverTest method createBroker.

@Override
protected BrokerService createBroker() throws Exception {
    BrokerService broker = super.createBroker();
    broker.setPersistent(true);
    broker.setBrokerName("local");
    broker.setDataDirectory("target/activemq-data");
    broker.setDeleteAllMessagesOnStartup(true);
    TransportConnector tc = broker.addConnector(getDefaultMQTTTransportConnectorUri());
    localBrokerMQTTPort = tc.getConnectUri().getPort();
    return broker;
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) BrokerService(org.apache.activemq.broker.BrokerService)

Aggregations

TransportConnector (org.apache.activemq.broker.TransportConnector)59 URI (java.net.URI)31 BrokerService (org.apache.activemq.broker.BrokerService)31 NetworkConnector (org.apache.activemq.network.NetworkConnector)10 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)9 DiscoveryNetworkConnector (org.apache.activemq.network.DiscoveryNetworkConnector)7 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Connection (javax.jms.Connection)4 PolicyEntry (org.apache.activemq.broker.region.policy.PolicyEntry)4 PolicyMap (org.apache.activemq.broker.region.policy.PolicyMap)4 JMSException (javax.jms.JMSException)3 Session (javax.jms.Session)3 File (java.io.File)2 Principal (java.security.Principal)2 MessageProducer (javax.jms.MessageProducer)2 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)2 ConnectionContext (org.apache.activemq.broker.ConnectionContext)2 Connector (org.apache.activemq.broker.Connector)2 StubConnection (org.apache.activemq.broker.StubConnection)2