-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Motivation Fixes #189 When consumer got messages from pulsar, It's difficult to ensure every message can be consume success. Pulsar support message redelivery feature by set acknowledge timeout when create a new consumer. This is a good feature guarantee consumer will not lost messages. But however, some message will redelivery so many times possible, even to the extent that it can be never stop. So, It's necessary to support a feature to control it by pulsar. Users can use this feature and customize this feature to control the message redelivery behavior. The feature named Dead Letter Topic. ### Modifications Consumer can set maximum number of redeliveries by java client. Consumer can set the name of Dead Letter Topic by java client, It’s not necessary. Message exceeding the maximum number of redeliveries should send to Dead Letter Topic and acknowledged automatic. ### Result If consumer enable future of dead letter topic. When Message exceeding the maximum number of redeliveries, message will send to the Dead Letter Topic and acknowledged automatic.
- Loading branch information
1 parent
7c62ecf
commit 95fe84c
Showing
22 changed files
with
680 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/InMemoryRedeliveryTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.broker.service; | ||
|
||
import org.apache.bookkeeper.mledger.Position; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class InMemoryRedeliveryTracker implements RedeliveryTracker { | ||
|
||
private ConcurrentHashMap<Position, AtomicInteger> trackerCache = new ConcurrentHashMap<>(16); | ||
|
||
@Override | ||
public int incrementAndGetRedeliveryCount(Position position) { | ||
trackerCache.putIfAbsent(position, new AtomicInteger(0)); | ||
return trackerCache.get(position).incrementAndGet(); | ||
} | ||
|
||
@Override | ||
public int getRedeliveryCount(Position position) { | ||
return trackerCache.getOrDefault(position, new AtomicInteger(0)).get(); | ||
} | ||
|
||
@Override | ||
public void remove(Position position) { | ||
trackerCache.remove(position); | ||
} | ||
|
||
@Override | ||
public void removeBatch(List<Position> positions) { | ||
if (positions != null) { | ||
positions.forEach(this::remove); | ||
} | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
trackerCache.clear(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/RedeliveryTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.broker.service; | ||
|
||
import org.apache.bookkeeper.mledger.Position; | ||
|
||
import java.util.List; | ||
|
||
public interface RedeliveryTracker { | ||
|
||
int incrementAndGetRedeliveryCount(Position position); | ||
|
||
int getRedeliveryCount(Position position); | ||
|
||
void remove(Position position); | ||
|
||
void removeBatch(List<Position> positions); | ||
|
||
void clear(); | ||
} |
55 changes: 55 additions & 0 deletions
55
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/RedeliveryTrackerDisabled.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.pulsar.broker.service; | ||
|
||
import org.apache.bookkeeper.mledger.Position; | ||
|
||
import java.util.List; | ||
|
||
public class RedeliveryTrackerDisabled implements RedeliveryTracker { | ||
|
||
public static final RedeliveryTrackerDisabled REDELIVERY_TRACKER_DISABLED = new RedeliveryTrackerDisabled(); | ||
|
||
private RedeliveryTrackerDisabled() {} | ||
|
||
@Override | ||
public int incrementAndGetRedeliveryCount(Position position) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int getRedeliveryCount(Position position) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void remove(Position position) { | ||
// no-op | ||
} | ||
|
||
@Override | ||
public void removeBatch(List<Position> positions) { | ||
// no-op | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
// no-op | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.