2025-10-14 11:41:13.070 INFO 928 --- [ main] c.t.n.demo.basicspringboot.DelayConsume : Starting DelayConsume using Java 1.8.0_462-462 on 18088363-BG with PID 928 (D:\r\idmdemo\target\classes started by admin in D:\r\idmdemo)
2025-10-14 11:41:13.071 INFO 928 --- [ main] c.t.n.demo.basicspringboot.DelayConsume : No active profile set, falling back to 1 default profile: "default"
2025-10-14 11:41:13.700 INFO 928 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2025-10-14 11:41:13.707 INFO 928 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2025-10-14 11:41:13.707 INFO 928 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.71]
2025-10-14 11:41:13.772 INFO 928 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2025-10-14 11:41:13.772 INFO 928 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 678 ms
2025-10-14 11:41:14.235 INFO 928 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 1 endpoint(s) beneath base path '/actuator'
2025-10-14 11:41:14.264 INFO 928 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2025-10-14 11:41:14.274 INFO 928 --- [ main] c.t.n.demo.basicspringboot.DelayConsume : Started DelayConsume in 1.416 seconds (JVM running for 1.719)
2025-10-14 11:41:14.292 INFO 928 --- [ main] c.t.s.e.port.kafka.KafkaEventCenter : start to register topic: delay_topic_level_2, groupId: delay_consumer_group
2025-10-14 11:41:14.298 INFO 928 --- [ main] c.t.s.e.port.kafka.KafkaEventCenter : start to register topic: vms_dlq_hello-topic, groupId: delay
2025-10-14 11:41:14.300 INFO 928 --- [ main] c.t.s.e.port.kafka.KafkaEventCenter : DelayMs=2000, level=2, expirationTime=1760413276300
2025-10-14 11:41:14.310 INFO 928 --- [_consumer_group] o.a.k.clients.consumer.ConsumerConfig : ConsumerConfig values:
allow.auto.create.topics = true
auto.commit.interval.ms = 5000
auto.offset.reset = latest
bootstrap.servers = [192.168.203.128:9092]
check.crcs = true
client.dns.lookup = use_all_dns_ips
client.id = consumer_10.13.35.30_76a6ca6f-b188-440c-88e5-aec400ec5ae7
client.rack =
connections.max.idle.ms = 540000
default.api.timeout.ms = 60000
enable.auto.commit = false
exclude.internal.topics = true
fetch.max.bytes = 52428800
fetch.max.wait.ms = 500
fetch.min.bytes = 1
group.id = delay_consumer_group
group.instance.id = null
heartbeat.interval.ms = 3000
interceptor.classes = []
internal.leave.group.on.close = true
internal.throw.on.fetch.stable.offset.unsupported = false
isolation.level = read_uncommitted
key.deserializer = class org.apache.kafka.common.serialization.StringDeserializer
max.partition.fetch.bytes = 1048576
max.poll.interval.ms = 300000
max.poll.records = 200
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.recording.level = INFO
metrics.sample.window.ms = 30000
partition.assignment.strategy = [org.apache.kafka.clients.consumer.CooperativeStickyAssignor]
receive.buffer.bytes = -1
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retry.backoff.ms = 100
sasl.client.callback.handler.class = null
sasl.jaas.config = null
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.login.callback.handler.class = null
sasl.login.class = null
sasl.login.refresh.buffer.seconds = 300
sasl.login.refresh.min.period.seconds = 60
sasl.login.refresh.window.factor = 0.8
sasl.login.refresh.window.jitter = 0.05
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
security.providers = null
send.buffer.bytes = 131072
session.timeout.ms = 45000
socket.connection.setup.timeout.max.ms = 30000
socket.connection.setup.timeout.ms = 10000
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2]
ssl.endpoint.identification.algorithm = https
ssl.engine.factory.class = null
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.certificate.chain = null
ssl.keystore.key = null
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLSv1.2
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.certificates = null
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
value.deserializer = class org.apache.kafka.common.serialization.ByteArrayDeserializer
2025-10-14 11:41:14.310 INFO 928 --- [llo-topic_delay] o.a.k.clients.consumer.ConsumerConfig : ConsumerConfig values:
allow.auto.create.topics = true
auto.commit.interval.ms = 5000
auto.offset.reset = latest
bootstrap.servers = [192.168.203.128:9092]
check.crcs = true
client.dns.lookup = use_all_dns_ips
client.id = consumer_10.13.35.30_05508b8f-0b32-45be-b949-9d790b839ad2
client.rack =
connections.max.idle.ms = 540000
default.api.timeout.ms = 60000
enable.auto.commit = false
exclude.internal.topics = true
fetch.max.bytes = 52428800
fetch.max.wait.ms = 500
fetch.min.bytes = 1
group.id = delay
group.instance.id = null
heartbeat.interval.ms = 3000
interceptor.classes = []
internal.leave.group.on.close = true
internal.throw.on.fetch.stable.offset.unsupported = false
isolation.level = read_uncommitted
key.deserializer = class org.apache.kafka.common.serialization.StringDeserializer
max.partition.fetch.bytes = 1048576
max.poll.interval.ms = 300000
max.poll.records = 200
metadata.max.age.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.recording.level = INFO
metrics.sample.window.ms = 30000
partition.assignment.strategy = [org.apache.kafka.clients.consumer.CooperativeStickyAssignor]
receive.buffer.bytes = -1
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retry.backoff.ms = 100
sasl.client.callback.handler.class = null
sasl.jaas.config = null
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.login.callback.handler.class = null
sasl.login.class = null
sasl.login.refresh.buffer.seconds = 300
sasl.login.refresh.min.period.seconds = 60
sasl.login.refresh.window.factor = 0.8
sasl.login.refresh.window.jitter = 0.05
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
security.providers = null
send.buffer.bytes = 131072
session.timeout.ms = 45000
socket.connection.setup.timeout.max.ms = 30000
socket.connection.setup.timeout.ms = 10000
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2]
ssl.endpoint.identification.algorithm = https
ssl.engine.factory.class = null
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.certificate.chain = null
ssl.keystore.key = null
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLSv1.2
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.certificates = null
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
value.deserializer = class org.apache.kafka.common.serialization.ByteArrayDeserializer
2025-10-14 11:41:14.326 INFO 928 --- [ main] o.a.k.clients.producer.ProducerConfig : ProducerConfig values:
acks = -1
batch.size = 4096
bootstrap.servers = [192.168.203.128:9092]
buffer.memory = 33554432
client.dns.lookup = use_all_dns_ips
client.id = producer-1
compression.type = none
connections.max.idle.ms = 540000
delivery.timeout.ms = 120000
enable.idempotence = false
interceptor.classes = []
internal.auto.downgrade.txn.commit = false
key.serializer = class org.apache.kafka.common.serialization.StringSerializer
linger.ms = 1
max.block.ms = 60000
max.in.flight.requests.per.connection = 5
max.request.size = 1048576
metadata.max.age.ms = 300000
metadata.max.idle.ms = 300000
metric.reporters = []
metrics.num.samples = 2
metrics.recording.level = INFO
metrics.sample.window.ms = 30000
partitioner.class = class org.apache.kafka.clients.producer.internals.DefaultPartitioner
receive.buffer.bytes = 32768
reconnect.backoff.max.ms = 1000
reconnect.backoff.ms = 50
request.timeout.ms = 30000
retries = 2147483647
retry.backoff.ms = 100
sasl.client.callback.handler.class = null
sasl.jaas.config = null
sasl.kerberos.kinit.cmd = /usr/bin/kinit
sasl.kerberos.min.time.before.relogin = 60000
sasl.kerberos.service.name = null
sasl.kerberos.ticket.renew.jitter = 0.05
sasl.kerberos.ticket.renew.window.factor = 0.8
sasl.login.callback.handler.class = null
sasl.login.class = null
sasl.login.refresh.buffer.seconds = 300
sasl.login.refresh.min.period.seconds = 60
sasl.login.refresh.window.factor = 0.8
sasl.login.refresh.window.jitter = 0.05
sasl.mechanism = GSSAPI
security.protocol = PLAINTEXT
security.providers = null
send.buffer.bytes = 131072
socket.connection.setup.timeout.max.ms = 30000
socket.connection.setup.timeout.ms = 10000
ssl.cipher.suites = null
ssl.enabled.protocols = [TLSv1.2]
ssl.endpoint.identification.algorithm = https
ssl.engine.factory.class = null
ssl.key.password = null
ssl.keymanager.algorithm = SunX509
ssl.keystore.certificate.chain = null
ssl.keystore.key = null
ssl.keystore.location = null
ssl.keystore.password = null
ssl.keystore.type = JKS
ssl.protocol = TLSv1.2
ssl.provider = null
ssl.secure.random.implementation = null
ssl.trustmanager.algorithm = PKIX
ssl.truststore.certificates = null
ssl.truststore.location = null
ssl.truststore.password = null
ssl.truststore.type = JKS
transaction.timeout.ms = 60000
transactional.id = null
value.serializer = class org.apache.kafka.common.serialization.ByteArraySerializer
2025-10-14 11:41:14.345 INFO 928 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka version: 2.8.0
2025-10-14 11:41:14.345 INFO 928 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka commitId: ebb1d6e21cc92130
2025-10-14 11:41:14.345 INFO 928 --- [ main] o.a.kafka.common.utils.AppInfoParser : Kafka startTimeMs: 1760413274344
2025-10-14 11:41:14.355 INFO 928 --- [_consumer_group] o.a.kafka.common.utils.AppInfoParser : Kafka version: 2.8.0
2025-10-14 11:41:14.355 INFO 928 --- [_consumer_group] o.a.kafka.common.utils.AppInfoParser : Kafka commitId: ebb1d6e21cc92130
2025-10-14 11:41:14.355 INFO 928 --- [_consumer_group] o.a.kafka.common.utils.AppInfoParser : Kafka startTimeMs: 1760413274355
2025-10-14 11:41:14.356 INFO 928 --- [_consumer_group] c.t.s.e.p.k.c.GenericKafkaConsumerTask : start to consumer kafka topic: delay_topic_level_2
2025-10-14 11:41:14.356 INFO 928 --- [llo-topic_delay] o.a.kafka.common.utils.AppInfoParser : Kafka version: 2.8.0
2025-10-14 11:41:14.356 INFO 928 --- [_consumer_group] c.t.s.e.p.k.c.AbstractTaskService : KafkaConsumerTask is running! topic:delay_topic_level_2
2025-10-14 11:41:14.356 INFO 928 --- [llo-topic_delay] o.a.kafka.common.utils.AppInfoParser : Kafka commitId: ebb1d6e21cc92130
2025-10-14 11:41:14.356 INFO 928 --- [llo-topic_delay] o.a.kafka.common.utils.AppInfoParser : Kafka startTimeMs: 1760413274355
2025-10-14 11:41:14.356 INFO 928 --- [llo-topic_delay] c.t.s.e.p.k.consumer.KafkaConsumerTask : start to consumer kafka topic: vms_dlq_hello-topic
2025-10-14 11:41:14.356 INFO 928 --- [llo-topic_delay] c.t.s.e.p.k.c.AbstractTaskService : KafkaConsumerTask is running! topic:vms_dlq_hello-topic
2025-10-14 11:41:14.356 INFO 928 --- [_consumer_group] o.a.k.clients.consumer.KafkaConsumer : [Consumer clientId=consumer_10.13.35.30_76a6ca6f-b188-440c-88e5-aec400ec5ae7, groupId=delay_consumer_group] Subscribed to topic(s): delay_topic_level_2
2025-10-14 11:41:14.356 INFO 928 --- [llo-topic_delay] o.a.k.clients.consumer.KafkaConsumer : [Consumer clientId=consumer_10.13.35.30_05508b8f-0b32-45be-b949-9d790b839ad2, groupId=delay] Subscribed to topic(s): vms_dlq_hello-topic
2025-10-14 11:41:14.510 INFO 928 --- [_consumer_group] org.apache.kafka.clients.Metadata : [Consumer clientId=consumer_10.13.35.30_76a6ca6f-b188-440c-88e5-aec400ec5ae7, groupId=delay_consumer_group] Cluster ID: Cp8MopI8TC6QJ8pHpIkP9A
2025-10-14 11:41:14.510 INFO 928 --- [llo-topic_delay] org.apache.kafka.clients.Metadata : [Consumer clientId=consumer_10.13.35.30_05508b8f-0b32-45be-b949-9d790b839ad2, groupId=delay] Cluster ID: Cp8MopI8TC6QJ8pHpIkP9A
2025-10-14 11:41:14.510 INFO 928 --- [ad | producer-1] org.apache.kafka.clients.Metadata : [Producer clientId=producer-1] Cluster ID: Cp8MopI8TC6QJ8pHpIkP9A
2025-10-14 11:41:14.511 INFO 928 --- [llo-topic_delay] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer_10.13.35.30_05508b8f-0b32-45be-b949-9d790b839ad2, groupId=delay] Discovered group coordinator admin1-virtual-machine:9092 (id: 2147483647 rack: null)
2025-10-14 11:41:14.511 INFO 928 --- [_consumer_group] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer_10.13.35.30_76a6ca6f-b188-440c-88e5-aec400ec5ae7, groupId=delay_consumer_group] Discovered group coordinator admin1-virtual-machine:9092 (id: 2147483647 rack: null)
2025-10-14 11:41:14.940 INFO 928 --- [_consumer_group] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer_10.13.35.30_76a6ca6f-b188-440c-88e5-aec400ec5ae7, groupId=delay_consumer_group] (Re-)joining group
2025-10-14 11:41:14.940 INFO 928 --- [llo-topic_delay] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer_10.13.35.30_05508b8f-0b32-45be-b949-9d790b839ad2, groupId=delay] (Re-)joining group
2025-10-14 11:41:14.951 INFO 928 --- [_consumer_group] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer_10.13.35.30_76a6ca6f-b188-440c-88e5-aec400ec5ae7, groupId=delay_consumer_group] (Re-)joining group
2025-10-14 11:41:14.952 INFO 928 --- [llo-topic_delay] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer_10.13.35.30_05508b8f-0b32-45be-b949-9d790b839ad2, groupId=delay] (Re-)joining group
2025-10-14 11:41:14.953 INFO 928 --- [_consumer_group] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer_10.13.35.30_76a6ca6f-b188-440c-88e5-aec400ec5ae7, groupId=delay_consumer_group] Successfully joined group with generation Generation{generationId=27, memberId='consumer_10.13.35.30_76a6ca6f-b188-440c-88e5-aec400ec5ae7-13b3b8a8-053c-487e-9876-e6dc99701e48', protocol='cooperative-sticky'}
2025-10-14 11:41:14.953 INFO 928 --- [llo-topic_delay] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer_10.13.35.30_05508b8f-0b32-45be-b949-9d790b839ad2, groupId=delay] Successfully joined group with generation Generation{generationId=101, memberId='consumer_10.13.35.30_05508b8f-0b32-45be-b949-9d790b839ad2-a48b0811-3a89-47d4-aba1-081f0fe8f61f', protocol='cooperative-sticky'}
2025-10-14 11:41:14.954 INFO 928 --- [_consumer_group] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer_10.13.35.30_76a6ca6f-b188-440c-88e5-aec400ec5ae7, groupId=delay_consumer_group] Finished assignment for group at generation 27: {consumer_10.13.35.30_76a6ca6f-b188-440c-88e5-aec400ec5ae7-13b3b8a8-053c-487e-9876-e6dc99701e48=Assignment(partitions=[delay_topic_level_2-0])}
2025-10-14 11:41:14.954 INFO 928 --- [llo-topic_delay] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer_10.13.35.30_05508b8f-0b32-45be-b949-9d790b839ad2, groupId=delay] Finished assignment for group at generation 101: {consumer_10.13.35.30_05508b8f-0b32-45be-b949-9d790b839ad2-a48b0811-3a89-47d4-aba1-081f0fe8f61f=Assignment(partitions=[vms_dlq_hello-topic-0])}
2025-10-14 11:41:14.956 INFO 928 --- [llo-topic_delay] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer_10.13.35.30_05508b8f-0b32-45be-b949-9d790b839ad2, groupId=delay] Successfully synced group in generation Generation{generationId=101, memberId='consumer_10.13.35.30_05508b8f-0b32-45be-b949-9d790b839ad2-a48b0811-3a89-47d4-aba1-081f0fe8f61f', protocol='cooperative-sticky'}
2025-10-14 11:41:14.956 INFO 928 --- [_consumer_group] o.a.k.c.c.internals.AbstractCoordinator : [Consumer clientId=consumer_10.13.35.30_76a6ca6f-b188-440c-88e5-aec400ec5ae7, groupId=delay_consumer_group] Successfully synced group in generation Generation{generationId=27, memberId='consumer_10.13.35.30_76a6ca6f-b188-440c-88e5-aec400ec5ae7-13b3b8a8-053c-487e-9876-e6dc99701e48', protocol='cooperative-sticky'}
2025-10-14 11:41:14.957 INFO 928 --- [llo-topic_delay] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer_10.13.35.30_05508b8f-0b32-45be-b949-9d790b839ad2, groupId=delay] Updating assignment with
Assigned partitions: [vms_dlq_hello-topic-0]
Current owned partitions: []
Added partitions (assigned - owned): [vms_dlq_hello-topic-0]
Revoked partitions (owned - assigned): []
2025-10-14 11:41:14.957 INFO 928 --- [llo-topic_delay] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer_10.13.35.30_05508b8f-0b32-45be-b949-9d790b839ad2, groupId=delay] Notifying assignor about the new Assignment(partitions=[vms_dlq_hello-topic-0])
2025-10-14 11:41:14.957 INFO 928 --- [_consumer_group] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer_10.13.35.30_76a6ca6f-b188-440c-88e5-aec400ec5ae7, groupId=delay_consumer_group] Updating assignment with
Assigned partitions: [delay_topic_level_2-0]
Current owned partitions: []
Added partitions (assigned - owned): [delay_topic_level_2-0]
Revoked partitions (owned - assigned): []
2025-10-14 11:41:14.957 INFO 928 --- [_consumer_group] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer_10.13.35.30_76a6ca6f-b188-440c-88e5-aec400ec5ae7, groupId=delay_consumer_group] Notifying assignor about the new Assignment(partitions=[delay_topic_level_2-0])
2025-10-14 11:41:14.958 INFO 928 --- [llo-topic_delay] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer_10.13.35.30_05508b8f-0b32-45be-b949-9d790b839ad2, groupId=delay] Adding newly assigned partitions: vms_dlq_hello-topic-0
2025-10-14 11:41:14.958 INFO 928 --- [_consumer_group] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer_10.13.35.30_76a6ca6f-b188-440c-88e5-aec400ec5ae7, groupId=delay_consumer_group] Adding newly assigned partitions: delay_topic_level_2-0
2025-10-14 11:41:14.958 INFO 928 --- [llo-topic_delay] com.tplink.smb.eventcenter.api.Handler : ending rebalance!
2025-10-14 11:41:14.958 INFO 928 --- [_consumer_group] com.tplink.smb.eventcenter.api.Handler : ending rebalance!
2025-10-14 11:41:14.963 INFO 928 --- [llo-topic_delay] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer_10.13.35.30_05508b8f-0b32-45be-b949-9d790b839ad2, groupId=delay] Setting offset for partition vms_dlq_hello-topic-0 to the committed offset FetchPosition{offset=0, offsetEpoch=Optional.empty, currentLeader=LeaderAndEpoch{leader=Optional[admin1-virtual-machine:9092 (id: 0 rack: null)], epoch=absent}}
2025-10-14 11:41:14.963 INFO 928 --- [_consumer_group] o.a.k.c.c.internals.ConsumerCoordinator : [Consumer clientId=consumer_10.13.35.30_76a6ca6f-b188-440c-88e5-aec400ec5ae7, groupId=delay_consumer_group] Setting offset for partition delay_topic_level_2-0 to the committed offset FetchPosition{offset=357, offsetEpoch=Optional.empty, currentLeader=LeaderAndEpoch{leader=Optional[admin1-virtual-machine:9092 (id: 0 rack: null)], epoch=absent}}@Setter
@Getter
@AllArgsConstructor
public class DelayEvent {
private final String topic;
private final String key;
private final Integer partition;
private final Event event;
@JsonIgnore
private final EventFuture eventFuture;
private final long expirationTime;
} public void registerDelayConsumer(String delayTopic, ExecutorService executorService) {
String delayGroupId = "delay_consumer_group";
// 构造延迟处理器时,注入已有scheduledExecutorService
DelayHandler delayHandler = new DelayHandler(this, new ScheduledThreadPoolExecutor(1));
// 调用原始注册逻辑,注册延迟主题的消费者
registerUnicastGenerically(
delayTopic, // 监听的延迟主题(支持通配或具体前缀)
delayGroupId, // 延迟消费者固定组ID
delayHandler,
executorService,
DelayEvent.class// 使用延迟处理器
);
}
}@Slf4j
@RequiredArgsConstructor
public class DelayHandler implements GenericEventHandler<DelayEvent> {
private final KafkaEventCenter eventCenter;
private final ScheduledExecutorService delayScheduler;
private final Map<String, Boolean> pausedTopics = new ConcurrentHashMap<>();
@Override
public void handleEvent(DelayEvent delayEvent) {
long currentTime = System.currentTimeMillis();
long expirationTime = delayEvent.getExpirationTime();
String targetTopic = delayEvent.getTopic();
// 如果已过期直接转发
if (expirationTime <= currentTime) {
eventCenter.forwardToTargetTopic(delayEvent);
return;
}
// 未过期则暂停目标Topic消费
pauseTargetTopic(targetTopic);
// 计算需要等待的时间
long delayMs = expirationTime - currentTime;
// 注册延迟任务:到期后恢复Topic并转发事件
delayScheduler.schedule(() -> {
log.info("触发延迟任务,目标主题={}, 当前时间={}", targetTopic, System.currentTimeMillis());
resumeTargetTopic(targetTopic);
eventCenter.forwardToTargetTopic(delayEvent);
}, delayMs, TimeUnit.MILLISECONDS);
}
/**
* 暂停目标Topic的消费者
*/
private void pauseTargetTopic(String targetTopic) {
if (pausedTopics.putIfAbsent(targetTopic, true) == null) {
try {
eventCenter.pauseTopic(targetTopic);
log.info("已暂停延迟Topic消费,targetTopic: {}", targetTopic);
} catch (Exception e) {
log.error("暂停Topic失败,targetTopic: {}", targetTopic, e);
pausedTopics.remove(targetTopic);
}
}
}
/**
* 恢复目标Topic的消费者
*/
private void resumeTargetTopic(String targetTopic) {
if (pausedTopics.remove(targetTopic) != null) {
try {
eventCenter.resumeTopic(targetTopic);
log.info("已恢复延迟Topic消费,targetTopic: {}", targetTopic);
} catch (Exception e) {
log.error("恢复Topic失败,targetTopic: {}", targetTopic, e);
}
}
}
}@Slf4j
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class})
@ComponentScan(basePackages = {
"com.tplink.nbu.demo.basicspringboot",
"com.tplink.smb.eventcenter.port.kafka.deadletter",
"com.tplink.smb.eventcenter.api.config"
})
public class DelayConsume implements CommandLineRunner {
@Autowired
private KafkaEventCenter eventCenter;
@Autowired
private DLQConfig deadLetterConfig;
private static final String EVENT_TOPIC = "delay_topic_level_2";
public static void main(String[] args) {
SpringApplication.run(DelayConsume.class, args);
}
@Override
public void run(String... args) throws Exception {
registerDelayConsumer();
registerEventConsumer();
eventCenter.sendDelay("vms_dlq_hello-topic", "key1", 0, new Event("key1", "延迟触发消息"), 2000,
new ForceMatchStrategy(), new EventFuture() {
@Override
public void onSuccess(EventCenterSendResult eventCenterSendResult) {
}
@Override
public void onFailure(Throwable throwable) {
}
});
}
private void registerDelayConsumer() {
eventCenter.registerDelayConsumer(EVENT_TOPIC, Executors.newSingleThreadExecutor());
}
private void registerEventConsumer() {
EventHandler eventHandler = event -> {
// 打印消息内容和消费时间戳,明确消费时机
log.info("[消费时间:{}] 触发消费,消息内容:{}",
LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME),
event.getMessage());
};
eventCenter.registerUnicast(
"vms_dlq_hello-topic",
"delay",
eventHandler,
Executors.newSingleThreadExecutor()
);
}
}
请继续分析修改,为何未触发消息转发