Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #435] Support Consumer Shutdown "awaitTerminationMillisWhenShutdown" #435

Merged
merged 2 commits into from
Mar 5, 2022
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 @@ -159,4 +159,10 @@
* The minimum value is 10 and the maximum is 30000.
*/
int suspendCurrentQueueTimeMillis() default 1000;

/**
* Maximum time to await message consuming when shutdown consumer, in milliseconds.
* The minimum value is 0
*/
int awaitTerminationMillisWhenShutdown() default 1000;
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public class DefaultRocketMQListenerContainer implements InitializingBean,
private int replyTimeout;
private String tlsEnable;
private String namespace;
private long awaitTerminationMillisWhenShutdown;

public long getSuspendCurrentQueueTimeMillis() {
return suspendCurrentQueueTimeMillis;
Expand Down Expand Up @@ -245,6 +246,7 @@ public void setRocketMQMessageListener(RocketMQMessageListener anno) {
this.namespace = anno.namespace();
this.delayLevelWhenNextConsume = anno.delayLevelWhenNextConsume();
this.suspendCurrentQueueTimeMillis = anno.suspendCurrentQueueTimeMillis();
this.awaitTerminationMillisWhenShutdown = Math.max(0, anno.awaitTerminationMillisWhenShutdown());
}

public ConsumeMode getConsumeMode() {
Expand Down Expand Up @@ -291,6 +293,15 @@ public void setConsumer(DefaultMQPushConsumer consumer) {
this.consumer = consumer;
}

public long getAwaitTerminationMillisWhenShutdown() {
return awaitTerminationMillisWhenShutdown;
}

public DefaultRocketMQListenerContainer setAwaitTerminationMillisWhenShutdown(long awaitTerminationMillisWhenShutdown) {
this.awaitTerminationMillisWhenShutdown = awaitTerminationMillisWhenShutdown;
return this;
}

@Override
public void destroy() {
this.setRunning(false);
Expand Down Expand Up @@ -624,6 +635,7 @@ private void initRocketMQPushConsumer() throws MQClientException {
consumer.setConsumeThreadMin(consumeThreadNumber);
consumer.setConsumeTimeout(consumeTimeout);
consumer.setMaxReconsumeTimes(maxReconsumeTimes);
consumer.setAwaitTerminationMillisWhenShutdown(awaitTerminationMillisWhenShutdown);
switch (messageModel) {
case BROADCASTING:
consumer.setMessageModel(org.apache.rocketmq.common.protocol.heartbeat.MessageModel.BROADCASTING);
Expand Down