Search in sources :

Example 1 with PulsarDeserializationSchemaInitializationContext

use of org.apache.flink.connector.pulsar.source.reader.deserializer.PulsarDeserializationSchemaInitializationContext in project flink by apache.

the class PulsarSource method createReader.

@Internal
@Override
public SourceReader<OUT, PulsarPartitionSplit> createReader(SourceReaderContext readerContext) throws Exception {
    // Initialize the deserialization schema before creating the pulsar reader.
    PulsarDeserializationSchemaInitializationContext initializationContext = new PulsarDeserializationSchemaInitializationContext(readerContext);
    deserializationSchema.open(initializationContext, sourceConfiguration);
    return PulsarSourceReaderFactory.create(readerContext, deserializationSchema, sourceConfiguration);
}
Also used : PulsarDeserializationSchemaInitializationContext(org.apache.flink.connector.pulsar.source.reader.deserializer.PulsarDeserializationSchemaInitializationContext) Internal(org.apache.flink.annotation.Internal)

Example 2 with PulsarDeserializationSchemaInitializationContext

use of org.apache.flink.connector.pulsar.source.reader.deserializer.PulsarDeserializationSchemaInitializationContext in project flink by apache.

the class PulsarSourceReaderTestBase method sourceReader.

private PulsarSourceReaderBase<Integer> sourceReader(boolean autoAcknowledgementEnabled, SubscriptionType subscriptionType) {
    Configuration configuration = operator().config();
    configuration.set(PULSAR_MAX_FETCH_RECORDS, 1);
    configuration.set(PULSAR_MAX_FETCH_TIME, 1000L);
    configuration.set(PULSAR_SUBSCRIPTION_NAME, randomAlphabetic(10));
    configuration.set(PULSAR_SUBSCRIPTION_TYPE, subscriptionType);
    if (autoAcknowledgementEnabled || configuration.get(PULSAR_SUBSCRIPTION_TYPE) == SubscriptionType.Shared) {
        configuration.set(PULSAR_ENABLE_AUTO_ACKNOWLEDGE_MESSAGE, true);
    }
    PulsarDeserializationSchema<Integer> deserializationSchema = pulsarSchema(Schema.INT32);
    SourceReaderContext context = new TestingReaderContext();
    try {
        deserializationSchema.open(new PulsarDeserializationSchemaInitializationContext(context), mock(SourceConfiguration.class));
    } catch (Exception e) {
        fail("Error while opening deserializationSchema");
    }
    SourceConfiguration sourceConfiguration = new SourceConfiguration(configuration);
    return (PulsarSourceReaderBase<Integer>) PulsarSourceReaderFactory.create(context, deserializationSchema, sourceConfiguration);
}
Also used : SourceConfiguration(org.apache.flink.connector.pulsar.source.config.SourceConfiguration) Configuration(org.apache.flink.configuration.Configuration) PulsarDeserializationSchemaInitializationContext(org.apache.flink.connector.pulsar.source.reader.deserializer.PulsarDeserializationSchemaInitializationContext) SourceConfiguration(org.apache.flink.connector.pulsar.source.config.SourceConfiguration) TestingReaderContext(org.apache.flink.connector.testutils.source.reader.TestingReaderContext) SourceReaderContext(org.apache.flink.api.connector.source.SourceReaderContext) PulsarAdminException(org.apache.pulsar.client.admin.PulsarAdminException) ParameterResolutionException(org.junit.jupiter.api.extension.ParameterResolutionException)

Aggregations

PulsarDeserializationSchemaInitializationContext (org.apache.flink.connector.pulsar.source.reader.deserializer.PulsarDeserializationSchemaInitializationContext)2 Internal (org.apache.flink.annotation.Internal)1 SourceReaderContext (org.apache.flink.api.connector.source.SourceReaderContext)1 Configuration (org.apache.flink.configuration.Configuration)1 SourceConfiguration (org.apache.flink.connector.pulsar.source.config.SourceConfiguration)1 TestingReaderContext (org.apache.flink.connector.testutils.source.reader.TestingReaderContext)1 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)1 ParameterResolutionException (org.junit.jupiter.api.extension.ParameterResolutionException)1