/** * Get the VM URL for the embedded EmbeddedActiveMQ server * * @return the VM URL for the embedded server */ public String getVmURL() { String vmURL = "vm://0"; for (TransportConfiguration transportConfiguration : configuration.getAcceptorConfigurations()) { Map<String, Object> params = transportConfiguration.getParams(); if (params != null && params.containsKey(TransportConstants.SERVER_ID_PROP_NAME)) { vmURL = "vm://" + params.get(TransportConstants.SERVER_ID_PROP_NAME); } } return vmURL; }
/** * Get the VM URL for the embedded EmbeddedActiveMQ server * * @return the VM URL for the embedded server */ public String getVmURL() { String vmURL = "vm://0"; for (TransportConfiguration transportConfiguration : configuration.getAcceptorConfigurations()) { Map<String, Object> params = transportConfiguration.getParams(); if (params != null && params.containsKey(TransportConstants.SERVER_ID_PROP_NAME)) { vmURL = "vm://" + params.get(TransportConstants.SERVER_ID_PROP_NAME); } } return vmURL; }
/** * Get the VM URL for the embedded EmbeddedActiveMQ server * * @return the VM URL for the embedded server */ public String getVmURL() { String vmURL = "vm://0"; for (TransportConfiguration transportConfiguration : configuration.getAcceptorConfigurations()) { Map<String, Object> params = transportConfiguration.getParams(); if (params != null && params.containsKey(TransportConstants.SERVER_ID_PROP_NAME)) { vmURL = "vm://" + params.get(TransportConstants.SERVER_ID_PROP_NAME); } } return vmURL; }
/** * Get the VM URL for the embedded EmbeddedActiveMQ server * * @return the VM URL for the embedded server */ public String getVmURL() { String vmURL = "vm://0"; for (TransportConfiguration transportConfiguration : configuration.getAcceptorConfigurations()) { Map<String, Object> params = transportConfiguration.getParams(); if (params != null && params.containsKey(TransportConstants.SERVER_ID_PROP_NAME)) { vmURL = "vm://" + params.get(TransportConstants.SERVER_ID_PROP_NAME); } } return vmURL; }
/** * Call this method once after a constructor in order to create a Netty instance to accept out of VM messages. * * @param host host to bind to * @param port port to listen on */ public void configureNetty(String host, int port){ Map<String, Object> params = map(TransportConstants.HOST_PROP_NAME, host, TransportConstants.PORT_PROP_NAME, port); config.getAcceptorConfigurations().add(new TransportConfiguration(NettyAcceptorFactory.class.getName(), params)); }
/** * Call this method once after a constructor in order to create a Netty instance to accept out of VM messages. * * @param host host to bind to * @param port port to listen on */ public void configureNetty(String host, int port){ Map<String, Object> params = map(TransportConstants.HOST_PROP_NAME, host, TransportConstants.PORT_PROP_NAME, port); config.getAcceptorConfigurations().add(new TransportConfiguration(NettyAcceptorFactory.class.getName(), params)); }
private void configureAcceptor() { config.setPersistenceEnabled(true); config.setSecurityEnabled(false); config.getAcceptorConfigurations().add(new TransportConfiguration(InVMAcceptorFactory.class.getName())); config.getConnectorConfigurations().put("connector", new TransportConfiguration(InVMConnectorFactory.class.getName())); }
private void configureAcceptor() { config.setPersistenceEnabled(true); config.setSecurityEnabled(false); config.getAcceptorConfigurations().add(new TransportConfiguration(InVMAcceptorFactory.class.getName())); config.getConnectorConfigurations().put("connector", new TransportConfiguration(InVMConnectorFactory.class.getName())); }
private static void updateAcceptorsAndConnectors(Configuration backupConfiguration, int portOffset, List<String> remoteConnectors, boolean fullServer) { //we only do this if we are a full server, if scale down then our acceptors wont be needed and our connectors will // be the same as the parent server if (fullServer) { Set<TransportConfiguration> acceptors = backupConfiguration.getAcceptorConfigurations(); for (TransportConfiguration acceptor : acceptors) { updatebackupParams(backupConfiguration.getName(), portOffset, acceptor.getParams()); } Map<String, TransportConfiguration> connectorConfigurations = backupConfiguration.getConnectorConfigurations(); for (Map.Entry<String, TransportConfiguration> entry : connectorConfigurations.entrySet()) { //check to make sure we aren't a remote connector as this shouldn't be changed if (!remoteConnectors.contains(entry.getValue().getName())) { updatebackupParams(backupConfiguration.getName(), portOffset, entry.getValue().getParams()); } } } else { //if we are scaling down then we wont need any acceptors but clear anyway for belts and braces backupConfiguration.getAcceptorConfigurations().clear(); } }
@Override protected void extraServerConfig(Configuration serverConfig) { Set<TransportConfiguration> acceptors = serverConfig.getAcceptorConfigurations(); for (TransportConfiguration tc : acceptors) { if (tc.getName().equals("netty")) { tc.getExtraParams().put("supportAdvisory", "false"); break; } } }
protected void addCoreConnector() throws Exception { // Overrides of this method can add additional configuration options or add multiple // MQTT transport connectors as needed, the port variable is always supposed to be // assigned the primary MQTT connector's port. Map<String, Object> params = new HashMap<>(); params.put(TransportConstants.PORT_PROP_NAME, "" + 5445); params.put(TransportConstants.PROTOCOLS_PROP_NAME, "CORE"); TransportConfiguration transportConfiguration = new TransportConfiguration(NETTY_ACCEPTOR_FACTORY, params); server.getConfiguration().getAcceptorConfigurations().add(transportConfiguration); LOG.info("Added connector {} to broker", getProtocolScheme()); }
private Configuration createDefaultConfig(final int index, final Map<String, Object> params, final String... acceptors) { Configuration configuration = createBasicConfig(index); for (String acceptor : acceptors) { TransportConfiguration transportConfig = new TransportConfiguration(acceptor, params); configuration.getAcceptorConfigurations().add(transportConfig); } return configuration; }
@Override protected void extraServerConfig(Configuration serverConfig) { Set<TransportConfiguration> acceptors = server.getConfiguration().getAcceptorConfigurations(); for (TransportConfiguration tc : acceptors) { if (tc.getName().equals("netty")) { tc.getExtraParams().put("virtualTopicConsumerWildcards", "Consumer.*.>;2"); tc.getExtraParams().put("virtualTopicConsumerLruCacheMax", "10000"); } } }
@Override protected void extraServerConfig(Configuration serverConfig) { serverConfig.setJMXManagementEnabled(true); if (useDefault) { //don't set parameters explicitly return; } Set<TransportConfiguration> acceptorConfigs = serverConfig.getAcceptorConfigurations(); for (TransportConfiguration tconfig : acceptorConfigs) { if ("netty".equals(tconfig.getName())) { Map<String, Object> params = tconfig.getExtraParams(); params.put("supportAdvisory", supportAdvisory); params.put("suppressInternalManagementObjects", suppressJmx); System.out.println("Now use properties: " + params); } } }
private void addMqttTransportConfiguration(Configuration configuration) throws IOException { TransportConfiguration transportConfiguration = new TransportConfiguration(NettyAcceptorFactory.class.getCanonicalName(), null, "mqtt", null); transportConfiguration.getParams().put(TransportConstants.SSL_ENABLED_PROP_NAME, true); transportConfiguration.getParams().put(TransportConstants.TRUSTSTORE_PATH_PROP_NAME, "truststore.jks"); transportConfiguration.getParams().put(TransportConstants.TRUSTSTORE_PASSWORD_PROP_NAME, "changeit"); transportConfiguration.getParams().put(TransportConstants.KEYSTORE_PATH_PROP_NAME, "keystore1.jks"); transportConfiguration.getParams().put(TransportConstants.KEYSTORE_PASSWORD_PROP_NAME, "changeit"); transportConfiguration.getParams().put(TransportConstants.CRL_PATH_PROP_NAME, "root.crl.pem"); transportConfiguration.getParams().put(TransportConstants.NEED_CLIENT_AUTH_PROP_NAME, "true"); transportConfiguration.getParams().put(TransportConstants.PORT_PROP_NAME, "1883"); transportConfiguration.getParams().put(TransportConstants.HOST_PROP_NAME, "localhost"); transportConfiguration.getParams().put(TransportConstants.PROTOCOLS_PROP_NAME, "MQTT"); configuration.getAcceptorConfigurations().add(transportConfiguration); }
private void testPerf(boolean nio) throws Exception { Configuration config = createDefaultInVMConfig(); Map<String, Object> params = new HashMap<>(); params.put(TransportConstants.USE_NIO_PROP_NAME, nio); config.getAcceptorConfigurations().add(new TransportConfiguration(NETTY_ACCEPTOR_FACTORY, params)); ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false)); AddressSettings addressSettings = new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK).setMaxSizeBytes(10 * 1024 * 1024); final String dest = "test-destination"; HierarchicalRepository<AddressSettings> repos = server.getAddressSettingsRepository(); repos.addMatch(dest, addressSettings); server.start(); for (int i = 0; i < 2; i++) { doTest(dest); } }
protected void configureAddressPolicy(ActiveMQServer server) { // Address configuration AddressSettings addressSettings = new AddressSettings(); addressSettings.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE); addressSettings.setAutoCreateQueues(isAutoCreateQueues()); addressSettings.setAutoCreateAddresses(isAutoCreateAddresses()); addressSettings.setDeadLetterAddress(SimpleString.toSimpleString(getDeadLetterAddress())); addressSettings.setExpiryAddress(SimpleString.toSimpleString(getDeadLetterAddress())); server.getConfiguration().getAddressesSettings().put("#", addressSettings); Set<TransportConfiguration> acceptors = server.getConfiguration().getAcceptorConfigurations(); for (TransportConfiguration tc : acceptors) { if (tc.getName().equals("netty-acceptor")) { tc.getExtraParams().put("anycastPrefix", "anycast://"); tc.getExtraParams().put("multicastPrefix", "multicast://"); } } }
@Test public void testExtraBackupReplicates() throws Exception { Configuration secondBackupConfig = backupConfig.copy(); TransportConfiguration tc = secondBackupConfig.getAcceptorConfigurations().iterator().next(); TestableServer secondBackupServer = createTestableServer(secondBackupConfig); tc.getParams().put("serverId", "2"); secondBackupConfig.setBindingsDirectory(getBindingsDir(1, true)).setJournalDirectory(getJournalDir(1, true)).setPagingDirectory(getPageDir(1, true)).setLargeMessagesDirectory(getLargeMessagesDir(1, true)).setSecurityEnabled(false); waitForRemoteBackupSynchronization(backupServer.getServer()); secondBackupServer.start(); Thread.sleep(5000); backupServer.stop(); waitForSync(secondBackupServer.getServer()); waitForRemoteBackupSynchronization(secondBackupServer.getServer()); }
@Test public void testExtraBackupGroupNameReplicates() throws Exception { ReplicaPolicyConfiguration backupReplicaPolicyConfiguration = (ReplicaPolicyConfiguration) backupServer.getServer().getConfiguration().getHAPolicyConfiguration(); backupReplicaPolicyConfiguration.setGroupName("foo"); ReplicatedPolicyConfiguration replicatedPolicyConfiguration = (ReplicatedPolicyConfiguration) liveServer.getServer().getConfiguration().getHAPolicyConfiguration(); replicatedPolicyConfiguration.setGroupName("foo"); Configuration secondBackupConfig = backupConfig.copy(); TransportConfiguration tc = secondBackupConfig.getAcceptorConfigurations().iterator().next(); TestableServer secondBackupServer = createTestableServer(secondBackupConfig); tc.getParams().put("serverId", "2"); secondBackupConfig.setBindingsDirectory(getBindingsDir(1, true)).setJournalDirectory(getJournalDir(1, true)).setPagingDirectory(getPageDir(1, true)).setLargeMessagesDirectory(getLargeMessagesDir(1, true)).setSecurityEnabled(false); ReplicaPolicyConfiguration replicaPolicyConfiguration = (ReplicaPolicyConfiguration) secondBackupConfig.getHAPolicyConfiguration(); replicaPolicyConfiguration.setGroupName("foo"); waitForRemoteBackupSynchronization(backupServer.getServer()); secondBackupServer.start(); Thread.sleep(5000); backupServer.stop(); waitForSync(secondBackupServer.getServer()); waitForRemoteBackupSynchronization(secondBackupServer.getServer()); }
protected ActiveMQServer createServer(int port) throws Exception { final ActiveMQServer server = this.createServer(true, true); server.getConfiguration().getAcceptorConfigurations().clear(); server.getConfiguration().getAcceptorConfigurations().add(addAcceptorConfiguration(server, port)); server.getConfiguration().setName(BROKER_NAME); server.getConfiguration().setJournalDirectory(server.getConfiguration().getJournalDirectory() + port); server.getConfiguration().setBindingsDirectory(server.getConfiguration().getBindingsDirectory() + port); server.getConfiguration().setPagingDirectory(server.getConfiguration().getPagingDirectory() + port); server.getConfiguration().setJMXManagementEnabled(true); server.getConfiguration().setMessageExpiryScanPeriod(5000); server.setMBeanServer(mBeanServer); // Add any additional Acceptors needed for tests addAdditionalAcceptors(server); // Address configuration configureAddressPolicy(server); // Add optional security for tests that need it configureBrokerSecurity(server); // Add extra configuration addConfiguration(server); server.start(); // Prepare all addresses and queues for client tests. createAddressAndQueues(server); return server; }