public static MessageId fromByteArrayWithTopic(byte[] data, TopicName topicName) throws IOException { checkNotNull(data); ByteBufCodedInputStream inputStream = ByteBufCodedInputStream.get(Unpooled.wrappedBuffer(data, 0, data.length)); PulsarApi.MessageIdData.Builder builder = PulsarApi.MessageIdData.newBuilder(); PulsarApi.MessageIdData idData; try { idData = builder.mergeFrom(inputStream, null).build(); } catch (UninitializedMessageException e) { throw new IOException(e); } MessageId messageId; if (idData.hasBatchIndex()) { messageId = new BatchMessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition(), idData.getBatchIndex()); } else { messageId = new MessageIdImpl(idData.getLedgerId(), idData.getEntryId(), idData.getPartition()); } if (idData.getPartition() > -1 && topicName != null) { messageId = new TopicMessageIdImpl( topicName.getPartition(idData.getPartition()).toString(), topicName.toString(), messageId); } inputStream.recycle(); builder.recycle(); idData.recycle(); return messageId; }
protected byte[] toByteArray(int batchIndex) { MessageIdData.Builder builder = MessageIdData.newBuilder(); builder.setLedgerId(ledgerId); builder.setEntryId(entryId); if (partitionIndex >= 0) { builder.setPartition(partitionIndex); } if (batchIndex != -1) { builder.setBatchIndex(batchIndex); } MessageIdData msgId = builder.build(); int size = msgId.getSerializedSize(); ByteBuf serialized = Unpooled.buffer(size, size); ByteBufCodedOutputStream stream = ByteBufCodedOutputStream.get(serialized); try { msgId.writeTo(stream); } catch (IOException e) { // This is in-memory serialization, should not fail throw new RuntimeException(e); } msgId.recycle(); builder.recycle(); stream.recycle(); return serialized.array(); }
handleAck(ack); for (int i = 0; i < ack.getMessageIdCount(); i++) { ack.getMessageId(i).recycle();
final boolean isDurable = subscribe.getDurable(); final MessageIdImpl startMessageId = subscribe.hasStartMessageId() ? new BatchMessageIdImpl( subscribe.getStartMessageId().getLedgerId(), subscribe.getStartMessageId().getEntryId(), subscribe.getStartMessageId().getPartition(), subscribe.getStartMessageId().getBatchIndex()) : null; final String subscription = subscribe.getSubscription();
void messageReceived(MessageIdData messageId, int redeliveryCount, ByteBuf headersAndPayload, ClientCnx cnx) { if (log.isDebugEnabled()) { log.debug("[{}][{}] Received message: {}/{}", topic, subscription, messageId.getLedgerId(), messageId.getEntryId()); MessageIdImpl msgId = new MessageIdImpl(messageId.getLedgerId(), messageId.getEntryId(), getPartitionIndex()); if (acknowledgmentsGroupingTracker.isDuplicate(msgId)) { if (log.isDebugEnabled()) {
org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData.Builder subBuilder = org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData.newBuilder(); if (hasStartMessageId()) { subBuilder.mergeFrom(getStartMessageId());
MessageIdImpl batchMessage = new MessageIdImpl(messageId.getLedgerId(), messageId.getEntryId(), getPartitionIndex()); BatchMessageAcker acker = BatchMessageAcker.newAcker(batchSize); && messageId.getLedgerId() == startMessageId.getLedgerId() && messageId.getEntryId() == startMessageId.getEntryId() && i <= startMessageId.getBatchIndex()) { BatchMessageIdImpl batchMessageIdImpl = new BatchMessageIdImpl(messageId.getLedgerId(), messageId.getEntryId(), getPartitionIndex(), i, acker); final MessageImpl<T> message = new MessageImpl<>(topicName.toString(), batchMessageIdImpl, msgMetadata, singleMessageMetadataBuilder.build(), singleMessagePayload,
} else { MessageIdData.Builder builder = MessageIdData.newBuilder(); builder.setLedgerId(startMessageId.getLedgerId()); builder.setEntryId(startMessageId.getEntryId()); consumerName, isDurable, startMessageIdData, metadata, readCompacted, InitialPosition.valueOf(subscriptionInitialPosition.getValue()), si); if (startMessageIdData != null) { startMessageIdData.recycle();
BiPredicate<String, MessageId> filter) throws IOException { checkArgument(msg.getMessageIdData().getBatchIndex() == -1); singleMessageMetadataBuilder, 0, batchSize); MessageId id = new BatchMessageIdImpl(msg.getMessageIdData().getLedgerId(), msg.getMessageIdData().getEntryId(), msg.getMessageIdData().getPartition(), i); if (!singleMessageMetadataBuilder.hasPartitionKey()) {
Entry entry = entries.get(i); PositionImpl pos = (PositionImpl) entry.getPosition(); MessageIdData.Builder messageIdBuilder = MessageIdData.newBuilder(); MessageIdData messageId = messageIdBuilder .setLedgerId(pos.getLedgerId()) promise = writePromise; int redeliveryCount = subscription.getDispatcher().getRedeliveryTracker().getRedeliveryCount(PositionImpl.get(messageId.getLedgerId(), messageId.getEntryId())); ctx.write(Commands.newMessage(consumerId, messageId, redeliveryCount, metadataAndPayload), promise); messageId.recycle(); messageIdBuilder.recycle(); entry.release();
org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData.Builder subBuilder = org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData.newBuilder(); input.readMessage(subBuilder, extensionRegistry); addMessageId(subBuilder.buildPartial());
.map(messageId -> (MessageIdImpl)messageId) .collect(Collectors.toSet()), MAX_REDELIVER_UNACKNOWLEDGED); MessageIdData.Builder builder = MessageIdData.newBuilder(); batches.forEach(ids -> { List<MessageIdData> messageIdDatas = ids.stream().map(messageId -> {
MessageIdImpl msgId = new MessageIdImpl(ledgerId, entryId, -1); MessageIdData.Builder messageIdBuilder = MessageIdData.newBuilder(); messageIdBuilder.setLedgerId(ledgerId); messageIdBuilder.setEntryId(entryId); messageId.recycle(); msgMetadata.recycle();
org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData.Builder subBuilder = org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData.newBuilder(); if (hasMessageId()) { subBuilder.mergeFrom(getMessageId());
topic, subscription, result.getLedgerId(), result.getEntryId()); future.complete(new MessageIdImpl(result.getLedgerId(), result.getEntryId(), result.getPartition())); }).exceptionally(e -> { log.error("[{}][{}] Failed getLastMessageId command", topic, subscription);
org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData.Builder subBuilder = org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData.newBuilder(); if (hasMessageId()) { subBuilder.mergeFrom(getMessageId());
org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData.Builder subBuilder = org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData.newBuilder(); if (hasMessageId()) { subBuilder.mergeFrom(getMessageId());
PositionImpl position = PositionImpl.get(msgId.getLedgerId(), msgId.getEntryId()); subscription.acknowledgeMessage(Collections.singletonList(position), AckType.Cumulative, properties); } else { for (int i = 0; i < ack.getMessageIdCount(); i++) { MessageIdData msgId = ack.getMessageId(i); PositionImpl position = PositionImpl.get(msgId.getLedgerId(), msgId.getEntryId()); positionsAcked.add(position);
org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData.Builder subBuilder = org.apache.pulsar.common.api.proto.PulsarApi.MessageIdData.newBuilder(); if (hasLastMessageId()) { subBuilder.mergeFrom(getLastMessageId());
public void redeliverUnacknowledgedMessages(List<MessageIdData> messageIds) { int totalRedeliveryMessages = 0; List<PositionImpl> pendingPositions = Lists.newArrayList(); for (MessageIdData msg : messageIds) { PositionImpl position = PositionImpl.get(msg.getLedgerId(), msg.getEntryId()); LongPair batchSize = pendingAcks.get(position.getLedgerId(), position.getEntryId()); if (batchSize != null) { pendingAcks.remove(position.getLedgerId(), position.getEntryId()); totalRedeliveryMessages += batchSize.first; pendingPositions.add(position); } } addAndGetUnAckedMsgs(this, -totalRedeliveryMessages); blockedConsumerOnUnackedMsgs = false; if (log.isDebugEnabled()) { log.debug("[{}-{}] consumer {} received {} msg-redelivery {}", topicName, subscription, consumerId, totalRedeliveryMessages, pendingPositions.size()); } subscription.redeliverUnacknowledgedMessages(this, pendingPositions); msgRedeliver.recordMultipleEvents(totalRedeliveryMessages, totalRedeliveryMessages); int numberOfBlockedPermits = Math.min(totalRedeliveryMessages, PERMITS_RECEIVED_WHILE_CONSUMER_BLOCKED_UPDATER.get(this)); // if permitsReceivedWhileConsumerBlocked has been accumulated then pass it to Dispatcher to flow messages if (numberOfBlockedPermits > 0) { PERMITS_RECEIVED_WHILE_CONSUMER_BLOCKED_UPDATER.getAndAdd(this, -numberOfBlockedPermits); MESSAGE_PERMITS_UPDATER.getAndAdd(this, numberOfBlockedPermits); subscription.consumerFlow(this, numberOfBlockedPermits); } }