I am trying to replicate the example here, under struct/SchemaDefinition. I would like to define the schema for my messages into a class called Davis
which is defined as follows:
package com.example.streaming; import lombok.Builder; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import java.sql.Timestamp; @Builder @AllArgsConstructor @NoArgsConstructor public class Davis { Timestamp timestamp; float temperature; }
I have imported the annotations from the Lombok project and I don't know if this is correct but Pulsar's documentation is a bit poor here. My producer class is something like this
import org.apache.pulsar.client.api.*; import org.apache.pulsar.client.impl.schema.JSONSchema; import java.io.IOException; public class DavisProducer { public static void main(String[] args) throws IOException { PulsarGetPropertyValues properties = new PulsarGetPropertyValues(); properties.getPropValues(); PulsarClient client = PulsarClient.builder() .serviceUrl(properties.getProperty("pulsar.service_url")) .authentication( AuthenticationFactory.token(properties.getProperty("pulsar.token")) ) .build(); Producer<Davis> producer = client.newProducer(JSONSchema.of(Davis.class)) .topic(properties.getProperty("pulsar.topic")) .create(); // Send a message to the topic producer.newMessage().value(Davis.builder() .timestamp(sometimestamp) .temp_out((float) 18.5556) .build()).send(); producer.close(); client.close(); } }
The code won't compile because Davis
doesn't have the method builder()
. What am I missing?