Skip to content

Instantly share code, notes, and snippets.

@sijie
sijie / delayed-message-code-example.md
Last active July 9, 2019 08:27
How to deliver messages after 3 minutes
producer.newMessage()
    .deliverAfter(3L, TimeUnit.Minute)
    .value("Hello Pulsar after 3 minutes!")
    .send();
@sijie
sijie / scheduled-message-example.md
Last active July 9, 2019 08:23
How to deliver messages at a given time
producer.newMessage()
    .deliverAt(new Date(2019, 06, 27, 23, 00, 00)
        .getTime())
    .value("Hello Pulsar at 11pm on 06/27/2019!")
    .send();
@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();
@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 / 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 / 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 / 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 / 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 / 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 / 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
);