The Pulsar client, attempting to produce or consume messages, failed because the schema of the data it was trying to send or receive didn’t match the schema registered for the topic.

Common Causes and Fixes

1. Schema Version Mismatch (Most Common)

  • Diagnosis: Check the schema version currently registered for the topic and compare it to the version the client is using.
    • Command: pulsar-admin schemas get my_tenant/my_namespace/my_topic
    • Fix: If the client is using an older, incompatible version, update the client’s schema to match the latest registered version or register a new compatible version.
      • Example (Registering New Compatible Schema): pulsar-admin schemas upload my_tenant/my_namespace/my_topic --filename new_schema.avsc
    • Why it works: Pulsar enforces schema compatibility. If a new schema is registered, it must be compatible with the existing one (e.g., adding optional fields, not removing required ones). The client must then use a schema version that is compatible with what’s currently on the broker.

2. Schema Evolution Policy Violation

  • Diagnosis: The schema evolution policy on the topic might be set to disallow the type of change that occurred between the client’s schema and the broker’s schema.
    • Command: pulsar-admin topics get-property my_tenant/my_namespace/my_topic --property schema.evolution.policy (This might not directly show the policy, but you can infer from the error. The default is BACKWARD.)
    • Fix: If the schema change was indeed incompatible (e.g., removing a required field, changing a field type), you need to either revert the schema change on the client or update the topic’s schema evolution policy to allow the change before applying it.
      • Example (Setting Policy to ALWAYS_COMPATIBLE temporarily): pulsar-admin topics set-property my_tenant/my_namespace/my_topic --property schema.evolution.policy=ALWAYS_COMPATIBLE
      • Example (Setting Policy to NONE - use with extreme caution): pulsar-admin topics set-property my_tenant/my_namespace/my_topic --property schema.evolution.policy=NONE
    • Why it works: The schema.evolution.policy (e.g., BACKWARD, FORWARD, FULL, NONE, ALWAYS_COMPATIBLE) dictates what types of schema modifications are permitted. Changing this policy, if appropriate, allows Pulsar to accept the new schema version. BACKWARD is common, meaning new schemas must be readable by old readers.

3. Client Using an Incorrect Schema (Typo/Misconfiguration)

  • Diagnosis: The client application is configured to use a schema that doesn’t actually exist for the topic, or it’s pointing to the wrong topic/namespace.
    • Check: Review the client’s configuration (e.g., producer.schema.name, consumer.schema.name, connection string, topic name in code).
    • Fix: Correct the client’s configuration to point to the correct topic and use the schema name that matches what’s registered on the broker.
      • Example (Java Producer Config):
        Producer<String> producer = pulsarClient.newProducer(Schema.STRING)
            .topic("persistent://my_tenant/my_namespace/my_topic")
            .create();
        
    • Why it works: Ensures the client is attempting to interact with the intended topic and its associated schema, resolving simple misconfigurations.

4. Schema Registry Issues (Less Common)

  • Diagnosis: The schema registry itself might be experiencing issues, preventing the client from fetching or validating the schema correctly. This is rare if Pulsar is otherwise healthy.
    • Check: Examine Pulsar broker logs for any errors related to schema registry communication or internal errors. Check the health of the schema registry service.
    • Fix: If the schema registry is indeed failing, restart the Pulsar brokers or the dedicated schema registry service if you have one configured separately.
    • Why it works: Restarts the potentially stalled or errored schema registry components, allowing clients to communicate with it successfully again.

5. Network Connectivity Between Client and Broker Schema Registry

  • Diagnosis: The client application cannot reach the Pulsar broker (or schema registry endpoint) to fetch schema information.
    • Check: Use ping or telnet from the client machine to the Pulsar broker’s schema port (default 8080 for HTTP API).
      • Command: telnet <pulsar_broker_host> 8080
    • Fix: Ensure firewalls are not blocking traffic, DNS is resolving correctly, and network routes are in place between the client and the Pulsar cluster’s schema API endpoint.
    • Why it works: Restores the necessary network path for the client to query and validate schemas against the Pulsar cluster.

6. Client Library Version Incompatibility

  • Diagnosis: An older or incompatible version of the Pulsar client library might not correctly interpret or handle schema evolution or registration.
    • Check: Verify the version of the Pulsar client library used in your application against the version of your Pulsar cluster.
    • Fix: Upgrade the Pulsar client library to a version that is compatible with your Pulsar cluster. Refer to the Pulsar documentation for compatibility matrices.
      • Example (Maven Dependency):
        <dependency>
            <groupId>org.apache.pulsar</groupId>
            <artifactId>pulsar-client-original</artifactId>
            <version>2.10.2</version> <!-- Use a recent, compatible version -->
        </dependency>
        
    • Why it works: Newer client versions often contain bug fixes and improvements for schema handling, ensuring correct interaction with the broker’s schema management.

The next error you’ll likely encounter if all schema issues are resolved is a serialization/deserialization problem if the data itself cannot be correctly converted to/from the schema type.

Want structured learning?

Take the full Pulsar course →