【采集调度器-后端TCP API】采集调度器下发任务命令 API
parent
467ac75700
commit
200243f524
@ -1,26 +0,0 @@
|
|||||||
package com.docus.server;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
|
||||||
import org.springframework.data.redis.listener.ChannelTopic;
|
|
||||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
public class RedisListenerConfig {
|
|
||||||
@Autowired
|
|
||||||
private RedisConnectionFactory redisConnectionFactory;
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public ChannelTopic expiredTopic() {
|
|
||||||
return new ChannelTopic("__keyevent@0__:expired"); // 选择0号数据库
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
public RedisMessageListenerContainer redisMessageListenerContainer() {
|
|
||||||
RedisMessageListenerContainer redisMessageListenerContainer = new RedisMessageListenerContainer();
|
|
||||||
redisMessageListenerContainer.setConnectionFactory(redisConnectionFactory);
|
|
||||||
return redisMessageListenerContainer;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.docus.server.common;
|
||||||
|
|
||||||
|
import com.docus.infrastructure.redis.listener.RedisKeyExpirationListener;
|
||||||
|
import com.docus.server.service.impl.RedisKeyExpirationService;
|
||||||
|
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class RedisCollectorTaskKeyExpirationListener extends RedisKeyExpirationListener {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RedisKeyExpirationService redisKeyExpirationService;
|
||||||
|
|
||||||
|
public RedisCollectorTaskKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
||||||
|
super(listenerContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void processExpireKey(String expireKey) {
|
||||||
|
redisKeyExpirationService.expired(expireKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean validExpireKey(String expireKey) {
|
||||||
|
return expireKey.startsWith("schCollectorRecord:noRetryTask:expireKey:")
|
||||||
|
|| expireKey.startsWith("schCollectorRecord:isRetryTask:expireKey:");
|
||||||
|
}
|
||||||
|
}
|
@ -1,37 +0,0 @@
|
|||||||
package com.docus.server.common;
|
|
||||||
|
|
||||||
import com.docus.server.service.impl.RedisKeyExpirationService;
|
|
||||||
import org.springframework.data.redis.connection.Message;
|
|
||||||
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
|
|
||||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
public class RedisKeyExpirationListener extends KeyExpirationEventMessageListener {
|
|
||||||
|
|
||||||
public RedisKeyExpirationListener(RedisMessageListenerContainer listenerContainer) {
|
|
||||||
super(listenerContainer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private RedisKeyExpirationService redisKeyExpirationService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 开启notify-keyspace-events Ex的配置
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onMessage(Message message, byte[] pattern) {
|
|
||||||
|
|
||||||
String expireKey = message.toString();
|
|
||||||
if (validExpireKey(expireKey)) {
|
|
||||||
redisKeyExpirationService.expired(expireKey);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean validExpireKey(String expireKey) {
|
|
||||||
return expireKey.startsWith("schCollectorRecord:noRetryTask:expireKey:")
|
|
||||||
|| expireKey.startsWith("schCollectorRecord:isRetryTask:expireKey:");
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue