Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bash
#
# 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
#
@sijie
sijie / kafka-source-exclamation-function.md
Created August 2, 2019 08:26
Kafka source with a String function example
protected void testKafkaSourcePulsarFunction(TopicName pulsarTopic) throws Exception {
    final String tenantName = pulsarTopic.getTenant();
    final String namespaceName = pulsarTopic.getNamespacePortion();

    // create kafka topic
    final String kafkaTopic = "test-kafka-source-pulsar-function-" + Base58.randomString(8);
    final NewTopic newKafkaTopic = new NewTopic(kafkaTopic, 1, (short) 1);
    kafkaAdmin.createTopics(
        Sets.newHashSet(newKafkaTopic),

new CreateTopicsOptions()

@sijie
sijie / key-value-schema-example.md
Created July 9, 2019 07:39
KeyValue Schema Example
Schema<KeyValue<Integer, String>> kvSchema = Schema.KeyValue(
    Schema.INT32,
    Schema.STRING,
    KeyValueEncodingType.SEPARATED
);
@sijie
sijie / auto-consume-example.md
Created July 9, 2019 07:38
AutoConsume Example
Consumer<GenericRecord> pulsarConsumer = client.newConsumer(Schema.AUTO_CONSUME())
    …
    .subscribe();
Message<GenericRecord> msg = consumer.receive() ;
GenericRecord record = msg.getValue();
@sijie
sijie / generic-record-example.md
Created July 9, 2019 07:37
Generic Record Example
Producer<GenericRecord> producer = client.newProducer(Schema.generic(schemaInfo)).create();
producer.newMessage()
    .value(schema.newRecordBuilder()
        .set("intField", 32)
        .build())
    .send();
@sijie
sijie / generic-schema-example.md
Created July 9, 2019 07:36
Generic Schema Example
RecordSchemaBuilder recordSchemaBuilder = SchemaBuilder.record("schemaName");
recordSchemaBuilder
    .field("intField")
    .type(SchemaType.INT32);
SchemaInfo schemaInfo = recordSchemaBuilder.build(SchemaType.AVRO);
Schema<GenericRecord> schema = Schema.generic(schemaInfo);
@sijie
sijie / compatibility-check-strategies.md
Last active July 9, 2019 07:34
Pulsar schema compatibility check strategies
Compatibility Check Strategy Changes allowed Check against which schemas Upgrade first
ALWAYS_INCOMPATIBLE All changes are disabled All previous versions None
ALWAYS_COMPATIBLE All changes are allowed Compatibility checking disabled Depends
BACKWARD Delete fields; Add optional fields Latest version Consumers
BACKWARD_TRANSITIVE Delete fields; Add optional fields All previous versions Consumers
FORWARD Add fields; Delete optional fields Latest version Producers
FORWARD_TRANSITIVE Add fields; Delete optional fields All previous versions Producers
FULL Modify optional fields Latest version Any order
FULL_TRANSITIVE Modify optional fields All previous versions Any order
@sijie
sijie / go-function-example.md
Created July 9, 2019 07:26
Pulsar Go Function example
import (
  "fmt"
  "context"
  "github.com/apache/pulsar/pulsar-function-go/pf"
)

func HandleRequest(ctx context.Context, in []byte) error {
  fmt.Println(string(in) + "!")
 return nil
@sijie
sijie / replicated-subscription-example.md
Created July 9, 2019 07:22
Replicated Subscription Example
Consumer<String> consumer = client.newConsumer(Schema.STRING)
    .topic("my-topic")
    .subscriptionName("my-subscription")
    .replicateSubscriptionState(true)
    .subscribe();
@sijie
sijie / key-shared-subscription.md
Created July 9, 2019 07:17
Key_Shared Subscription Example
client.newConsumer()
    .topic("topic")
    .subscriptionType(SubscriptionType.Key_Shared)
    .subscriptionName("key-shared-subscription")
    .subscribe();