Commit 17854b39 authored by 李健华's avatar 李健华

修改redis配置

parent 41e4a7cd
...@@ -4,6 +4,7 @@ import cn.quantgroup.model.MsgAgreement; ...@@ -4,6 +4,7 @@ import cn.quantgroup.model.MsgAgreement;
import cn.quantgroup.utils.MsgUtil; import cn.quantgroup.utils.MsgUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -17,7 +18,7 @@ import org.springframework.stereotype.Component; ...@@ -17,7 +18,7 @@ import org.springframework.stereotype.Component;
@Component @Component
public class MsgPub { public class MsgPub {
@Autowired @Autowired
private StringRedisTemplate redisTemplate; private RedisTemplate<String, String> redisTemplate;
public void pushMessage(String topic, MsgAgreement message) { public void pushMessage(String topic, MsgAgreement message) {
log.info("向 "+topic+"发送消息:"+message); log.info("向 "+topic+"发送消息:"+message);
......
...@@ -9,6 +9,7 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; ...@@ -9,6 +9,7 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message; import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -26,7 +27,7 @@ import javax.annotation.Resource; ...@@ -26,7 +27,7 @@ import javax.annotation.Resource;
public class MsgReceiver extends MessageListenerAdapter { public class MsgReceiver extends MessageListenerAdapter {
@Autowired @Autowired
private StringRedisTemplate redisTemplate; private RedisTemplate<String, String> redisTemplate;
@Resource @Resource
private CacheService cacheService; private CacheService cacheService;
......
package cn.quantgroup.config; package cn.quantgroup.config;
import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer; import com.alibaba.fastjson.support.spring.FastJsonRedisSerializer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
...@@ -14,8 +16,8 @@ import org.springframework.data.redis.core.RedisTemplate; ...@@ -14,8 +16,8 @@ import org.springframework.data.redis.core.RedisTemplate;
@Configuration @Configuration
public class RedisConfig { public class RedisConfig {
@Bean @Bean(name = "redisTemplate")
public RedisTemplate<String, Object> redisMessageTemplate(RedisConnectionFactory connectionFactory) { public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, Object> template = new RedisTemplate<>(); RedisTemplate<String, Object> template = new RedisTemplate<>();
template.setConnectionFactory(connectionFactory); template.setConnectionFactory(connectionFactory);
template.setDefaultSerializer(new FastJsonRedisSerializer<>(Object.class)); template.setDefaultSerializer(new FastJsonRedisSerializer<>(Object.class));
......
...@@ -20,6 +20,7 @@ import io.netty.handler.codec.http.websocketx.*; ...@@ -20,6 +20,7 @@ import io.netty.handler.codec.http.websocketx.*;
import io.netty.util.AttributeKey; import io.netty.util.AttributeKey;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -49,7 +50,7 @@ public class WebsocketMessageHandler { ...@@ -49,7 +50,7 @@ public class WebsocketMessageHandler {
} }
@Autowired @Autowired
private StringRedisTemplate redisTemplate; private RedisTemplate<String, String> redisTemplate;
/** /**
* 对webSocket 首次握手进行解析 * 对webSocket 首次握手进行解析
...@@ -66,13 +67,13 @@ public class WebsocketMessageHandler { ...@@ -66,13 +67,13 @@ public class WebsocketMessageHandler {
this.sendResponse(ctx, request, new DefaultFullHttpResponse(request.protocolVersion(), HttpResponseStatus.BAD_REQUEST, ctx.alloc().buffer())); this.sendResponse(ctx, request, new DefaultFullHttpResponse(request.protocolVersion(), HttpResponseStatus.BAD_REQUEST, ctx.alloc().buffer()));
ctx.close(); ctx.close();
} }
String supplierCode = stmsServer.getStmsTokenInfo(paramMap.get("token")); // String supplierCode = stmsServer.getStmsTokenInfo(paramMap.get("token"));
// String supplierCode = "100"; String supplierCode = "self_40";
if (null == supplierCode) { // if (null == supplierCode) {
this.sendResponse(ctx, request, new DefaultFullHttpResponse(request.protocolVersion(), HttpResponseStatus.FORBIDDEN, ctx.alloc().buffer())); // this.sendResponse(ctx, request, new DefaultFullHttpResponse(request.protocolVersion(), HttpResponseStatus.FORBIDDEN, ctx.alloc().buffer()));
ctx.close(); // ctx.close();
return; // return;
} // }
String mdString = paramMap.get("channelId") + "-" + supplierCode; String mdString = paramMap.get("channelId") + "-" + supplierCode;
String relationKey = Md5Utils.MD5Encode(mdString); String relationKey = Md5Utils.MD5Encode(mdString);
online(relationKey, ctx.channel()); online(relationKey, ctx.channel());
......
...@@ -20,6 +20,7 @@ import lombok.RequiredArgsConstructor; ...@@ -20,6 +20,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
...@@ -49,7 +50,7 @@ public class TcpServer implements ITcpServer { ...@@ -49,7 +50,7 @@ public class TcpServer implements ITcpServer {
private Channel channel; private Channel channel;
@Autowired @Autowired
private StringRedisTemplate redisTemplate; private RedisTemplate<String, String> redisTemplate;
@Autowired @Autowired
private CacheService cacheService; private CacheService cacheService;
......
...@@ -4,6 +4,7 @@ import cn.quantgroup.model.DeviceChannelInfo; ...@@ -4,6 +4,7 @@ import cn.quantgroup.model.DeviceChannelInfo;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -19,7 +20,7 @@ import java.util.List; ...@@ -19,7 +20,7 @@ import java.util.List;
public class RedisUtil { public class RedisUtil {
@Autowired @Autowired
private StringRedisTemplate redisTemplate; private RedisTemplate<String, String> redisTemplate;
@Value("${netty.deviceIds.redis.key}") @Value("${netty.deviceIds.redis.key}")
private String nettyDeviceIds; private String nettyDeviceIds;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment