I have encountered schema problems recently. eg, creating a consumer with Schema.STRING:
try (PulsarClient client = PulsarClient.builder() //
.serviceUrl("pulsar://localhost:6650") //
.build()) {
try (Consumer<String> consumer = client.newConsumer(Schema.STRING) //
.topic("Foo") //
.subscriptionName("test-sub") //
.subscriptionInitialPosition(SubscriptionInitialPosition.Earliest) //
.subscribe()) {
log.info("Subscribe successfully");
}
} catch (PulsarClientException e) {
log.error("{}", e.getMessage(), e);
}
The log is:
org.apache.pulsar.client.api.PulsarClientException$IncompatibleSchemaException: Topic does not have schema to check
Finally I found some topics may not have associated schema, see SchemaRegistryServiceImpl in broker.service.schema package:
public CompletableFuture<Void> checkConsumerCompatibility(String schemaId, SchemaData schemaData,
SchemaCompatibilityStrategy strategy) {
return getSchema(schemaId).thenCompose(existingSchema -> {
if (existingSchema != null && !existingSchema.schema.isDeleted()) {
// ...
} else { // existingSchema is null or it's deleted
return FutureUtil.failedFuture(new IncompatibleSchemaException("Topic does not have schema to check"));
}
});
}
I thought it's because those topics have been produced by C++ client without schema. But it seems that I'm wrong. I created a new topic and used C++ client to produce some messages, but a consumer with string schema subscribed successfully. I've also trying producing some messages with Java producer without schema, but the result were the same.
In my private cluster for test, there're still 2 topics that couldn't be subscribed with string schema. But I didn't know how did I make it happen.
I have encountered schema problems recently. eg, creating a consumer with
Schema.STRING:The log is:
Finally I found some topics may not have associated schema, see
SchemaRegistryServiceImplinbroker.service.schemapackage:I thought it's because those topics have been produced by C++ client without schema. But it seems that I'm wrong. I created a new topic and used C++ client to produce some messages, but a consumer with string schema subscribed successfully. I've also trying producing some messages with Java producer without schema, but the result were the same.
In my private cluster for test, there're still 2 topics that couldn't be subscribed with string schema. But I didn't know how did I make it happen.