Search in sources :

Example 1 with UniformRangeGenerator

use of org.apache.flink.connector.pulsar.source.enumerator.topic.range.UniformRangeGenerator in project flink by apache.

the class PulsarSourceBuilder method build.

/**
 * Build the {@link PulsarSource}.
 *
 * @return a PulsarSource with the settings made for this builder.
 */
@SuppressWarnings("java:S3776")
public PulsarSource<OUT> build() {
    // Ensure the topic subscriber for pulsar.
    checkNotNull(subscriber, "No topic names or topic pattern are provided.");
    SubscriptionType subscriptionType = configBuilder.get(PULSAR_SUBSCRIPTION_TYPE);
    if (subscriptionType == SubscriptionType.Key_Shared) {
        if (rangeGenerator == null) {
            LOG.warn("No range generator provided for key_shared subscription," + " we would use the UniformRangeGenerator as the default range generator.");
            this.rangeGenerator = new UniformRangeGenerator();
        }
    } else {
        // Override the range generator.
        this.rangeGenerator = new FullRangeGenerator();
    }
    if (boundedness == null) {
        LOG.warn("No boundedness was set, mark it as a endless stream.");
        this.boundedness = Boundedness.CONTINUOUS_UNBOUNDED;
    }
    if (boundedness == Boundedness.BOUNDED && configBuilder.get(PULSAR_PARTITION_DISCOVERY_INTERVAL_MS) >= 0) {
        LOG.warn("{} property is overridden to -1 because the source is bounded.", PULSAR_PARTITION_DISCOVERY_INTERVAL_MS);
        configBuilder.override(PULSAR_PARTITION_DISCOVERY_INTERVAL_MS, -1L);
    }
    checkNotNull(deserializationSchema, "deserializationSchema should be set.");
    // Enable transaction if the cursor auto commit is disabled for Key_Shared & Shared.
    if (FALSE.equals(configBuilder.get(PULSAR_ENABLE_AUTO_ACKNOWLEDGE_MESSAGE)) && (subscriptionType == SubscriptionType.Key_Shared || subscriptionType == SubscriptionType.Shared)) {
        LOG.info("Pulsar cursor auto commit is disabled, make sure checkpoint is enabled " + "and your pulsar cluster is support the transaction.");
        configBuilder.override(PULSAR_ENABLE_TRANSACTION, true);
        if (!configBuilder.contains(PULSAR_READ_TRANSACTION_TIMEOUT)) {
            LOG.warn("The default pulsar transaction timeout is 3 hours, " + "make sure it was greater than your checkpoint interval.");
        } else {
            Long timeout = configBuilder.get(PULSAR_READ_TRANSACTION_TIMEOUT);
            LOG.warn("The configured transaction timeout is {} mille seconds, " + "make sure it was greater than your checkpoint interval.", timeout);
        }
    }
    if (!configBuilder.contains(PULSAR_CONSUMER_NAME)) {
        LOG.warn("We recommend set a readable consumer name through setConsumerName(String) in production mode.");
    }
    // Since these implementation could be a lambda, make sure they are serializable.
    checkState(isSerializable(startCursor), "StartCursor isn't serializable");
    checkState(isSerializable(stopCursor), "StopCursor isn't serializable");
    checkState(isSerializable(rangeGenerator), "RangeGenerator isn't serializable");
    // Check builder configuration.
    SourceConfiguration sourceConfiguration = configBuilder.build(SOURCE_CONFIG_VALIDATOR, SourceConfiguration::new);
    return new PulsarSource<>(sourceConfiguration, subscriber, rangeGenerator, startCursor, stopCursor, boundedness, deserializationSchema);
}
Also used : SubscriptionType(org.apache.pulsar.client.api.SubscriptionType) FullRangeGenerator(org.apache.flink.connector.pulsar.source.enumerator.topic.range.FullRangeGenerator) UniformRangeGenerator(org.apache.flink.connector.pulsar.source.enumerator.topic.range.UniformRangeGenerator) SourceConfiguration(org.apache.flink.connector.pulsar.source.config.SourceConfiguration)

Example 2 with UniformRangeGenerator

use of org.apache.flink.connector.pulsar.source.enumerator.topic.range.UniformRangeGenerator in project flink by apache.

the class PulsarSourceBuilderTest method rangeGeneratorRequiresKeyShared.

@Test
void rangeGeneratorRequiresKeyShared() {
    PulsarSourceBuilder<String> builder = new PulsarSourceBuilder<>();
    builder.setSubscriptionType(SubscriptionType.Shared);
    UniformRangeGenerator rangeGenerator = new UniformRangeGenerator();
    assertThatThrownBy(() -> builder.setRangeGenerator(rangeGenerator)).isInstanceOf(IllegalArgumentException.class);
}
Also used : UniformRangeGenerator(org.apache.flink.connector.pulsar.source.enumerator.topic.range.UniformRangeGenerator) Test(org.junit.jupiter.api.Test)

Aggregations

UniformRangeGenerator (org.apache.flink.connector.pulsar.source.enumerator.topic.range.UniformRangeGenerator)2 SourceConfiguration (org.apache.flink.connector.pulsar.source.config.SourceConfiguration)1 FullRangeGenerator (org.apache.flink.connector.pulsar.source.enumerator.topic.range.FullRangeGenerator)1 SubscriptionType (org.apache.pulsar.client.api.SubscriptionType)1 Test (org.junit.jupiter.api.Test)1