Java Code Examples for org.apache.pulsar.broker.ServiceConfiguration#setInternalListenerName()
The following examples show how to use
org.apache.pulsar.broker.ServiceConfiguration#setInternalListenerName() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultipleListenerValidatorTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = IllegalArgumentException.class) public void testAppearTogether() { ServiceConfiguration config = new ServiceConfiguration(); config.setAdvertisedAddress("127.0.0.1"); config.setAdvertisedListeners("internal:pulsar://192.168.1.11:6660,internal:pulsar+ssl://192.168.1.11:6651"); config.setInternalListenerName("internal"); MultipleListenerValidator.validateAndAnalysisAdvertisedListener(config); }
Example 2
Source File: MultipleListenerValidatorTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = IllegalArgumentException.class) public void testListenerDuplicate_1() { ServiceConfiguration config = new ServiceConfiguration(); config.setAdvertisedListeners(" internal:pulsar://127.0.0.1:6660, internal:pulsar+ssl://127.0.0.1:6651," + " internal:pulsar://192.168.1.11:6660, internal:pulsar+ssl://192.168.1.11:6651"); config.setInternalListenerName("internal"); MultipleListenerValidator.validateAndAnalysisAdvertisedListener(config); }
Example 3
Source File: MultipleListenerValidatorTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = IllegalArgumentException.class) public void testListenerDuplicate_2() { ServiceConfiguration config = new ServiceConfiguration(); config.setAdvertisedListeners(" internal:pulsar://127.0.0.1:6660," + " internal:pulsar://192.168.1.11:6660"); config.setInternalListenerName("internal"); MultipleListenerValidator.validateAndAnalysisAdvertisedListener(config); }
Example 4
Source File: MultipleListenerValidatorTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = IllegalArgumentException.class) public void testDifferentListenerWithSameHostPort() { ServiceConfiguration config = new ServiceConfiguration(); config.setAdvertisedListeners(" internal:pulsar://127.0.0.1:6660," + " external:pulsar://127.0.0.1:6660"); config.setInternalListenerName("internal"); MultipleListenerValidator.validateAndAnalysisAdvertisedListener(config); }
Example 5
Source File: MultipleListenerValidatorTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = IllegalArgumentException.class) public void testListenerWithoutTLSPort() { ServiceConfiguration config = new ServiceConfiguration(); config.setAdvertisedListeners(" internal:pulsar://127.0.0.1:6660, internal:pulsar+ssl://127.0.0.1:6651"); config.setInternalListenerName("internal"); MultipleListenerValidator.validateAndAnalysisAdvertisedListener(config); }
Example 6
Source File: MultipleListenerValidatorTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test public void testListenerWithTLSPort() { ServiceConfiguration config = new ServiceConfiguration(); config.setBrokerServicePortTls(Optional.of(6651)); config.setAdvertisedListeners(" internal:pulsar://127.0.0.1:6660, internal:pulsar+ssl://127.0.0.1:6651"); config.setInternalListenerName("internal"); MultipleListenerValidator.validateAndAnalysisAdvertisedListener(config); }
Example 7
Source File: MultipleListenerValidatorTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = IllegalArgumentException.class) public void testListenerWithoutNonTLSAddress() { ServiceConfiguration config = new ServiceConfiguration(); config.setBrokerServicePortTls(Optional.of(6651)); config.setAdvertisedListeners(" internal:pulsar+ssl://127.0.0.1:6651"); config.setInternalListenerName("internal"); MultipleListenerValidator.validateAndAnalysisAdvertisedListener(config); }
Example 8
Source File: MultipleListenerValidatorTest.java From pulsar with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = IllegalArgumentException.class) public void testWithoutListenerNameInAdvertisedListeners() { ServiceConfiguration config = new ServiceConfiguration(); config.setBrokerServicePortTls(Optional.of(6651)); config.setAdvertisedListeners(" internal:pulsar://127.0.0.1:6660, internal:pulsar+ssl://127.0.0.1:6651"); config.setInternalListenerName("external"); MultipleListenerValidator.validateAndAnalysisAdvertisedListener(config); }
Example 9
Source File: MultipleListenerValidator.java From pulsar with Apache License 2.0 | 4 votes |
/** * validate the configure of `advertisedListeners`, `internalListenerName`, `advertisedAddress`. * 1. `advertisedListeners` and `advertisedAddress` must not appear together. * 2. the listener name in `advertisedListeners` must not duplicate. * 3. user can not assign same 'host:port' to different listener. * 4. if `internalListenerName` is absent, the first `listener` in the `advertisedListeners` will be the `internalListenerName`. * 5. if pulsar do not specify `brokerServicePortTls`, should only contain one entry of `pulsar://` per listener name. * @param config the pulsar broker configure. * @return */ public static Map<String, AdvertisedListener> validateAndAnalysisAdvertisedListener(ServiceConfiguration config) { if (StringUtils.isNotBlank(config.getAdvertisedListeners()) && StringUtils.isNotBlank(config.getAdvertisedAddress())) { throw new IllegalArgumentException("`advertisedListeners` and `advertisedAddress` must not appear together"); } if (StringUtils.isBlank(config.getAdvertisedListeners())) { return Collections.EMPTY_MAP; } Optional<String> firstListenerName = Optional.empty(); Map<String, List<String>> listeners = Maps.newHashMap(); for (final String str : StringUtils.split(config.getAdvertisedListeners(), ",")) { int index = str.indexOf(":"); if (index <= 0) { throw new IllegalArgumentException("the configure entry `advertisedListeners` is invalid. because " + str + " do not contain listener name"); } String listenerName = StringUtils.trim(str.substring(0, index)); if (!firstListenerName.isPresent()) { firstListenerName = Optional.of(listenerName); } String value = StringUtils.trim(str.substring(index + 1)); listeners.computeIfAbsent(listenerName, k -> Lists.newArrayListWithCapacity(2)); listeners.get(listenerName).add(value); } if (StringUtils.isBlank(config.getInternalListenerName())) { config.setInternalListenerName(firstListenerName.get()); } if (!listeners.containsKey(config.getInternalListenerName())) { throw new IllegalArgumentException("the `advertisedListeners` configure do not contain `internalListenerName` entry"); } final Map<String, AdvertisedListener> result = Maps.newHashMap(); final Map<String, Set<String>> reverseMappings = Maps.newHashMap(); for (final Map.Entry<String, List<String>> entry : listeners.entrySet()) { if (entry.getValue().size() > 2) { throw new IllegalArgumentException("there are redundant configure for listener `" + entry.getKey() + "`"); } URI pulsarAddress = null, pulsarSslAddress = null; for (final String strUri : entry.getValue()) { try { URI uri = URI.create(strUri); if (StringUtils.equalsIgnoreCase(uri.getScheme(), "pulsar")) { if (pulsarAddress == null) { pulsarAddress = uri; } else { throw new IllegalArgumentException("there are redundant configure for listener `" + entry.getKey() + "`"); } } else if (StringUtils.equalsIgnoreCase(uri.getScheme(), "pulsar+ssl")) { if (pulsarSslAddress == null) { pulsarSslAddress = uri; } else { throw new IllegalArgumentException("there are redundant configure for listener `" + entry.getKey() + "`"); } } String hostPort = String.format("%s:%d", uri.getHost(), uri.getPort()); reverseMappings.computeIfAbsent(hostPort, k -> Sets.newTreeSet()); Set<String> sets = reverseMappings.get(hostPort); if (sets == null) { sets = Sets.newTreeSet(); reverseMappings.put(hostPort, sets); } sets.add(entry.getKey()); if (sets.size() > 1) { throw new IllegalArgumentException("must not specify `" + hostPort + "` to different listener."); } } catch (Throwable cause) { throw new IllegalArgumentException("the value " + strUri + " in the `advertisedListeners` configure is invalid"); } } if (!config.getBrokerServicePortTls().isPresent()) { if (pulsarSslAddress != null) { throw new IllegalArgumentException("If pulsar do not start ssl port, there is no need to configure " + " `pulsar+ssl` in `" + entry.getKey() + "` listener."); } } else { if (pulsarSslAddress == null) { throw new IllegalArgumentException("the `" + entry.getKey() + "` listener in the `advertisedListeners` " + " do not specify `pulsar+ssl` address."); } } if (pulsarAddress == null) { throw new IllegalArgumentException("the `" + entry.getKey() + "` listener in the `advertisedListeners` " + " do not specify `pulsar` address."); } result.put(entry.getKey(), AdvertisedListener.builder().brokerServiceUrl(pulsarAddress).brokerServiceUrlTls(pulsarSslAddress).build()); } return result; }