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/05/22 13:40:59 UTC

[GitHub] [pulsar] wolfstudy opened a new issue #4339: [go client] max message size error

wolfstudy opened a new issue #4339: [go client] max message size error
URL: https://github.com/apache/pulsar/issues/4339
 
 
   **Describe the bug**
   
   Encountered a very magical problem, when I use java-client to send data, the maximum size of the message is `MaxMessageSize=5 * 1024 * 1024 - 10 * 1024` can be sent normally, as follows:
   
   ```
   import java.util.concurrent.TimeUnit;
   
   import org.apache.pulsar.client.api.Consumer;
   import org.apache.pulsar.client.api.Message;
   import org.apache.pulsar.client.api.Producer;
   import org.apache.pulsar.client.api.PulsarClient;
   import org.apache.pulsar.client.api.PulsarClientException;
   import org.apache.pulsar.client.api.SubscriptionInitialPosition;
   
   public class MsgSizeTests {
       public static void main(String[] args) throws PulsarClientException, InterruptedException {
           PulsarClient client = PulsarClient.builder().serviceUrl("pulsar://localhost:6650").build();
           Producer producer = client.newProducer().topic("test1").enableBatching(false).create();
   
           Consumer consumer =
                   client.newConsumer().topic("test1").subscriptionName("test-sub").subscriptionInitialPosition(
                           SubscriptionInitialPosition.Latest).subscribe();
   
           byte[] msg = new byte[5 * 1024 * 1024 - 10 * 1024];
           System.out.println(new String(msg));
           try {
               System.out.println("sending over....");
               producer.send(msg);
           } catch (PulsarClientException e) {
               e.printStackTrace();
           }
           System.out.println("sending....");
           TimeUnit.SECONDS.sleep(1);
           Message message = null;
           try {
               message = consumer.receive();
           } catch (PulsarClientException e) {
               e.printStackTrace();
           }
           System.out.println("receive....");
           TimeUnit.SECONDS.sleep(1);
           System.out.println(new String((byte[]) message.getValue()));
           if (message.getValue().equals(msg)) {
               System.out.println(new String((byte[]) message.getValue()));
               System.out.println("error");
           }
   
           producer.close();
           consumer.unsubscribe();
           consumer.close();
           client.close();
       }
   }
   ```
   
   When I send it using `pulsar-client-go`,  will tell me `MessageTooBig`, code as follows:
   
   ```
   func main() {
   	client, err := pulsar.NewClient(pulsar.ClientOptions{
   		URL:       "pulsar://localhost:6650",
   		IOThreads: 5,
   	})
   
   	if err != nil {
   		log.Fatal(err)
   	}
   
   	defer client.Close()
   
   	producer, err := client.CreateProducer(pulsar.ProducerOptions{
   		Topic:           "my-topic",
   		CompressionType: pulsar.NoCompression,
   		//Batching: false,
   	})
   	if err != nil {
   		log.Fatal(err)
   	}
   
   	defer producer.Close()
   
   	ctx := context.Background()
   	buf := make([]byte, 10*1024*1024)
   	arrays := [1024*1024*5 - 10*1024 - 20]byte{}
   	buf = arrays[:]
   	fmt.Println(len(buf))
   
   	producer.SendAsync(ctx, pulsar.ProducerMessage{
   		Payload: buf,
   	}, func(producerMessage pulsar.ProducerMessage, e error) {
   		fmt.Print("send complete. err=", e)
   	})
   }
   ```
   
   error as follows:
   
   ```
   send complete. err=Failed to send message: MessageTooBig
   ```
   
   error location as follows:
   
   **c_producer.go #line:252**
   ```
   //export pulsarProducerSendCallbackProxy
   func pulsarProducerSendCallbackProxy(res C.pulsar_result, message *C.pulsar_message_t, ctx unsafe.Pointer) {
   	sendCallback := restorePointer(ctx).(sendCallback)
   
   	if res != C.pulsar_result_Ok {
   		sendCallback.callback(sendCallback.message, newError(res, "Failed to send message"))
   	} else {
   		sendCallback.callback(sendCallback.message, nil)
   	}
   }
   ```
   
   When I continue to try to reduce the size of the message until `arrays := [1024*1024*5 - 10*1024 - 20]byte{}`, the message can be sent normally. What I can't explain is that what 20 bytes are used for.
   
   At first I guess it might be the reason for batch, but opening and closing the batch is the same effect.
   

----------------------------------------------------------------
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