@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(); }
@Override public Map<String, String> getTransportConnectors() { Map<String, String> answer = new HashMap<String, String>(); try { for (TransportConnector connector : brokerService.getTransportConnectors()) { answer.put(connector.getName(), connector.getConnectUri().toString()); } } catch (Exception e) { LOG.debug("Failed to read URI to build transport connectors map", e); } return answer; }
public String getDefaultSocketURIString() { if (started.get()) { if (this.defaultSocketURIString == null) { for (TransportConnector tc:this.transportConnectors) { String result = null; try { result = tc.getPublishableConnectString(); } catch (Exception e) { LOG.warn("Failed to get the ConnectURI for {}", tc, e); } if (result != null) { // find first publishable uri if (tc.isUpdateClusterClients() || tc.isRebalanceClusterClients()) { this.defaultSocketURIString = result; break; } else { // or use the first defined if (this.defaultSocketURIString == null) { this.defaultSocketURIString = result; } } } } } return this.defaultSocketURIString; } return null; }
@Before public void init() throws Exception { underTest = new TransportConnector(); underTest.setBrokerService(new BrokerService()); }
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(); LOG.info("Broker " + name + " has started."); server.getBroker().waitUntilStarted(); server.getBroker().addShutdownHook(new Runnable() { @Override
URI connectorURI = connector.getConnectUri(); String scheme = connectorURI.getScheme(); if ("vm".equals(scheme)) { return connectorURI; String userInfo = getPublishedUserInfoValue(connectorURI.getUserInfo()); String host = getPublishedHostValue(connectorURI.getHost()); if (hostMapping.containsKey(host)) { host = hostMapping.get(host);
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 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; } });
public Map<String, String> getTransportConnectorURIsAsMap() { Map<String, String> answer = new HashMap<>(); for (TransportConnector connector : transportConnectors) { try { URI uri = connector.getConnectUri(); if (uri != null) { String scheme = uri.getScheme(); if (scheme != null) { answer.put(scheme.toLowerCase(Locale.ENGLISH), uri.toString()); } } } catch (Exception e) { LOG.debug("Failed to read URI to build transportURIsAsMap", e); } } return answer; }
advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_ORIGIN_BROKER_ID, id); String url = getBrokerService().getVmConnectorURI().toString(); && ((TransportConnector) context.getConnector()).getPublishableConnectString() != null) { url = ((TransportConnector) context.getConnector()).getPublishableConnectString(); } else if (getBrokerService().getDefaultSocketURIString() != null) { url = getBrokerService().getDefaultSocketURIString();
@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); } }
@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(); } }
broker = new BrokerService(); broker.setUseJmx(true); broker.setTmpDataDirectory(tempDir); broker.setDataDirectory(dataDir.toString()); if (brokerConfiguration == null) { 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 { URI discoveryUri = config.getDiscoveryUri(); 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); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://SiteWhereTest"); javax.jms.Connection connection = connectionFactory.createConnection(); connection.setExceptionListener(new ExceptionListener() { connection.start();
@Before public void setUp() throws Exception { brokerService = new BrokerService(); brokerService.setPersistent(false); brokerService.setPlugins(new BrokerPlugin[] { new BrokerPluginSupport() { @Override public void removeConnection(ConnectionContext context, ConnectionInfo info, Throwable error) throws Exception { LOG.info("Remove Connection called for connection [{}] with error: {}", info.getConnectionId(), error); removeException.set(error); super.removeConnection(context, info, error); } }}); stealableConnectionURI = brokerService.addConnector("tcp://0.0.0.0:0?allowLinkStealing=true").getPublishableConnectString(); unstealableConnectionURI = brokerService.addConnector("tcp://0.0.0.0:0?allowLinkStealing=false").getPublishableConnectString(); brokerService.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); } }
private void configureTransportConnector(final String jmsBrokerHost, final Integer jmsBrokerPort) { String uriString = "tcp://" + jmsBrokerHost + ":" + jmsBrokerPort; try { transportConnector.setUri(new URI(uriString)); } catch (URISyntaxException e) { logger.error("Wrong URI: '" + uriString + "', message: " + e.getMessage()); //NOSONAR - we don't need more info } }
private void registerConnectors() throws Exception { List<String> services = new LinkedList<String>(); for (String name : connectors) { TransportConnector connector = server.getBroker().getConnectorByName(name); if (connector == null) { warn("ActiveMQ broker '%s' does not have a connector called '%s'", name, name); } else { services.add(connector.getConnectUri().getScheme() + "://${zk:" + System.getProperty("runtime.id") + "/ip}:" + connector.getPublishableConnectURI().getPort()); } } discoveryAgent.setServices(services.toArray(new String[services.size()])); }