0

I have one doubt in AvroSchema, I am creating a java program which having a AvroSchema is a type of schema .In this line Producer producer = pulsarClient.newProducer(AvroSchema.of(Foo.class)).topic("test_topic").create(); first parameter of newProducer method is schema, here we are passing one AvroSchema of Foo class, but its giving error AvroSchema cannot be resolved.

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

I am following https://pulsar.apache.org/docs/en/sql-getting-started/ this url for implement a pulsar sql connectivity. What would be the reason for this issue ? Thanks in advance !!

Bhagesh Arora
  • 547
  • 2
  • 12
  • 30

1 Answers1

0

I don't see import org.apache.pulsar.client.impl.schema.AvroSchema; in your code, I think this is the problem. If not, can you post the whole exception please ?

Alexandre Cartapanis
  • 1,513
  • 3
  • 15
  • 19