// ѡ���broker�ڵ�ij������
partition =
this.producerZooKeeper.selectPartition(topic, message, this.partitionSelector, serverUrl);
if (partition == null) {
// û�п��÷������׳��쳣
throw new MetaClientException("There is no partitions in `" + serverUrl
+ "` to send message with topic `" + topic + "` in a transaction");
}
}
}
if (partition == null) {
partition = this.selectPartition(message);
}
if (partition == null) {
throw new MetaClientException("There is no aviable partition for topic " + topic
+ ",maybe you don't publish it at first?");
}
if (serverUrl == null) {
serverUrl = this.producerZooKeeper.selectBroker(topic, partition);
}
if (serverUrl == null) {
throw new MetaClientException("There is no aviable server right now for topic " + topic
+ " and partition " + partition + ",maybe you don't publish it at first?");
}
if (this.isInTransaction() && this.lastSentInfo.get() == null) {
// ��һ�η��ͣ���Ҫ��������
this.beforeSendMessageFirstTime(serverUrl);
}
final int flag = MessageFlagUtils.getFlag(message);
final PutCommand putCommand =
new PutCommand(topic, partition.getPartition(), encodedData, flag, CheckSum.crc32(encodedData),
this.getTransactionId(), OpaqueGenerator.getNextOpaque());
final BooleanCommand resp = this.invokeToGroup(serverUrl, partition, putCommand, message, timeout, unit);
return this.genSendResult(message, partition, serverUrl, resp);
}
catch (final TimeoutException e) {
throw new MetaOpeartionTimeoutException("Send message timeout in "
+ TimeUnit.MILLISECONDS.convert(timeout, unit) + " mills");
}
catch (final InterruptedException e) {
throw e;
}
catch (final MetaClientException e) {
throw e;
}
catch (final Exception e) {
throw new MetaClientException("send message failed", e);
}
}