You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2019/06/10 06:47:14 UTC

[GitHub] [pulsar] ambition119 opened a new pull request #4500: [Issue 4489] [Schema-AVRO] Unable to encode POJO class with byte[] fields

ambition119 opened a new pull request #4500: [Issue 4489] [Schema-AVRO] Unable to encode POJO class with byte[] fields
URL: https://github.com/apache/pulsar/pull/4500
 
 
   ### Motivation
   
   Fixes #4489
   
   ### Modifications
   
   1. upgrade avro.version to 1.9.0
   2. https://issues.apache.org/jira/browse/AVRO-1401
   
   ### Verifying this change
   
   Example run ok:
   ```java
   import lombok.Data;
   import org.apache.pulsar.client.api.Producer;
   import org.apache.pulsar.client.api.PulsarClient;
   import org.apache.pulsar.client.api.Schema;
   
   public class ProduceExample {
       public static void main(String[] args) throws Exception {
         try (PulsarClient client = PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build()) {
           Schema schema = Schema.AVRO(Foo.class);
   
           Producer producer = client.newProducer(schema).topic("test_src").create();
   
           producer.send(new Foo("12".getBytes(), true));
         }
   
         System.out.println("producer msg end ...");
       }
   
     @Data
     static class Foo {
       private byte[] bs;
       private boolean b;
       public Foo() {
       }
       public Foo(byte[] bs, boolean b) {
         this.bs = bs;
         this.b = b;
       }
     }
   }
   ```
   
   ```java
   import org.apache.pulsar.client.api.Consumer;
   import org.apache.pulsar.client.api.Message;
   import org.apache.pulsar.client.api.PulsarClient;
   import org.apache.pulsar.client.api.Schema;
   import org.apache.spark.streaming.receiver.example.ProduceExample.Foo;
   
   public class ConsumerExample {
     public static void main(String[] args) throws Exception {
       try (PulsarClient client = PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build()) {
         Schema sa = Schema.AVRO(ProduceExample.Foo.class);
         Consumer consumer = client.newConsumer(sa).topic("test_src").subscriptionName("test").subscribe();
         Message receive = consumer.receive();
         Object value = receive.getValue();
         if (value instanceof ProduceExample.Foo) {
           ProduceExample.Foo foo = (Foo) value;
           System.out.println(new String(foo.getBs()));
           System.out.println(foo.isB());
         }
       }
     }
   
   }
   ```
   
   stdout:
   ```shell
   log4j:WARN No appenders could be found for logger (io.netty.util.internal.logging.InternalLoggerFactory).
   log4j:WARN Please initialize the log4j system properly.
   log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
   12
   true
   
   Process finished with exit code 0
   ```
   
   
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services