Apache-Pulsar 模式没有方法 builder()

Apache-Pulsar schema doesn't have method builder()

我正在尝试在 struct/SchemaDefinition 下复制示例 here。我想将消息的架构定义为名为 Davis 的 class,其定义如下:

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;
}

我已经从 Lombok project 导入了注释,我不知道这是否正确,但是 Pulsar 的文档在这里有点差..
我的制作人class是这样的

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();

    }
}

代码无法编译,因为 Davis 没有方法 builder()。我错过了什么?

我有另一种方法可以做到这一点。看看你是否喜欢这种风格:

https://github.com/tspannhw/StreamingAnalyticsUsingFlinkSQL/blob/main/src/main/java/IoTProducer.java

https://github.com/tspannhw/StreamingAnalyticsUsingFlinkSQL/blob/main/src/main/java/IoTMessage.java

要在一个地点与所有 Pulsar 人会面,请报名参加峰会

https://streamnative.io/en/blog/community/2021-09-07-speakers-announced-for-pulsar-virtual-summit-europe-2021/

问题是 Lombok 项目未作为 compileOnly 依赖项包含在 Gradle (v7.1) 中。

找到了答案