Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,47 @@ public void testMaxPendingChunkMessages() throws Exception {
assertNull(consumer.receive(5, TimeUnit.SECONDS));
}

@Test
public void testResendChunkMessages() throws Exception {
log.info("-- Starting {} test --", methodName);
final String topicName = "persistent://my-property/my-ns/testResendChunkMessages";

@Cleanup
Consumer<String> consumer = pulsarClient.newConsumer(Schema.STRING)
.topic(topicName)
.subscriptionName("my-subscriber-name")
.maxPendingChunkedMessage(10)
.autoAckOldestChunkedMessageOnQueueFull(true)
.subscribe();
@Cleanup
Producer<String> producer = pulsarClient.newProducer(Schema.STRING)
.topic(topicName)
.chunkMaxMessageSize(100)
.enableChunking(true)
.enableBatching(false)
.create();

sendSingleChunk(producer, "0", 0, 2);

sendSingleChunk(producer, "0", 0, 2); // Resending the first chunk
sendSingleChunk(producer, "1", 0, 3); // This is for testing the interwoven chunked message
sendSingleChunk(producer, "1", 1, 3);
sendSingleChunk(producer, "1", 0, 3); // Resending the UUID-1 chunked message

sendSingleChunk(producer, "0", 1, 2);

Message<String> receivedMsg = consumer.receive(5, TimeUnit.SECONDS);
assertEquals(receivedMsg.getValue(), "chunk-0-0|chunk-0-1|");
consumer.acknowledge(receivedMsg);

sendSingleChunk(producer, "1", 1, 3);
sendSingleChunk(producer, "1", 2, 3);

receivedMsg = consumer.receive(5, TimeUnit.SECONDS);
assertEquals(receivedMsg.getValue(), "chunk-1-0|chunk-1-1|chunk-1-2|");
consumer.acknowledge(receivedMsg);
}

/**
* Validate that chunking is not supported with batching and non-persistent topic
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,17 @@ private ByteBuf processMessageChunk(ByteBuf compressedPayload, MessageMetadata m

ChunkedMessageCtx chunkedMsgCtx = chunkedMessagesMap.get(msgMetadata.getUuid());

if (msgMetadata.getChunkId() == 0 && chunkedMsgCtx == null) {
if (msgMetadata.getChunkId() == 0) {
Comment thread
RobertIndie marked this conversation as resolved.
if (chunkedMsgCtx != null) {
// The first chunk of a new chunked-message received before receiving other chunks of previous
// chunked-message
// so, remove previous chunked-message from map and release buffer
if (chunkedMsgCtx.chunkedMsgBuffer != null) {
ReferenceCountUtil.safeRelease(chunkedMsgCtx.chunkedMsgBuffer);
}
chunkedMsgCtx.recycle();
chunkedMessagesMap.remove(msgMetadata.getUuid());
}
pendingChunkedMessageCount++;
if (maxPendingChunkedMessage > 0 && pendingChunkedMessageCount > maxPendingChunkedMessage) {
removeOldestPendingChunkedMessage();
Expand Down