Xiaomi Galaxy Talos Book

Simple API


Simple Producer API

SimpleProducer is for the purpose of providing users with a synchronous put interface; the user needs to specify partitionId when using it; each SimpleProducer corresponds to a partition; it is best recommended that the user send the batch when using the synchronous interface, so the interface parameter is the List type;

putMessage(List<Message> messageList)

Parameter: messageList, the function accepts a Message List and sends it to the partition specified by the user when the SimpleProducer is initialized;

Return value: boolean, function returns whether putMessage succeeds or not;

Simple Consumer API

SimpleProducer is the synchronous interface for consumer data; the user using simple consumer needs to specify partition, specify startOffset to get data:

Please note: When using simple consumer, the user needs to deal with the consumer allocation of the partition and the consumer failover issues. At the same time, the user needs to record the consumption offset and commit by himself.

fetchMessage(long startOffset)

Parameter: startOffset specifies where to start pulling data, including startOffset

Return value: List<MessageAndOffset>, which returns a list; the member is MessageAndOffset object instance

Exception: Same as next interface

fetchMessage(long startOffset, int maxFetchedNumber)

Parameter:

  • startOffset specifies where to start pulling data, including startOffset
  • maxFetchednumber specifies the maximum number of messages for a single time of batch pulling. If no value is assigned, the above interface is used, and by default, one goes to the configuration in the consumer config GALAXY_TALOS_CONSUMER_MAX_FETCH_RECORDS

Return value: List<MessageAndOffset>, which returns a list; the member is MessageAndOffset object instance

Exception:

  • TException, the error returned from the server side, may be PARTITION_NOT_SERVING, MESSAGE_OFFSET_OUT_OF_RANGE, or other exceptions. For more specific information, one may look at the stack information, and then it may be handled differently depending on the situation, for example, if it is PARTITION_NOT_SERVING, you can sleep to delay for a while; if it is MESSAGE_OFFSET_OUT_OF_RANGE, you need to modify startOffset;

  • IOException may be a compression error; for more specific information, look at the stack information