Java Code Examples for org.apache.pulsar.client.api.SubscriptionInitialPosition#Latest

The following examples show how to use org.apache.pulsar.client.api.SubscriptionInitialPosition#Latest . 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: ConsumerConnector.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public ConsumerConnector(ConsumerConfig config) {
    checkNotNull(config, "ConsumerConfig can't be null");
    clientId = config.clientId();
    groupId = config.groupId();
    isAutoCommit = config.autoCommitEnable();
    if ("largest".equalsIgnoreCase(config.autoOffsetReset())) {
        strategy = SubscriptionInitialPosition.Latest;
    } else if ("smallest".equalsIgnoreCase(config.autoOffsetReset())) {
        strategy = SubscriptionInitialPosition.Earliest;
    }
    String consumerId = !config.consumerId().isEmpty() ? config.consumerId().get() : null;
    int maxMessage = config.queuedMaxMessages();
    String serviceUrl = config.zkConnect();

    Properties properties = config.props() != null && config.props().props() != null ? config.props().props()
            : new Properties();
    try {
        client = PulsarClientKafkaConfig.getClientBuilder(properties).serviceUrl(serviceUrl).build();
    } catch (PulsarClientException e) {
        throw new IllegalArgumentException(
                "Failed to create pulsar-client using url = " + serviceUrl + ", properties = " + properties, e);
    }

    topicStreams = Sets.newConcurrentHashSet();
    consumerBuilder = client.newConsumer();
    consumerBuilder.subscriptionName(groupId);
    if (properties.containsKey("queued.max.message.chunks") && config.queuedMaxMessages() > 0) {
        consumerBuilder.receiverQueueSize(maxMessage);
    }
    if (consumerId != null) {
        consumerBuilder.consumerName(consumerId);
    }
    if (properties.containsKey("auto.commit.interval.ms") && config.autoCommitIntervalMs() > 0) {
        consumerBuilder.acknowledgmentGroupTime(config.autoCommitIntervalMs(), TimeUnit.MILLISECONDS);
    }
    this.executor = Executors.newScheduledThreadPool(1, new DefaultThreadFactory("pulsar-kafka"));
}
 
Example 2
Source File: PulsarKafkaConsumer.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private SubscriptionInitialPosition getStrategy(final String strategy) {
    switch(strategy) {
	    case "earliest":
	        return SubscriptionInitialPosition.Earliest;
	    default:
            return SubscriptionInitialPosition.Latest;
	}
}
 
Example 3
Source File: PulsarKafkaConsumer.java    From pulsar with Apache License 2.0 5 votes vote down vote up
private SubscriptionInitialPosition getStrategy(final String strategy) {
    if ("earliest".equals(strategy)) {
        return SubscriptionInitialPosition.Earliest;
    } else {
        return SubscriptionInitialPosition.Latest;
    }
}