Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

sguzzo avatar image
sguzzo asked Erick Ramirez edited

Apache Pulsar schema doesn't have method builder()

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?

astra streaming
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

sguzzo avatar image
sguzzo answered

The issue was that Lombok Project was not included as a compileOnly dependency in Gradle (v7.1).

Found the answer at https://stackoverflow.com/a/55227788/14314060

Share
10 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.