我对AvroSchema存有疑问,我正在创建一个Java程序,其中的AvroSchema是一种模式。在这一行中,Producer producer = pulsarClient.newProducer(AvroSchema.of(Foo.class))。topic(“ test_topic “)。创建(); newProducer方法的第一个参数是schema,这里我们传递了一个Foo类的AvroSchema,但是它的给定错误AvroSchema无法解决。
import java.util.concurrent.TimeUnit;
import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.Message;
import org.apache.pulsar.client.api.Producer;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.api.PulsarClientException;
import org.apache.pulsar.client.api.SubscriptionType;
public class Test {
public static class Foo {
private int field1 = 1;
private String field2;
private long field3;
public void setField1(int i) {
// TODO Auto-generated method stub
field1 = i;
}
public void setField2(String string) {
// TODO Auto-generated method stub
field2 = string;
}
public void setField3(long currentTimeMillis) {
// TODO Auto-generated method stub
field3 = currentTimeMillis;
}
}
public static void main(String[] args) throws Exception {
PulsarClient pulsarClient = PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build();
Producer<Foo> producer = pulsarClient.newProducer(AvroSchema.of(Foo.class)).topic("test_topic").create();
for (int i = 0; i < 1000; i++) {
Foo foo = new Foo();
foo.setField1(i);
foo.setField2("foo" + i);
foo.setField3(System.currentTimeMillis());
producer.newMessage().value(foo).send();
}
producer.close();
pulsarClient.close();
}
}
我正在关注https://pulsar.apache.org/docs/en/sql-getting-started/ 该网址用于实现pulsar sql连接。 这是什么原因? 在此先感谢!!
答案 0 :(得分:0)
我在您的代码中看不到import org.apache.pulsar.client.impl.schema.AvroSchema;
,我认为这是问题所在。如果没有,您可以发布整个例外情况吗?