Search in sources :

Example 21 with BrokerService

use of org.apache.activemq.broker.BrokerService in project tomee by apache.

the class ActiveMQ5Factory method newDefaultBroker.

// forking org.apache.activemq.broker.DefaultBrokerFactory.createBroker() to support network connector properties
private BrokerService newDefaultBroker(final URI uri) throws Exception {
    final URISupport.CompositeData compositeData = URISupport.parseComposite(uri);
    final Map<String, String> params = new HashMap<String, String>(compositeData.getParameters());
    final BrokerService brokerService = newPatchedBrokerService();
    IntrospectionSupport.setProperties(brokerService, params);
    if (!params.isEmpty()) {
        String msg = "There are " + params.size() + " Broker options that couldn't be set on the BrokerService." + " Check the options are spelled correctly." + " Unknown parameters=[" + params + "]." + " This BrokerService cannot be started.";
        throw new IllegalArgumentException(msg);
    }
    if (compositeData.getPath() != null) {
        brokerService.setBrokerName(compositeData.getPath());
    }
    for (final URI component : compositeData.getComponents()) {
        if ("network".equals(component.getScheme())) {
            brokerService.addNetworkConnector(component.getSchemeSpecificPart());
        } else if ("proxy".equals(component.getScheme())) {
            brokerService.addProxyConnector(component.getSchemeSpecificPart());
        } else {
            brokerService.addConnector(component);
        }
    }
    return brokerService;
}
Also used : HashMap(java.util.HashMap) URISupport(org.apache.activemq.util.URISupport) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI)

Example 22 with BrokerService

use of org.apache.activemq.broker.BrokerService in project tomee by apache.

the class ActiveMQResourceAdapter method stopImpl.

private void stopImpl() throws Exception {
    super.stop();
    final Collection<BrokerService> brokers = ActiveMQFactory.getBrokers();
    final Iterator<BrokerService> it = brokers.iterator();
    while (it.hasNext()) {
        final BrokerService bs = it.next();
        try {
            bs.stop();
            bs.waitUntilStopped();
        } catch (final Throwable t) {
        //Ignore
        }
        it.remove();
    }
    stopScheduler();
    Logger.getInstance(LogCategory.OPENEJB_STARTUP, ActiveMQResourceAdapter.class).getChildLogger("service").info("Stopped ActiveMQ broker");
}
Also used : BrokerService(org.apache.activemq.broker.BrokerService)

Example 23 with BrokerService

use of org.apache.activemq.broker.BrokerService in project tomee by apache.

the class BrokerServer method init.

@Override
public void init(final Properties properties) throws Exception {
    final String port = properties.getProperty("port", "1527");
    final String bind = properties.getProperty("bind");
    final String disabled = properties.getProperty("disabled");
    this.port = Integer.parseInt(port);
    this.disabled = Boolean.parseBoolean(disabled);
    host = InetAddress.getByName(bind);
    if (this.disabled) {
        return;
    }
    final URI uri = new URI("tcp", null, bind, this.port, null, null, null);
    broker = new BrokerService();
    broker.setPersistent(false);
    broker.addConnector(uri);
}
Also used : URI(java.net.URI) BrokerService(org.apache.activemq.broker.BrokerService)

Example 24 with BrokerService

use of org.apache.activemq.broker.BrokerService in project camel by apache.

the class StompBaseTest method setUp.

@Override
public void setUp() throws Exception {
    port = AvailablePortFinder.getNextAvailable(61613);
    try {
        brokerService = new BrokerService();
        brokerService.setPersistent(false);
        brokerService.setAdvisorySupport(false);
        if (isUseSsl()) {
            SslContext sslContext = new SslContext();
            sslContext.setSSLContext(getServerSSLContext());
            brokerService.setSslContext(sslContext);
            brokerService.addConnector("stomp+ssl://localhost:" + getPort() + "?trace=true");
        } else {
            brokerService.addConnector("stomp://localhost:" + getPort() + "?trace=true");
        }
        brokerService.start();
        brokerService.waitUntilStarted();
        super.setUp();
        canTest = true;
    } catch (Exception e) {
        System.err.println("Cannot test due " + e.getMessage() + " more details in the log");
        log.warn("Cannot test due " + e.getMessage(), e);
        canTest = false;
    }
}
Also used : BrokerService(org.apache.activemq.broker.BrokerService) SslContext(org.apache.activemq.broker.SslContext)

Example 25 with BrokerService

use of org.apache.activemq.broker.BrokerService in project storm by apache.

the class MqttBrokerPublisher method startBroker.

public static void startBroker() throws Exception {
    LOG.info("Starting broker...");
    broker = new BrokerService();
    broker.addConnector("mqtt://localhost:1883");
    broker.setDataDirectory("target");
    broker.start();
    LOG.info("MQTT broker started");
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            try {
                LOG.info("Shutting down MQTT broker...");
                broker.stop();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : BrokerService(org.apache.activemq.broker.BrokerService)

Aggregations

BrokerService (org.apache.activemq.broker.BrokerService)40 Test (org.junit.Test)13 URI (java.net.URI)10 ServletContext (javax.servlet.ServletContext)7 ServletContextEvent (javax.servlet.ServletContextEvent)7 MemoryPersistenceAdapter (org.apache.activemq.store.memory.MemoryPersistenceAdapter)5 Before (org.junit.Before)5 PersistenceAdapter (org.apache.activemq.store.PersistenceAdapter)4 JDBCPersistenceAdapter (org.apache.activemq.store.jdbc.JDBCPersistenceAdapter)4 Properties (java.util.Properties)3 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)3 ServerSocket (java.net.ServerSocket)2 HashMap (java.util.HashMap)2 BrokerPlugin (org.apache.activemq.broker.BrokerPlugin)2 PolicyEntry (org.apache.activemq.broker.region.policy.PolicyEntry)2 PolicyMap (org.apache.activemq.broker.region.policy.PolicyMap)2 SystemUsage (org.apache.activemq.usage.SystemUsage)2 URISupport (org.apache.activemq.util.URISupport)2 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)2 JDBCDataSource (org.hsqldb.jdbc.JDBCDataSource)2