org.apache.kafka.clients.admin.AdminClientConfig Java Examples
The following examples show how to use
org.apache.kafka.clients.admin.AdminClientConfig.
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: KafkaDataServerStartable.java From incubator-pinot with Apache License 2.0 | 6 votes |
public void init(Properties props) { port = (int) props.get(PORT); zkStr = props.getProperty(ZOOKEEPER_CONNECT); logDirPath = props.getProperty(LOG_DIRS); // Create the ZK nodes for Kafka, if needed int indexOfFirstSlash = zkStr.indexOf('/'); if (indexOfFirstSlash != -1) { String bareZkUrl = zkStr.substring(0, indexOfFirstSlash); String zkNodePath = zkStr.substring(indexOfFirstSlash); ZkClient client = new ZkClient(bareZkUrl); client.createPersistent(zkNodePath, true); client.close(); } File logDir = new File(logDirPath); logDir.mkdirs(); props.put("zookeeper.session.timeout.ms", "60000"); serverStartable = new KafkaServerStartable(new KafkaConfig(props)); final Map<String, Object> config = new HashMap<>(); config.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:" + port); config.put(AdminClientConfig.CLIENT_ID_CONFIG, "Kafka2AdminClient-" + UUID.randomUUID().toString()); config.put(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, 15000); adminClient = KafkaAdminClient.create(config); }
Example #2
Source File: KafkaRangerTopicCreationTest.java From ranger with Apache License 2.0 | 6 votes |
@Test public void testCreateTopic() throws Exception { final String topic = "test"; Properties properties = new Properties(); properties.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:" + port); properties.put("client.id", "test-consumer-id"); properties.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SASL_PLAINTEXT"); AdminClient client = KafkaAdminClient.create(properties); CreateTopicsResult result = client.createTopics(Arrays.asList(new NewTopic(topic, 1, (short) 1))); result.values().get(topic).get(); for (Map.Entry<String, KafkaFuture<Void>> entry : result.values().entrySet()) { System.out.println("Create Topic : " + entry.getKey() + " " + "isCancelled : " + entry.getValue().isCancelled() + " " + "isCompletedExceptionally : " + entry.getValue().isCompletedExceptionally() + " " + "isDone : " + entry.getValue().isDone()); } }
Example #3
Source File: KafkaStorage.java From zipkin-storage-kafka with Apache License 2.0 | 6 votes |
@Override public String toString() { return "KafkaStorage{" + " bootstrapServers=" + adminConfig.getProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG) + ", spanPartitioning{ enabled=" + partitioningEnabled + ", spansTopic=" + partitioningSpansTopic + "}" + ", spanAggregation{ enabled=" + aggregationEnabled + ", spansTopic=" + aggregationSpansTopic + ", traceTopic=" + aggregationTraceTopic + ", dependencyTopic=" + aggregationDependencyTopic + "}" + ", traceStore { traceByIdQueryEnabled=" + traceByIdQueryEnabled + ", traceSearchEnabled=" + traceSearchEnabled + ", spansTopic=" + storageSpansTopic + "}" + ", dependencyStore { dependencyQueryEnabled=" + dependencyQueryEnabled + ", dependencyTopic=" + storageDependencyTopic + "}" + '}'; }
Example #4
Source File: IntegrationTest.java From aiven-kafka-connect-gcs with GNU Affero General Public License v3.0 | 6 votes |
@BeforeEach void setUp() throws ExecutionException, InterruptedException { testBucketAccessor.clear(gcsPrefix); final Properties adminClientConfig = new Properties(); adminClientConfig.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers()); adminClient = AdminClient.create(adminClientConfig); final Map<String, Object> producerProps = new HashMap<>(); producerProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBootstrapServers()); producerProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); producerProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); producer = new KafkaProducer<>(producerProps); final NewTopic newTopic0 = new NewTopic(TEST_TOPIC_0, 4, (short) 1); final NewTopic newTopic1 = new NewTopic(TEST_TOPIC_1, 4, (short) 1); adminClient.createTopics(Arrays.asList(newTopic0, newTopic1)).all().get(); connectRunner = new ConnectRunner(pluginDir, kafka.getBootstrapServers(), OFFSET_FLUSH_INTERVAL_MS); connectRunner.start(); }
Example #5
Source File: KafkaModule.java From emodb with Apache License 2.0 | 6 votes |
@Provides @Singleton AdminClient provideAdminClient(@BootstrapServers String bootstrapServers, @Nullable SslConfiguration sslConfiguration) { Properties properties = new Properties(); properties.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); if (null != sslConfiguration) { properties.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, SslConfiguration.PROTOCOL); properties.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, sslConfiguration.getTrustStoreLocation()); properties.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, sslConfiguration.getTrustStorePassword()); properties.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, sslConfiguration.getKeyStoreLocation()); properties.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, sslConfiguration.getKeyStorePassword()); properties.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, sslConfiguration.getKeyPassword()); } return AdminClient.create(properties); }
Example #6
Source File: KafkaBinderTests.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 6 votes |
@Test(expected = TopicExistsException.class) public void testSameTopicCannotBeProvisionedAgain() throws Throwable { try (AdminClient admin = AdminClient.create( Collections.singletonMap(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, embeddedKafka.getEmbeddedKafka().getBrokersAsString()))) { admin.createTopics(Collections .singletonList(new NewTopic("fooUniqueTopic", 1, (short) 1))).all() .get(); try { admin.createTopics(Collections .singletonList(new NewTopic("fooUniqueTopic", 1, (short) 1))) .all().get(); } catch (Exception ex) { assertThat(ex.getCause() instanceof TopicExistsException).isTrue(); throw ex.getCause(); } } }
Example #7
Source File: KafkaBinderTests.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 6 votes |
@Before public void init() { String multiplier = System.getenv("KAFKA_TIMEOUT_MULTIPLIER"); if (multiplier != null) { timeoutMultiplier = Double.parseDouble(multiplier); } BrokerAddress[] brokerAddresses = embeddedKafka.getEmbeddedKafka() .getBrokerAddresses(); List<String> bAddresses = new ArrayList<>(); for (BrokerAddress bAddress : brokerAddresses) { bAddresses.add(bAddress.toString()); } String[] foo = new String[bAddresses.size()]; Map<String, Object> adminConfigs = new HashMap<>(); adminConfigs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bAddresses.toArray(foo)[0]); adminClient = AdminClient.create(adminConfigs); }
Example #8
Source File: CruiseControlMetricsUtils.java From cruise-control with BSD 2-Clause "Simplified" License | 5 votes |
/** * Parse AdminClient configs based on the given {@link CruiseControlMetricsReporterConfig configs}. * * @param adminClientConfigs Configs that will be return with SSL configs. * @param configs Configs to be used for parsing AdminClient SSL configs. * @return AdminClient configs. */ public static Properties addSslConfigs(Properties adminClientConfigs, CruiseControlMetricsReporterConfig configs) { // Add security protocol (if specified). try { String securityProtocol = configs.getString(AdminClientConfig.SECURITY_PROTOCOL_CONFIG); adminClientConfigs.put(AdminClientConfig.SECURITY_PROTOCOL_CONFIG, securityProtocol); setStringConfigIfExists(configs, adminClientConfigs, SaslConfigs.SASL_MECHANISM); setPasswordConfigIfExists(configs, adminClientConfigs, SaslConfigs.SASL_JAAS_CONFIG); // Configure SSL configs (if security protocol is SSL or SASL_SSL) if (securityProtocol.equals(SecurityProtocol.SSL.name) || securityProtocol.equals(SecurityProtocol.SASL_SSL.name)) { setStringConfigIfExists(configs, adminClientConfigs, SslConfigs.SSL_TRUSTMANAGER_ALGORITHM_CONFIG); setStringConfigIfExists(configs, adminClientConfigs, SslConfigs.SSL_KEYMANAGER_ALGORITHM_CONFIG); setStringConfigIfExists(configs, adminClientConfigs, SslConfigs.SSL_KEYSTORE_TYPE_CONFIG); setStringConfigIfExists(configs, adminClientConfigs, SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG); setStringConfigIfExists(configs, adminClientConfigs, SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG); setStringConfigIfExists(configs, adminClientConfigs, SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG); setStringConfigIfExists(configs, adminClientConfigs, SslConfigs.SSL_SECURE_RANDOM_IMPLEMENTATION_CONFIG); setPasswordConfigIfExists(configs, adminClientConfigs, SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG); setPasswordConfigIfExists(configs, adminClientConfigs, SslConfigs.SSL_KEY_PASSWORD_CONFIG); setPasswordConfigIfExists(configs, adminClientConfigs, SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG); } } catch (ConfigException ce) { // let it go. } return adminClientConfigs; }
Example #9
Source File: KafkaClientConfigUtil.java From kafka-webview with MIT License | 5 votes |
/** * Builds a map of all common Kafka client configuration settings. * @param clusterConfig ClusterConfig instance to use as basis for configuration/ * @param consumerId Id of consumer to use. This will be prefixed with consumerIdPrefix property. * @param config Apply configuration to existing map. * @return a new Map containing the configuration options. */ private Map<String, Object> applyCommonSettings( final ClusterConfig clusterConfig, final String consumerId, final Map<String, Object> config ) { // Generate groupId with our configured static prefix. final String prefixedGroupId = consumerIdPrefix.concat("-").concat(consumerId); // Generate consumerId, which should be unique per user and thread. final String prefixedConsumerId = prefixedGroupId.concat("-") + Thread.currentThread().getId(); // Set common config items config.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, clusterConfig.getConnectString()); config.put(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, requestTimeoutMs); // groupId is intended to be unique for each user session. // clientId is intended to be unique per user session and thread. // See Issue-57 https://github.com/SourceLabOrg/kafka-webview/issues/57#issuecomment-363508531 // See Issue-175 https://github.com/SourceLabOrg/kafka-webview/issues/175 config.put(ConsumerConfig.CLIENT_ID_CONFIG, prefixedConsumerId); config.put(ConsumerConfig.GROUP_ID_CONFIG, prefixedGroupId); // Optionally configure SSL applySslSettings(clusterConfig, config); // Optionally configure SASL applySaslSettings(clusterConfig, config); return config; }
Example #10
Source File: KafkaTopologyBuilder.java From kafka-topology-builder with MIT License | 5 votes |
private static Properties buildProperties(Map<String, String> cliParams) { Properties props = new Properties(); if (cliParams.get(ADMIN_CLIENT_CONFIG_OPTION) != null) { try { props.load(new FileInputStream(cliParams.get(ADMIN_CLIENT_CONFIG_OPTION))); } catch (IOException e) { // TODO: Can be ignored } } props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, cliParams.get(BROKERS_OPTION)); props.put(AdminClientConfig.RETRIES_CONFIG, Integer.MAX_VALUE); return props; }
Example #11
Source File: KafkaClientConfigUtilTest.java From kafka-webview with MIT License | 5 votes |
private void validateDefaultKeys(final Map<String, Object> config) { assertNotNull(config); validateKey(config, AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, expectedBrokerHosts); validateKey(config, AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG, expectedRequestTimeoutValue); validateKey(config, AdminClientConfig.CLIENT_ID_CONFIG, expectedFinalConsumerId); validateKey(config, ConsumerConfig.GROUP_ID_CONFIG, expectedFinalGroupId); }
Example #12
Source File: KafkaProducerConfiguration.java From integration-patterns with MIT License | 5 votes |
@Bean public KafkaAdmin admin() { Map<String, Object> configs = new HashMap<>(); configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, servers); return new KafkaAdmin(configs); }
Example #13
Source File: KafkaAdminClientExamples.java From vertx-kafka-client with Apache License 2.0 | 5 votes |
/** * Example about Kafka Admin Client creation * @param vertx Vert.x instance */ public void exampleCreateAdminClient(Vertx vertx) { // creating the admin client using properties config Properties config = new Properties(); config.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); KafkaAdminClient adminClient = KafkaAdminClient.create(vertx, config); }
Example #14
Source File: AbstractKafkaClientsIntegrationTestHarness.java From li-apache-kafka-clients with BSD 2-Clause "Simplified" License | 5 votes |
protected Properties getAdminClientProperties(Properties overrides) { Properties result = new Properties(); //populate defaults result.setProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers()); setSecurityConfigs(result, "adminClient"); //apply overrides if (overrides != null) { result.putAll(overrides); } return result; }
Example #15
Source File: KafkaTopicProvisioner.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 5 votes |
/** * In general, binder properties supersede boot kafka properties. The one exception is * the bootstrap servers. In that case, we should only override the boot properties if * (there is a binder property AND it is a non-default value) OR (if there is no boot * property); this is needed because the binder property never returns a null value. * @param adminProps the admin properties to normalize. * @param bootProps the boot kafka properties. * @param binderProps the binder kafka properties. */ public static void normalalizeBootPropsWithBinder(Map<String, Object> adminProps, KafkaProperties bootProps, KafkaBinderConfigurationProperties binderProps) { // First deal with the outlier String kafkaConnectionString = binderProps.getKafkaConnectionString(); if (ObjectUtils .isEmpty(adminProps.get(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG)) || !kafkaConnectionString .equals(binderProps.getDefaultKafkaConnectionString())) { adminProps.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaConnectionString); } // Now override any boot values with binder values Map<String, String> binderProperties = binderProps.getConfiguration(); Set<String> adminConfigNames = AdminClientConfig.configNames(); binderProperties.forEach((key, value) -> { if (key.equals(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG)) { throw new IllegalStateException( "Set binder bootstrap servers via the 'brokers' property, not 'configuration'"); } if (adminConfigNames.contains(key)) { Object replaced = adminProps.put(key, value); if (replaced != null && KafkaTopicProvisioner.logger.isDebugEnabled()) { KafkaTopicProvisioner.logger.debug("Overrode boot property: [" + key + "], from: [" + replaced + "] to: [" + value + "]"); } } }); }
Example #16
Source File: KafkaTopicProvisionerTests.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") @Test public void bootPropertiesOverriddenExceptServers() throws Exception { KafkaProperties bootConfig = new KafkaProperties(); bootConfig.getProperties().put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "PLAINTEXT"); bootConfig.setBootstrapServers(Collections.singletonList("localhost:1234")); KafkaBinderConfigurationProperties binderConfig = new KafkaBinderConfigurationProperties( bootConfig); binderConfig.getConfiguration().put(AdminClientConfig.SECURITY_PROTOCOL_CONFIG, "SSL"); ClassPathResource ts = new ClassPathResource("test.truststore.ks"); binderConfig.getConfiguration().put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, ts.getFile().getAbsolutePath()); binderConfig.setBrokers("localhost:9092"); KafkaTopicProvisioner provisioner = new KafkaTopicProvisioner(binderConfig, bootConfig); AdminClient adminClient = provisioner.createAdminClient(); assertThat(KafkaTestUtils.getPropertyValue(adminClient, "client.selector.channelBuilder")).isInstanceOf(SslChannelBuilder.class); Map configs = KafkaTestUtils.getPropertyValue(adminClient, "client.selector.channelBuilder.configs", Map.class); assertThat( ((List) configs.get(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG)).get(0)) .isEqualTo("localhost:1234"); adminClient.close(); }
Example #17
Source File: KafkaTopicProvisionerTests.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 5 votes |
@SuppressWarnings("rawtypes") @Test public void bootPropertiesOverriddenIncludingServers() throws Exception { KafkaProperties bootConfig = new KafkaProperties(); bootConfig.getProperties().put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "PLAINTEXT"); bootConfig.setBootstrapServers(Collections.singletonList("localhost:9092")); KafkaBinderConfigurationProperties binderConfig = new KafkaBinderConfigurationProperties( bootConfig); binderConfig.getConfiguration().put(AdminClientConfig.SECURITY_PROTOCOL_CONFIG, "SSL"); ClassPathResource ts = new ClassPathResource("test.truststore.ks"); binderConfig.getConfiguration().put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, ts.getFile().getAbsolutePath()); binderConfig.setBrokers("localhost:1234"); KafkaTopicProvisioner provisioner = new KafkaTopicProvisioner(binderConfig, bootConfig); AdminClient adminClient = provisioner.createAdminClient(); assertThat(KafkaTestUtils.getPropertyValue(adminClient, "client.selector.channelBuilder")).isInstanceOf(SslChannelBuilder.class); Map configs = KafkaTestUtils.getPropertyValue(adminClient, "client.selector.channelBuilder.configs", Map.class); assertThat( ((List) configs.get(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG)).get(0)) .isEqualTo("localhost:1234"); adminClient.close(); }
Example #18
Source File: KafkaBinderTests.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testTopicPatterns() throws Exception { try (AdminClient admin = AdminClient.create( Collections.singletonMap(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, embeddedKafka.getEmbeddedKafka().getBrokersAsString()))) { admin.createTopics(Collections .singletonList(new NewTopic("topicPatterns.1", 1, (short) 1))).all() .get(); Binder binder = getBinder(); ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties = createConsumerProperties(); consumerProperties.getExtension().setDestinationIsPattern(true); DirectChannel moduleInputChannel = createBindableChannel("input", createConsumerBindingProperties(consumerProperties)); final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<String> topic = new AtomicReference<>(); moduleInputChannel.subscribe(m -> { topic.set(m.getHeaders().get(KafkaHeaders.RECEIVED_TOPIC, String.class)); latch.countDown(); }); Binding<MessageChannel> consumerBinding = binder.bindConsumer( "topicPatterns\\..*", "testTopicPatterns", moduleInputChannel, consumerProperties); DefaultKafkaProducerFactory pf = new DefaultKafkaProducerFactory( KafkaTestUtils.producerProps(embeddedKafka.getEmbeddedKafka())); KafkaTemplate template = new KafkaTemplate(pf); template.send("topicPatterns.1", "foo"); assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue(); assertThat(topic.get()).isEqualTo("topicPatterns.1"); consumerBinding.unbind(); pf.destroy(); } }
Example #19
Source File: MultiClusterTopicManagementService.java From kafka-monitor with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") TopicManagementHelper(Map<String, Object> props) throws Exception { TopicManagementServiceConfig config = new TopicManagementServiceConfig(props); AdminClientConfig adminClientConfig = new AdminClientConfig(props); String topicFactoryClassName = config.getString(TopicManagementServiceConfig.TOPIC_FACTORY_CLASS_CONFIG); _topicCreationEnabled = config.getBoolean(TopicManagementServiceConfig.TOPIC_CREATION_ENABLED_CONFIG); _topic = config.getString(TopicManagementServiceConfig.TOPIC_CONFIG); _zkConnect = config.getString(TopicManagementServiceConfig.ZOOKEEPER_CONNECT_CONFIG); _replicationFactor = config.getInt(TopicManagementServiceConfig.TOPIC_REPLICATION_FACTOR_CONFIG); _minPartitionsToBrokersRatio = config.getDouble(TopicManagementServiceConfig.PARTITIONS_TO_BROKERS_RATIO_CONFIG); _minPartitionNum = config.getInt(TopicManagementServiceConfig.MIN_PARTITION_NUM_CONFIG); _preferredLeaderElectionRequested = false; _requestTimeoutMs = adminClientConfig.getInt(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG); _bootstrapServers = adminClientConfig.getList(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG); _topicProperties = new Properties(); if (props.containsKey(TopicManagementServiceConfig.TOPIC_PROPS_CONFIG)) { for (Map.Entry<String, Object> entry: ((Map<String, Object>) props.get(TopicManagementServiceConfig.TOPIC_PROPS_CONFIG)).entrySet()) _topicProperties.put(entry.getKey(), entry.getValue().toString()); } Map topicFactoryConfig = props.containsKey(TopicManagementServiceConfig.TOPIC_FACTORY_PROPS_CONFIG) ? (Map) props.get(TopicManagementServiceConfig.TOPIC_FACTORY_PROPS_CONFIG) : new HashMap(); _topicFactory = (TopicFactory) Class.forName(topicFactoryClassName).getConstructor(Map.class).newInstance(topicFactoryConfig); _adminClient = constructAdminClient(props); LOGGER.info("{} configs: {}", _adminClient.getClass().getSimpleName(), props); }
Example #20
Source File: TopicST.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Tag(NODEPORT_SUPPORTED) @Test void testCreateTopicViaAdminClient() throws ExecutionException, InterruptedException, TimeoutException { String clusterName = CLUSTER_NAME + "-external-name"; KafkaResource.kafkaEphemeral(clusterName, 3, 3) .editSpec() .editKafka() .editListeners() .withNewKafkaListenerExternalNodePort() .withTls(false) .endKafkaListenerExternalNodePort() .endListeners() .endKafka() .endSpec() .done(); Properties properties = new Properties(); properties.setProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, AbstractKafkaClient.getExternalBootstrapConnect(NAMESPACE, clusterName)); try (AdminClient adminClient = AdminClient.create(properties)) { LOGGER.info("Creating async topic {} via Admin client", TOPIC_NAME); CreateTopicsResult crt = adminClient.createTopics(singletonList(new NewTopic(TOPIC_NAME, 1, (short) 1))); crt.all().get(); Set<String> topics = adminClient.listTopics().names().get(Constants.GLOBAL_CLIENTS_TIMEOUT, TimeUnit.MILLISECONDS); LOGGER.info("Verify that in Kafka cluster contains {} topics", 1); assertThat(topics.size(), is(1)); assertThat(topics.contains(TOPIC_NAME), is(true)); } LOGGER.info("Verify that corresponding {} KafkaTopic custom resources were created and topic is in Ready state", 1); KafkaTopicUtils.waitForKafkaTopicCreation(TOPIC_NAME); KafkaTopicUtils.waitForKafkaTopicReady(TOPIC_NAME); }
Example #21
Source File: KafkaSender.java From zipkin-reporter-java with Apache License 2.0 | 5 votes |
/** * Filter the properties configured for the producer by removing those not used for the Admin * Client. * * @see AdminClientConfig config properties */ Map<String, Object> filterPropertiesForAdminClient(Properties properties) { Map<String, Object> adminClientProperties = new LinkedHashMap<>(); for (Map.Entry property : properties.entrySet()) { if (AdminClientConfig.configNames().contains(property.getKey())) { adminClientProperties.put(property.getKey().toString(), property.getValue()); } } return adminClientProperties; }
Example #22
Source File: EventStreamsConsoleSample.java From event-streams-samples with Apache License 2.0 | 5 votes |
static final Properties getAdminConfigs(String bootstrapServers, String apikey) { Properties configs = new Properties(); configs.put(ConsumerConfig.CLIENT_ID_CONFIG, "kafka-java-console-sample-admin"); configs.put(AdminClientConfig.CLIENT_DNS_LOOKUP_CONFIG, "use_all_dns_ips"); configs.putAll(getCommonConfigs(bootstrapServers, apikey)); return configs; }
Example #23
Source File: KafkaAdminClientTest.java From elasticactors with Apache License 2.0 | 5 votes |
@Test(enabled = false) public void testListTopics() throws Exception { Map<String, Object> adminClientConfig = new HashMap<>(); adminClientConfig.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "api.local.getbux.com:32400,api.local.getbux.com:32401,api.local.getbux.com:32402"); adminClientConfig.put(AdminClientConfig.CLIENT_ID_CONFIG, "test-adminClient"); AdminClient adminClient = AdminClient.create(adminClientConfig); // ensure all the topics are created ListTopicsResult listTopicsResult = adminClient.listTopics(); Map<String, TopicListing> availableTopics = listTopicsResult.namesToListings().get(); assertNotNull(availableTopics); }
Example #24
Source File: ReplicationThrottleHelperTest.java From cruise-control with BSD 2-Clause "Simplified" License | 5 votes |
private void createTopics() { AdminClient adminClient = KafkaCruiseControlUtils.createAdminClient(Collections.singletonMap( AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, broker(0).plaintextAddr())); try { adminClient.createTopics(Arrays.asList( new NewTopic(TOPIC0, 2, (short) 2), new NewTopic(TOPIC1, 2, (short) 2) )); } finally { KafkaCruiseControlUtils.closeAdminClientWithTimeout(adminClient); } }
Example #25
Source File: AccessControlManagerIT.java From kafka-topology-builder with MIT License | 5 votes |
private Properties config() { Properties props = new Properties(); props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); props.put(AdminClientConfig.RETRIES_CONFIG, Integer.MAX_VALUE); props.put(AdminClientConfig.SECURITY_PROTOCOL_CONFIG, "SASL_PLAINTEXT"); props.put("sasl.mechanism", "PLAIN"); props.put( "sasl.jaas.config", "org.apache.kafka.common.security.plain.PlainLoginModule required username=\"kafka\" password=\"kafka\";"); return props; }
Example #26
Source File: ZipkinKafkaStorageModuleTest.java From zipkin-storage-kafka with Apache License 2.0 | 5 votes |
@Test void canOverridesProperty_adminConfigs() { TestPropertyValues.of( "zipkin.storage.type:kafka", "zipkin.storage.kafka.overrides.bootstrap.servers:host1:19092" ).applyTo(context); Access.registerKafka(context); context.refresh(); assertThat(context.getBean(KafkaStorage.class) .adminConfig.getProperty(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG)) .isEqualTo("host1:19092"); }
Example #27
Source File: SpringBootDecisionTracingConfiguration.java From kogito-runtimes with Apache License 2.0 | 5 votes |
/** * Defining a {@link KafkaAdmin} bean allows to automatically add topic to the broker via {@link NewTopic} beans */ @Bean public KafkaAdmin kafkaAdmin() { Map<String, Object> configs = new HashMap<>(); configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaBootstrapAddress); return new KafkaAdmin(configs); }
Example #28
Source File: KafkaSetupHandler.java From stream-registry with Apache License 2.0 | 5 votes |
private AdminClient createAdminClient() { val configs = new HashMap<String, Object>(); configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); log.info("Creating a Kafka Admin client with configuration {}", configs); return AdminClient.create(configs); }
Example #29
Source File: NotificationEventListenerKafkaIntegrationTest.java From stream-registry with Apache License 2.0 | 5 votes |
private AdminClient createAdminClient() { Map<String, Object> configs = new HashMap<>(); configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); log.info("Creating a Kafka Admin client with configuration {}", configs); return AdminClient.create(configs); }
Example #30
Source File: KafkaTopicClientImplIntegrationTest.java From ksql-fork-with-deep-learning-function with Apache License 2.0 | 5 votes |
@Before public void setUp() { testTopic = UUID.randomUUID().toString(); KAFKA.createTopic(testTopic); adminClient = AdminClient.create(ImmutableMap.of( AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, KAFKA.bootstrapServers())); client = new KafkaTopicClientImpl(adminClient); }