@Before public void startBroker() throws Exception { broker = new BrokerService(); broker.setPersistent(false); TransportConnector connector = broker.addConnector(new TransportConnector()); connector.setUri(new URI("tcp://0.0.0.0:0")); connector.setName("tcp"); broker.start(); broker.waitUntilStarted(); brokerConnectURI = broker.getConnectorByName("tcp").getConnectUri(); }
@Before public void setUp() throws Exception { brokerService = new BrokerService(); brokerService.setPersistent(false); brokerService.setUseJmx(true); String connectionUri = brokerService.addConnector("tcp://localhost:0").getPublishableConnectString(); brokerService.start(); brokerService.waitUntilStarted(); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(connectionUri); final Connection conn = connectionFactory.createConnection(); try { conn.start(); final Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); final Destination queue = session.createQueue(testQueueName); final Message toSend = session.createMessage(); toSend.setStringProperty("foo", "bar"); final MessageProducer producer = session.createProducer(queue); producer.send(queue, toSend); } finally { conn.close(); } }
/** * Adds a new transport connector for the given bind address * * @return the newly created and added transport connector * @throws Exception */ public TransportConnector addConnector(URI bindAddress) throws Exception { return addConnector(createTransportConnector(bindAddress)); }
/** * * @throws Exception * @org. apache.xbean.InitMethod */ public void autoStart() throws Exception { if(shouldAutostart()) { start(); } }
protected void stopBroker() { // we can no longer keep the lock so lets fail LOG.error("{}, no longer able to keep the exclusive lock so giving up being a master", brokerService.getBrokerName()); try { if( brokerService.isRestartAllowed() ) { brokerService.requestRestart(); } brokerService.stop(); } catch (Exception e) { LOG.warn("Failure occurred while stopping broker"); } }
server = createBroker(config, properties); for (TransportConnector t : server.getBroker().getTransportConnectors()) { String portKey = t.getName() + "-port"; if (properties.containsKey(portKey)) { URI template = t.getUri(); t.setUri(new URI(template.getScheme(), template.getUserInfo(), template.getHost(), Integer.valueOf("" + properties.get(portKey)), template.getPath(), template.getQuery(), template.getFragment())); server.getBroker().start(); info("Broker %s has started.", name); server.getBroker().waitUntilStarted(); server.getBroker().addShutdownHook(new Runnable() { @Override public void run() {
@Override public BrokerService createBroker(URI brokerURI) throws Exception { BrokerService service = new BrokerService(); IntrospectionSupport.setProperties(service, brokerOptions); service.setBrokerName(finalBroker); TransportConnector c = service.addConnector("tcp://0.0.0.0:0"); c.setDiscoveryUri(new URI("multicast://default?group=" + finalGroup)); service.addNetworkConnector("multicast://default?group=" + finalGroup); return service; } });
int waitForStart = -1; CompositeData data = URISupport.parseComposite(location); if (data.getComponents().length == 1 && "broker".equals(data.getComponents()[0].getScheme())) { brokerURI = data.getComponents()[0]; CompositeData brokerData = URISupport.parseComposite(brokerURI); location = new URI("vm://" + host); } else { broker = BrokerFactory.createBroker(brokerURI); broker.start(); MDC.put("activemq.broker", broker.getBrokerName()); } catch (URISyntaxException e) { throw IOExceptionSupport.create(e); if (server == null) { server = (VMTransportServer)bind(location, true); TransportConnector connector = new TransportConnector(server); connector.setBrokerService(broker); connector.setUri(location); connector.setTaskRunnerFactory(broker.getTaskRunnerFactory()); connector.start(); CONNECTORS.put(host, connector);
@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); } }
/** * Adds a new transport connector for the given bind address * * @return the newly created and added transport connector * @throws Exception */ public TransportConnector addConnector(String bindAddress) throws Exception { return addConnector(new URI(bindAddress)); }
broker = new BrokerService(); broker.setUseJmx(true); broker.setTmpDataDirectory(tempDir); broker.setDataDirectory(dataDir.toString()); if (brokerConfiguration == null) { broker.setBrokerName(brokerName); createManagementContext(brokerName); selectedPort.bind(Port.TYPE.TCP); TransportConnector connector = broker.addConnector("tcp://" + bindAddress + ":" + selectedPort.getNumber()); String group = info.getDomain().getAuthority(); connector.setDiscoveryUri(URI.create("multicast://default?group=" + group)); broker.addNetworkConnector("multicast://default?group=" + group); } else { String name = brokerConfiguration.getName(); if (name != null) { brokerName = name; broker.setBrokerName(name); } else { broker.setBrokerName(brokerName); adapter.setSyncOnWrite(persistenceConfig.isSyncOnWrite()); adapter.setDisableLocking(persistenceConfig.isDisableLocking()); broker.setPersistenceAdapter(adapter); broker.addNetworkConnector(uri); TransportConnector connector = broker.addConnector(uri); connector.setDiscoveryUri(discoveryUri);
public void doActiveMqClientTest() throws Exception { BrokerService brokerService = new BrokerService(); brokerService.setBrokerName("SiteWhereTest"); TransportConnector connector = new TransportConnector(); connector.setUri(new URI("tcp://0.0.0.0:1234")); brokerService.addConnector(connector); brokerService.setUseShutdownHook(false); brokerService.setUseJmx(false); brokerService.start(); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://SiteWhereTest"); javax.jms.Connection connection = connectionFactory.createConnection(); connection.setExceptionListener(new ExceptionListener() { connection.start();
/** * Create a light JMS broker * * @param brokerName The broker name * @param discoveryURI The rendez-vous address to use, in example: rendezvous://lightbrokers */ public LightBroker(String brokerName, String discoveryURI) { try { final TransportConnector transportConnector = new TransportConnector(); transportConnector.setUri(new URI("tcp://0.0.0.0:0")); transportConnector.setDiscoveryUri(new URI(discoveryURI)); broker = new BrokerService(); broker.setPersistent(false); broker.setUseJmx(false); broker.getManagementContext().setFindTigerMbeanServer(true); broker.setEnableStatistics(false); broker.setSupportFailOver(true); broker.setUseShutdownHook(true); broker.setBrokerName(brokerName); broker.addConnector(transportConnector); broker.addNetworkConnector(discoveryURI); broker.setPopulateJMSXUserID(true); } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
public BrokerService createBroker(URI brokerURI) throws Exception { CompositeData compositeData = URISupport.parseComposite(brokerURI); Map<String, String> params = new HashMap<String, String>(compositeData.getParameters()); BrokerService brokerService = new BrokerService(); 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()); } URI[] components = compositeData.getComponents(); for (int i = 0; i < components.length; i++) { if ("network".equals(components[i].getScheme())) { brokerService.addNetworkConnector(components[i].getSchemeSpecificPart()); } else if ("proxy".equals(components[i].getScheme())) { brokerService.addProxyConnector(components[i].getSchemeSpecificPart()); } else { brokerService.addConnector(components[i]); } } return brokerService; }
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; }
@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); }
protected void addAdditionalConnectors(BrokerService brokerService, Map<String, Integer> portMap) throws Exception { int port = PORT; if (portMap.containsKey(AMQP_CONNECTOR_NAME)) { port = portMap.get(AMQP_CONNECTOR_NAME); } TransportConnector connector = brokerService .addConnector("amqp://0.0.0.0:" + port + "?transport.transformer=" + getAmqpTransformer() + "&transport.socketBufferSize=" + getSocketBufferSize() + "&ioBufferSize=" + getIOBufferSize()); connector.setName(AMQP_CONNECTOR_NAME); port = connector.getPublishableConnectURI().getPort(); LOG.debug("Using amqp port: {}", port); }
@Override public void start() throws Exception { String uri = uriPrefix + hostName + ":" + port; LOG.info("ACTIVEMQ: Starting ActiveMQ on {}", uri); configure(); broker = new BrokerService(); broker.addConnector(uri); broker.start(); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(uri + uriPostfix); Connection conn = factory.createConnection(); conn.start(); session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); dest = session.createQueue(queueName); consumer = session.createConsumer(dest); producer = session.createProducer(dest); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); }
@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); }