pulsar sink 示例

[onnectors]# cat avro-schema
{
  "type": "AVRO",
  "schema": "{\"type\":\"record\",\"name\":\"Test\",\"fields\":[{\"name\":\"id\",\"type\":\"int\"},{\"name\":\"name\",\"type\":[\"null\",\"string\"]}]}",
  "properties": {}
}



[onnectors]# cat pconfigjson
configs:
  userName: "postgres"
  password: "123456"
  jdbcUrl: "jdbc:postgresql://127.0.0.1:5432/postgres"
  tableName: "pulsar_postgres_jdbc_sink"
 
 
 ./bin/pulsar-admin sinks delete --tenant public --namespace default --name psink
 
 ./bin/pulsar-admin schemas delete pxtopic
 
./bin/pulsar-admin schemas upload  -f ./connectors/avro-schema pxtopic

./bin/pulsar-admin schemas get pxtopic


./bin/pulsar-admin sinks create \
--archive ./connectors/pulsar-io-jdbc-postgres-2.6.1.nar \
--inputs pxtopic\
  --name psink \
--sink-config-file ./connectors/pconfigjson \
--parallelism 1

 

 

pg数据表

 

 

发送代码:

 static void xrun2() {
class Test {
int id;
String name;
}
PulsarClient client = null;
try {
client = PulsarClient.builder()
.serviceUrl("pulsar://192.168.0.10:6650")
.build();
String xtopic = "persistent://public/default/pxtopic";

Producer producerx = client.newProducer(Schema.AVRO(Test.class))
.topic(xtopic)
.create();

int xx = 10000;
while (xx++ < 13000) {
try {
Test o = new Test();
o.id = xx;
o.name = "this is a test " + xx ;
producerx.sendAsync(o);
} catch (Exception e) {
e.printStackTrace();
}
}
}
catch (Exception e){
e.printStackTrace();
}
System.err.println("done !!!!");
}

 

posted @ 2020-09-17 13:01  大大唐  阅读(364)  评论(0)    收藏  举报