BewareMyPower commented on issue #7728:
URL: https://github.com/apache/pulsar/issues/7728#issuecomment-699799122


   It looks like there's some wrong when broker handles subscribe request. 
Here's my test code:
   
   ```java
       final static String serviceUrl = "pulsar://localhost:6650";
       final static String webServiceUrl = "http://localhost:8080";;
   
       static void checkSchema(String topic) {
           try (PulsarAdmin admin = 
PulsarAdmin.builder().serviceHttpUrl(webServiceUrl).build()) {
               System.out.println("schema of " + topic + ": " + 
admin.schemas().getSchemaInfo(topic));
           } catch (PulsarClientException | PulsarAdminException e) {
               System.err.println("getSchemaInfo failed for " + topic + ": " + 
e.getMessage());
           }
       }
   
       static void producerNoSchemaToCheck(String topic) {
           try (PulsarClient client = 
PulsarClient.builder().serviceUrl(serviceUrl).build()) {
               // 1. byte[] (without schema)
               try (Producer<byte[]> producer = 
client.newProducer(Schema.BYTES).topic(topic).create()) {
                   System.out.println("Producer<byte[]>: " + 
producer.getProducerName());
               }
               checkSchema(topic);
               // 2. String (with schema) => OK
               try (Producer<String> producer = 
client.newProducer(Schema.STRING).topic(topic).create()) {
                   System.out.println("Producer<String>: " + 
producer.getProducerName());
               }
               checkSchema(topic);
           } catch (PulsarClientException e) {
               e.printStackTrace();
           }
       }
   
       static void consumerNoSchemaToCheck(String topic) {
           try (PulsarClient client = 
PulsarClient.builder().serviceUrl(serviceUrl).build()) {
               // 1. byte[] (without schema)
               try (Consumer<byte[]> consumer = 
client.newConsumer(Schema.BYTES).topic(topic).subscriptionName("my-sub").subscribe())
 {
                   System.out.println("Consumer<byte[]>: " + 
consumer.getConsumerName());
               }
               checkSchema(topic);
               // 2. String (with schema) => Topic does not have schema to check
               try (Consumer<String> consumer = 
client.newConsumer(Schema.STRING).topic(topic).subscriptionName("my-sub").subscribe())
 {
                   System.out.println("Consumer<String>: " + 
consumer.getConsumerName());
               }
               checkSchema(topic);
           } catch (PulsarClientException e) {
               e.printStackTrace();
           }
       }
   
       public static void main(String[] args) {
           long t = System.currentTimeMillis();
           consumerNoSchemaToCheck("my-topic-" + t);
           producerNoSchemaToCheck("my-topic-" + (t + 1));
       }
   ```
   
   The output:
   
   ```
   Consumer<byte[]>: b1669
   getSchemaInfo failed for my-topic-1601273689739: HTTP 404 Not Found
   
org.apache.pulsar.client.api.PulsarClientException$IncompatibleSchemaException: 
Topic does not have schema to check
        at 
org.apache.pulsar.client.api.PulsarClientException.unwrap(PulsarClientException.java:862)
        at 
org.apache.pulsar.client.impl.ConsumerBuilderImpl.subscribe(ConsumerBuilderImpl.java:101)
        at SchemaDemo.consumerNoSchemaToCheck(SchemaDemo.java:46)
        at SchemaDemo.main(SchemaDemo.java:57)
   Producer<byte[]>: standalone-0-24
   getSchemaInfo failed for my-topic-1601273689740: HTTP 404 Not Found
   Producer<String>: standalone-0-25
   schema of my-topic-1601273689740: {
     "name": "my-topic-1601273689740",
     "schema": "",
     "type": "STRING",
     "properties": {}
   }
   ```
   
   - consumer:
     1. Create a `Consumer<byte[]>` to create a new topic and subscribe it;
     2. Check the schema: 404;
     3. Create a `Consumer<String>` to subscribe the same topic, **failed: 
Topic does not have schema to check**.
   - producer:
     1. Create a `Producer<byte[]>` to create a new topic;
     2. Check the schema: 404;
     3. Create a `Producer<String>` to specify the same topic;
     4. Check the schema: STRING.
     


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to