/** * Initializes {@code broker} and starts it. * @throws Exception if an exception during adding a connector occurs */ 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(); } } }); }
public static void main(String[]args) throws Exception { BrokerService brokerService = new BrokerService(); brokerService.addConnector( "tcp://0.0.0.0:61616?trace=" + TRANSPORT_TRACE + "&transport.wireFormat.maxFrameSize=104857600"); brokerService.setPersistent(false); brokerService.setUseJmx(false); brokerService.setAdvisorySupport(false); brokerService.start(); brokerService.waitUntilStopped(); } }
@Override protected void setUp() throws Exception { brokerService = new BrokerService(); pa = createPersistenceAdapter(true); brokerService.setPersistenceAdapter(pa); brokerService.start(); }
@Override protected void setUp() throws Exception { broker = createBroker(); broker.start(); broker.waitUntilStarted(); resourceProvider = getJmsResourceProvider(); topic = resourceProvider.isTopic(); // We will be using transacted sessions. setSessionTransacted(); connectionFactory = newConnectionFactory(); reconnect(); }
@Before public void setUp() throws Exception { brokerService = new BrokerService(); brokerService.setPersistent(false); brokerService.start(); factory = new ActiveMQConnectionFactory(BrokerRegistry.getInstance().findFirst().getVmConnectorURI()); producerConnection = factory.createConnection(); producerConnection.start(); producerSession = producerConnection.createSession(false,Session.AUTO_ACKNOWLEDGE); queue = producerSession.createQueue(getClass().getName()); producer = producerSession.createProducer(queue); }
public synchronized void init() throws ServletException { // lets initialize the ActiveMQ broker try { if (broker == null) { broker = createBroker(); // Add the servlet connector String url = getConnectorURL(); HttpTransportFactory factory = new HttpTransportFactory(); transportConnector = (HttpTransportServer) factory.doBind(new URI(url)); broker.addConnector(transportConnector); String brokerURL = getServletContext().getInitParameter("org.apache.activemq.brokerURL"); if (brokerURL != null) { log("Listening for internal communication on: " + brokerURL); } } broker.start(); } catch (Exception e) { throw new ServletException("Failed to start embedded broker: " + e, e); } // now lets register the listener TransportAcceptListener listener = transportConnector.getAcceptListener(); getServletContext().setAttribute("transportChannelListener", listener); super.init(); }
BrokerService broker = new BrokerService(); // configure the broker broker.setBrokerName("localhost"); broker.setUseJmx(false); broker.start();
@Override public void start(ILifecycleProgressMonitor monitor) throws SiteWhereException { try { getBrokerService().setBrokerName(getBrokerName()); TransportConnector connector = new TransportConnector(); connector.setUri(new URI(getTransportUri())); getBrokerService().addConnector(connector); getBrokerService().setUseShutdownHook(false); getBrokerService().setUseJmx(false); getBrokerService().start(); startConsumers(); } catch (Exception e) { throw new SiteWhereException("Error starting ActiveMQ inbound event receiver.", e); } }
@Override public void before() throws Exception { m_temporaryDirectory = Files.createTempDirectory("activemq-data"); m_broker.setPersistent(false); m_broker.setDataDirectory(m_temporaryDirectory.toString()); m_broker.start(); if (!m_broker.waitUntilStarted()) { throw new Exception("ActiveMQ broker was not started or stopped unexpectedly. Error: " + m_broker.getStartException()); } }
@BeforeAll public static void initialize() throws Exception { BROKER.setPersistent(false); BROKER.start(); }
private void startActiveMqBroker() throws Exception { this.activeMQBroker = new BrokerService(); this.activeMQBroker.addConnector("stomp://localhost:" + this.port); this.activeMQBroker.setStartAsync(false); this.activeMQBroker.setPersistent(false); this.activeMQBroker.setUseJmx(false); this.activeMQBroker.getSystemUsage().getMemoryUsage().setLimit(1024 * 1024 * 5); this.activeMQBroker.getSystemUsage().getTempUsage().setLimit(1024 * 1024 * 5); this.activeMQBroker.start(); }
@Before public void setUp() throws Exception { this.brokerService = new BrokerService(); this.brokerService.addConnector(this.brokerUrl); this.brokerService.setDataDirectory(BROKER_DATA_DIRECTORY); this.brokerService.start(); this.workerApplicationContext = new AnnotationConfigApplicationContext(WorkerConfiguration.class); }
@Given("^Start Broker$") public void start() { if (NO_EMBEDDED_SERVERS) { return; } logger.info("Starting new Broker instance"); try { // test if port is already open if (Ports.isPortOpen(1883)) { throw new IllegalStateException("Broker port is already in use"); } // start the broker System.setProperty(KAHA_DB_DIRECTORY, DEFAULT_KAHA_DB_DIRECTORY); broker = BrokerFactory.createBroker(ACTIVEMQ_XML); broker.setDataDirectory(DEFAULT_DATA_DIRECTORY); logger.info("Setting ActiveMQ data directory to {}", broker.getBrokerDataDirectory()); broker.start(); // wait for the broker if (!broker.waitUntilStarted(Duration.ofSeconds(20).toMillis())) { throw new IllegalStateException("Failed to start up broker in time"); } if (EXTRA_STARTUP_DELAY > 0) { Thread.sleep(Duration.ofSeconds(EXTRA_STARTUP_DELAY).toMillis()); } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException("Failed to start broker", e); } }
@Override protected void setUp() throws Exception { brokerService = new BrokerService(); brokerService.setPersistent(false); brokerService.start(); factory = new ActiveMQConnectionFactory(BrokerRegistry.getInstance().findFirst().getVmConnectorURI()); consumerConnection = factory.createConnection(); consumerConnection.start(); producerConnection = factory.createConnection(); producerConnection.start(); consumerSession = consumerConnection.createSession(false,Session.AUTO_ACKNOWLEDGE); topic = consumerSession.createTopic(getName()); producerSession = producerConnection.createSession(false,Session.AUTO_ACKNOWLEDGE); consumer = consumerSession.createConsumer(topic); producer = producerSession.createProducer(topic); }
brokerService = new BrokerService(); if (brokerName != null) { brokerService.setBrokerName(brokerName); persistenceFactory.setDataSource((DataSource) dataSource.$getResource()); brokerService.start();
public synchronized void init() throws ServletException { // lets initialize the ActiveMQ broker try { if (broker == null) { broker = createBroker(); // Add the servlet connector String url = getConnectorURL(); HttpTransportFactory factory = new HttpTransportFactory(); transportConnector = (HttpTransportServer) factory.doBind(new URI(url)); broker.addConnector(transportConnector); String brokerURL = getServletContext().getInitParameter("org.apache.activemq.brokerURL"); if (brokerURL != null) { log("Listening for internal communication on: " + brokerURL); } } broker.start(); } catch (Exception e) { throw new ServletException("Failed to start embedded broker: " + e, e); } // now lets register the listener TransportAcceptListener listener = transportConnector.getAcceptListener(); getServletContext().setAttribute("transportChannelListener", listener); super.init(); }
TransportConnector connector = new TransportConnector(); connector.setUri(new URI(getTransportUri())); brokerService.addConnector(connector); brokerService.setDataDirectory(getDataDirectory()); brokerService.setUseShutdownHook(false); brokerService.setUseJmx(false); brokerService.start(); startConsumers(); } catch (Exception e) {
@Override public void before() throws Exception { m_temporaryDirectory = Files.createTempDirectory("activemq-data"); m_broker.setPersistent(false); m_broker.setDataDirectory(m_temporaryDirectory.toString()); m_broker.start(); if (!m_broker.waitUntilStarted()) { throw new Exception("ActiveMQ broker was not started or stopped unexpectedly. Error: " + m_broker.getStartException()); } }
@BeforeAll public void setUp() throws Exception { BROKER.setPersistent(false); BROKER.start(); APP.before(); CLIENT = new JerseyClientBuilder(APP.getEnvironment()).build("test client"); CLIENT.property(CONNECT_TIMEOUT, 10000); CLIENT.property(READ_TIMEOUT, 12000); setDefaultPollInterval(100L, MILLISECONDS); }
@Before public void setUp() throws Exception { brokerService = new BrokerService(); brokerService.setAdvisorySupport(true); brokerService.setPersistent(false); brokerService.setUseJmx(false); brokerService.start(); }