parent
af29eb818c
commit
9b1336f408
@ -0,0 +1,26 @@
|
|||||||
|
package com.mashibing.strategy.config;
|
||||||
|
|
||||||
|
import com.mashibing.common.constant.RabbitMQConstant;
|
||||||
|
import org.springframework.amqp.core.Queue;
|
||||||
|
import org.springframework.amqp.core.QueueBuilder;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author heqijun
|
||||||
|
* @ClassName: RabbitMQConfig
|
||||||
|
* @Description: RabbitMQConfig
|
||||||
|
* @date 2025/6/8 17:46
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class RabbitMQConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建策略模块发送【手机号归属地和运营商】到后台管理模块的队列名称
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
public Queue preSendQueue() {
|
||||||
|
return QueueBuilder.durable(RabbitMQConstant.MOBILE_AREA_OPERATOR).build();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.mashibing.strategy.config;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.amqp.core.Message;
|
||||||
|
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
||||||
|
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
||||||
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author heqijun
|
||||||
|
* @ClassName: RabbitMQTemplateConfig
|
||||||
|
* @Description: 配置RabbitMQTemplate的confirm和return机制
|
||||||
|
* @date 2025/6/8 17:52
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Slf4j
|
||||||
|
public class RabbitMQTemplateConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
|
||||||
|
|
||||||
|
//设置connectionFactory
|
||||||
|
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
|
||||||
|
|
||||||
|
//配置confirm机制回调
|
||||||
|
rabbitTemplate.setConfirmCallback((correlationData, ack, cause) -> {
|
||||||
|
//消息妹有发送到交换机
|
||||||
|
if (!ack) {
|
||||||
|
log.error("【策略模块-发送消息】消息没有发送到交换机。。。" +
|
||||||
|
"\n correlationData={},ack={},cause:{} ", correlationData, ack, cause);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//配置return机制回调
|
||||||
|
rabbitTemplate.setReturnCallback((message, replyCode, replyText, exchange, routingKey) -> log.error("【策略模块-发送消息】消息没有路由到指定的队列。。。" +
|
||||||
|
"\nmessage={},exchange={},routingKey={}", new String(message.getBody()), exchange, routingKey));
|
||||||
|
|
||||||
|
return rabbitTemplate;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.mashibing.test.feignClient;
|
||||||
|
|
||||||
|
import com.mashibing.common.clients.BeaconCacheClient;
|
||||||
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author heqijun
|
||||||
|
* @ClassName: BeaconCacheClient
|
||||||
|
* @Description: 缓存模块openFeignClient接口
|
||||||
|
* @date 2025/6/5 20:13
|
||||||
|
*/
|
||||||
|
|
||||||
|
@FeignClient("beacon-cache")
|
||||||
|
public interface CacheClient extends BeaconCacheClient {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.mashibing.test.mapper;
|
||||||
|
|
||||||
|
import com.mashibing.test.entity.MobileArea;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author heqijun
|
||||||
|
* @ClassName: MobileAreaMapper
|
||||||
|
* @Description: TODO(这里用一句话描述这个类的作用)
|
||||||
|
* @date 2025/6/8 14:47
|
||||||
|
*/
|
||||||
|
|
||||||
|
public interface MobileDirtywordMapper {
|
||||||
|
|
||||||
|
@Select("select dirtyword from mobile_dirtyword")
|
||||||
|
List<String> findAllDirtyword();
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.mashibing.test.mapper;
|
||||||
|
|
||||||
|
import com.mashibing.common.constant.CacheConstant;
|
||||||
|
import com.mashibing.test.feignClient.CacheClient;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@SpringBootTest
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
class MobileDirtywordMapperTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CacheClient cacheClient;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
MobileDirtywordMapper mapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void findAllDirtyword() {
|
||||||
|
|
||||||
|
List<String> dirtywords = mapper.findAllDirtyword();
|
||||||
|
cacheClient.saddStr(CacheConstant.DIRTY_WORD, dirtywords.toArray(new String[]{}));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue