forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to configure most client/producer/consumer options in Kafka API…
… wrapper (apache#1207)
- Loading branch information
Showing
6 changed files
with
203 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...-kafka/src/main/java/org/apache/pulsar/client/kafka/compat/PulsarConsumerKafkaConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.client.kafka.compat; | ||
|
||
import java.util.Properties; | ||
|
||
import org.apache.pulsar.client.api.ConsumerConfiguration; | ||
|
||
public class PulsarConsumerKafkaConfig { | ||
|
||
/// Config variables | ||
public static final String CONSUMER_NAME = "pulsar.consumer.name"; | ||
public static final String RECEIVER_QUEUE_SIZE = "pulsar.consumer.receiver.queue.size"; | ||
public static final String TOTAL_RECEIVER_QUEUE_SIZE_ACROSS_PARTITIONS = "pulsar.consumer.total.receiver.queue.size.across.partitions"; | ||
|
||
public static ConsumerConfiguration getConsumerConfiguration(Properties properties) { | ||
ConsumerConfiguration conf = new ConsumerConfiguration(); | ||
|
||
if (properties.containsKey(CONSUMER_NAME)) { | ||
conf.setConsumerName(properties.getProperty(CONSUMER_NAME)); | ||
} | ||
|
||
if (properties.containsKey(RECEIVER_QUEUE_SIZE)) { | ||
conf.setReceiverQueueSize(Integer.parseInt(properties.getProperty(RECEIVER_QUEUE_SIZE))); | ||
} | ||
|
||
if (properties.containsKey(TOTAL_RECEIVER_QUEUE_SIZE_ACROSS_PARTITIONS)) { | ||
conf.setMaxTotalReceiverQueueSizeAcrossPartitions( | ||
Integer.parseInt(properties.getProperty(TOTAL_RECEIVER_QUEUE_SIZE_ACROSS_PARTITIONS))); | ||
} | ||
|
||
return conf; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...-kafka/src/main/java/org/apache/pulsar/client/kafka/compat/PulsarProducerKafkaConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.client.kafka.compat; | ||
|
||
import java.util.Properties; | ||
|
||
import org.apache.pulsar.client.api.ProducerConfiguration; | ||
|
||
public class PulsarProducerKafkaConfig { | ||
|
||
/// Config variables | ||
public static final String PRODUCER_NAME = "pulsar.producer.name"; | ||
public static final String INITIAL_SEQUENCE_ID = "pulsar.producer.initial.sequence.id"; | ||
|
||
public static final String MAX_PENDING_MESSAGES = "pulsar.producer.max.pending.messages"; | ||
public static final String MAX_PENDING_MESSAGES_ACROSS_PARTITIONS = "pulsar.producer.max.pending.messages.across.partitions"; | ||
public static final String BATCHING_ENABLED = "pulsar.producer.batching.enabled"; | ||
public static final String BATCHING_MAX_MESSAGES = "pulsar.producer.batching.max.messages"; | ||
|
||
public static ProducerConfiguration getProducerConfiguration(Properties properties) { | ||
ProducerConfiguration conf = new ProducerConfiguration(); | ||
|
||
if (properties.containsKey(PRODUCER_NAME)) { | ||
conf.setProducerName(properties.getProperty(PRODUCER_NAME)); | ||
} | ||
|
||
if (properties.containsKey(INITIAL_SEQUENCE_ID)) { | ||
conf.setInitialSequenceId(Long.parseLong(properties.getProperty(INITIAL_SEQUENCE_ID))); | ||
} | ||
|
||
if (properties.containsKey(MAX_PENDING_MESSAGES)) { | ||
conf.setMaxPendingMessages(Integer.parseInt(properties.getProperty(MAX_PENDING_MESSAGES))); | ||
} | ||
|
||
if (properties.containsKey(MAX_PENDING_MESSAGES_ACROSS_PARTITIONS)) { | ||
conf.setMaxPendingMessagesAcrossPartitions( | ||
Integer.parseInt(properties.getProperty(MAX_PENDING_MESSAGES_ACROSS_PARTITIONS))); | ||
} | ||
|
||
conf.setBatchingEnabled(Boolean.parseBoolean(properties.getProperty(BATCHING_ENABLED, "true"))); | ||
|
||
if (properties.containsKey(BATCHING_MAX_MESSAGES)) { | ||
conf.setBatchingMaxMessages(Integer.parseInt(properties.getProperty(BATCHING_MAX_MESSAGES))); | ||
} | ||
|
||
return conf; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters