调整Cache模块。

解决推送模块最后一次推送后,依然推送的BUG。
处理ip追加后,ES无法添加的问题。
master
郑大仙丶 2 years ago
parent 76574a4e42
commit fa60fef39f

@ -11,6 +11,8 @@ import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author zjw
* @description ip
@ -29,11 +31,11 @@ public class IPCheckFilter implements CheckFilter {
public void check(StandardSubmit submit) {
log.info("【接口模块-校验ip】 校验ing…………");
//1. 根据CacheClient根据客户的apikey以及ipAddress去查询客户的IP白名单
String ip = cacheClient.hgetString(CacheConstant.CLIENT_BUSINESS + submit.getApikey(), IP_ADDRESS);
List<String> ip = (List<String>) cacheClient.hget(CacheConstant.CLIENT_BUSINESS + submit.getApikey(), IP_ADDRESS);
submit.setIp(ip);
//2. 如果IP白名单为null直接放行
if(StringUtils.isEmpty(ip) || ip.contains(submit.getRealIP())){
if(ip != null || ip.contains(submit.getRealIP())){
log.info("【接口模块-校验ip】 客户端请求IP合法");
return;
}

@ -8,8 +8,6 @@ import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -30,7 +28,9 @@ public class CacheController {
@PostMapping(value = "/cache/hmset/{key}")
public void hmset(@PathVariable(value = "key") String key, @RequestBody Map<String, Object> map) {
log.info("【缓存模块】 hmset方法存储key = {}存储value = {}", key, map);
redisClient.putMap(key, map);
// 因为飞马框架更新,这里的方法名称更改了。
// redisClient.putMap(key, map);
redisClient.hSet(key,map);
}
@PostMapping(value = "/cache/set/{key}")
@ -68,7 +68,9 @@ public class CacheController {
@GetMapping("/cache/hgetall/{key}")
public Map hGetAll(@PathVariable(value = "key")String key){
log.info("【缓存模块】 hGetAll方法获取key ={} 的数据", key);
Map<String, Object> value = redisClient.getMap(key);
// 因为飞马框架更新,这里的方法名称更改了。
// Map<String, Object> value = redisClient.getMap(key);
Map<String, Object> value = redisClient.hGetAll(key);
log.info("【缓存模块】 hGetAll方法获取key ={} 的数据 value = {}", key,value);
return value;
}
@ -76,7 +78,9 @@ public class CacheController {
@GetMapping("/cache/hget/{key}/{field}")
public Object hget(@PathVariable(value = "key")String key,@PathVariable(value = "field")String field){
log.info("【缓存模块】 hget方法获取key ={}field = {}的数据", key,field);
Object value = redisClient.getMapItem(key, field);
// 因为飞马框架更新,这里的方法名称更改了。
// Object value = redisClient.getMapItem(key, field);
Object value = redisClient.hGet(key, field);
log.info("【缓存模块】 hget方法获取key ={}field = {} 的数据 value = {}", key,field,value);
return value;
}
@ -84,7 +88,9 @@ public class CacheController {
@GetMapping("/cache/smember/{key}")
public Set smember(@PathVariable(value = "key")String key){
log.info("【缓存模块】 smember方法获取key ={}的数据", key);
Set<Object> values = redisClient.sGet(key);
// 因为飞马框架更新,这里的方法名称更改了。
// Set<Object> values = redisClient.sGet(key);
Set<Object> values = redisClient.sMembers(key);
log.info("【缓存模块】 smember方法获取key ={} 的数据 value = {}", key,values);
return values;
}
@ -139,7 +145,9 @@ public class CacheController {
@PathVariable(value = "field") String field,
@PathVariable(value = "delta") Long delta){
log.info("【缓存模块】 hIncrBy方法自增 key = {},field = {}number = {}", key,field,delta);
Long result = redisClient.incrementMap(key, field, delta);
// 因为飞马框架更新,这里的方法名称更改了。
// Long result = redisClient.incrementMap(key, field, delta);
Long result = redisClient.hIncrementBy(key, field, delta);
log.info("【缓存模块】 hIncrBy方法自增 key = {},field = {}number = {},剩余数值为 = {}", key,field,delta,result);
return result;
}

@ -2,8 +2,6 @@ package com.mashibing.cache.controller;
import com.msb.framework.redis.RedisClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
@ -22,13 +20,13 @@ public class TestController {
// 写测试 hash结构
@PostMapping("/test/set/{key}")
public String set(@PathVariable String key, @RequestBody Map map){
redisClient.putMap(key,map);
redisClient.hSet(key,map);
return "ok";
}
// 读测试
@GetMapping("/test/get/{key}")
public Map get(@PathVariable String key){
Map<String, Object> result = redisClient.getMap(key);
Map<String, Object> result = redisClient.hGetAll(key);
return result;
}
// 管道测试

@ -34,4 +34,13 @@ public interface RabbitMQConstants {
String SMS_GATEWAY = "sms_gateway_topic_";
/**
*
*/
String SMS_GATEWAY_NORMAL_EXCHANGE = "sms_gateway_normal_exchange";
String SMS_GATEWAY_NORMAL_QUEUE = "sms_gateway_normal_queue";
String SMS_GATEWAY_DEAD_EXCHANGE = "sms_gateway_dead_exchange";
String SMS_GATEWAY_DEAD_QUEUE = "sms_gateway_dead_queue";
}

@ -11,6 +11,7 @@ import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;
/**
* --POJO
@ -36,7 +37,7 @@ public class StandardSubmit implements Serializable {
/**
* ip
*/
private String ip;
private List<String> ip;
/**
* uid

@ -6,6 +6,7 @@ import com.mashibing.common.util.JsonUtil;
import com.mashibing.search.service.SearchService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
@ -28,6 +29,7 @@ public class SmsWriteLogListener {
private final String INDEX = "sms_submit_log_";
@RabbitListener(queues = RabbitMQConstants.SMS_WRITE_LOG)
public void consume(StandardSubmit submit, Channel channel, Message message) throws IOException {
//1、调用搜索模块的添加方法完成添加操作

@ -12,7 +12,7 @@ import org.springframework.cloud.openfeign.EnableFeignClients;
*/
@SpringBootApplication
@EnableDiscoveryClient
@EnableDynamicThreadPool
//@EnableDynamicThreadPool
@EnableFeignClients
public class SmsGatewayStarterApp {

@ -1,18 +1,70 @@
package com.mashibing.smsgateway.config;
import org.springframework.amqp.core.AcknowledgeMode;
import static com.mashibing.common.constant.RabbitMQConstants.*;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* ~
* @author zjw
* @description
*/
//@Configuration
@Configuration
public class RabbitMQConfig {
private final int TTL = 10000;
private final String FANOUT_ROUTING_KEY = "";
// 声明死信队列,需要准备普通交换机,普通队列,死信交换机,死信队列
@Bean
public Exchange normalExchange(){
return ExchangeBuilder.fanoutExchange(SMS_GATEWAY_NORMAL_EXCHANGE).build();
}
@Bean
public Queue normalQueue(){
Queue queue = QueueBuilder.durable(SMS_GATEWAY_NORMAL_QUEUE)
.withArgument("x-message-ttl",TTL)
.withArgument("x-dead-letter-exchange",SMS_GATEWAY_DEAD_EXCHANGE)
.withArgument("x-dead-letter-routing-key",FANOUT_ROUTING_KEY)
.build();
return queue;
}
@Bean
public Binding normalBinding(Exchange normalExchange,Queue normalQueue){
return BindingBuilder.bind(normalQueue).to(normalExchange).with("").noargs();
}
@Bean
public Exchange deadExchange(){
return ExchangeBuilder.fanoutExchange(SMS_GATEWAY_DEAD_EXCHANGE).build();
}
@Bean
public Queue deadQueue(){
return QueueBuilder.durable(SMS_GATEWAY_DEAD_QUEUE).build();
}
@Bean
public Binding deadBinding(Exchange deadExchange,Queue deadQueue){
return BindingBuilder.bind(deadQueue).to(deadExchange).with("").noargs();
}
// 配置类的方式修改RabbitMQ消费的方式
// @Bean
public SimpleRabbitListenerContainerFactory gatewayContainerFactory(ConnectionFactory connectionFactory,
SimpleRabbitListenerContainerFactoryConfigurer configurer){

@ -68,7 +68,8 @@ public class DeliverRunnable implements Runnable {
}
}
//4、发送消息让搜索模块对之前写入的信息做修改这里需要做一个死信队列延迟10s发送修改es信息的消息
// 声明好具体的交换机和队列后直接发送report到死信队列即可
rabbitTemplate.convertAndSend(RabbitMQConstants.SMS_GATEWAY_NORMAL_EXCHANGE,"",report);
}
}

@ -1,6 +1,11 @@
package com.mashibing.test.entity;
import org.apache.commons.lang.StringUtils;
import java.util.Arrays;
import java.util.List;
public class ClientBusiness {
private long id;
@ -50,8 +55,12 @@ public class ClientBusiness {
}
public String getIpAddress() {
return ipAddress;
public List<String> getIpAddress() {
String ips = ipAddress;
if(!StringUtils.isEmpty(ips)){
return Arrays.asList(ips.split(","));
}
return null;
}
public void setIpAddress(String ipAddress) {

Loading…
Cancel
Save