Skip to content

Commit 297dda8

Browse files
committed
update quark-chat with add protocol service
1 parent 5a6ed2f commit 297dda8

File tree

24 files changed

+1263
-9
lines changed

24 files changed

+1263
-9
lines changed

quark-admin/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<modelVersion>4.0.0</modelVersion>
1212
<groupId>com.quark</groupId>
1313
<artifactId>quark-admin</artifactId>
14-
<packaging>jar</packaging>
14+
<packaging>war</packaging>
1515

1616

1717
<dependencies>
@@ -73,7 +73,7 @@
7373
<groupId>org.springframework.boot</groupId>
7474
<artifactId>spring-boot-maven-plugin</artifactId>
7575
<configuration>
76-
<fork>true</fork><!-- 如果没有该项配置,肯呢个devtools不会起作用,即应用不会restart -->
76+
<fork>true</fork>
7777
</configuration>
7878
</plugin>
7979
</plugins>

quark-chat/pom.xml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,43 @@
1313
<groupId>com.quark</groupId>
1414
<artifactId>quark-chat</artifactId>
1515
<version>1.0-SNAPSHOT</version>
16+
<packaging>jar</packaging>
1617

17-
18+
<dependencies>
19+
<dependency>
20+
<groupId>com.quark</groupId>
21+
<artifactId>quark-common</artifactId>
22+
<version>1.0-SNAPSHOT</version>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-test</artifactId>
31+
<scope>test</scope>
32+
</dependency>
33+
<!--Redis服务-->
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-data-redis</artifactId>
37+
</dependency>
38+
<!--JSON序列化-->
39+
<dependency>
40+
<groupId>com.alibaba</groupId>
41+
<artifactId>fastjson</artifactId>
42+
<version>1.2.23</version>
43+
</dependency>
44+
<!--Netty-->
45+
<dependency>
46+
<groupId>io.netty</groupId>
47+
<artifactId>netty-all</artifactId>
48+
<version>4.1.6.Final</version>
49+
</dependency>
50+
<dependency>
51+
<groupId>com.fasterxml.jackson.core</groupId>
52+
<artifactId>jackson-databind</artifactId>
53+
</dependency>
54+
</dependencies>
1855
</project>
Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,50 @@
11
package com.quark.chat;
22

3+
import com.quark.chat.server.QuarkChatServer;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.CommandLineRunner;
8+
import org.springframework.boot.ExitCodeGenerator;
9+
import org.springframework.boot.SpringApplication;
10+
import org.springframework.boot.autoconfigure.SpringBootApplication;
11+
import org.springframework.cache.annotation.EnableCaching;
12+
import org.springframework.context.annotation.Bean;
13+
14+
import javax.annotation.PreDestroy;
15+
import java.io.IOException;
16+
import java.io.InputStream;
17+
import java.util.Properties;
18+
319
/**
420
* @Author : ChinaLHR
521
* @Date : Create in 22:14 2017/10/19
622
* @Email : [email protected]
723
*/
8-
public class ChatApplication {
24+
@SpringBootApplication
25+
@EnableCaching//缓存支持
26+
public class ChatApplication implements CommandLineRunner {
27+
@Autowired
28+
private QuarkChatServer server;
29+
30+
private final Logger logger = LoggerFactory.getLogger(getClass());
31+
32+
public static void main(String[] args) throws IOException {
33+
Properties properties = new Properties();
34+
InputStream in = ChatApplication.class.getClassLoader().getResourceAsStream("chat.properties");
35+
properties.load(in);
36+
SpringApplication app = new SpringApplication(ChatApplication.class);
37+
app.setDefaultProperties(properties);
38+
app.run(args);
39+
}
40+
41+
@Bean
42+
public QuarkChatServer quarkChatServer(){
43+
return new QuarkChatServer();
44+
}
45+
46+
@Override
47+
public void run(String... strings) throws Exception {
48+
server.start();
49+
}
950
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.quark.chat.config;
2+
3+
import org.springframework.context.annotation.ComponentScan;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
/**
7+
* @Author : ChinaLHR
8+
* @Date : Create in 10:27 2017/10/22
9+
* @Email : [email protected]
10+
*/
11+
@Configuration
12+
@ComponentScan(basePackages = "com.quark.common")
13+
public class ChatConfig {
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.quark.chat.config;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.context.annotation.PropertySource;
6+
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
7+
8+
@Configuration
9+
@PropertySource("classpath:resource.properties")
10+
public class PropertiesConfig {
11+
12+
@Bean
13+
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
14+
return new PropertySourcesPlaceholderConfigurer();
15+
}
16+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.quark.chat.config;
2+
3+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
4+
import com.fasterxml.jackson.annotation.PropertyAccessor;
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import org.springframework.cache.CacheManager;
7+
import org.springframework.cache.annotation.CachingConfigurerSupport;
8+
import org.springframework.cache.annotation.EnableCaching;
9+
import org.springframework.cache.interceptor.KeyGenerator;
10+
import org.springframework.context.annotation.Bean;
11+
import org.springframework.context.annotation.Configuration;
12+
import org.springframework.data.redis.cache.RedisCacheManager;
13+
import org.springframework.data.redis.connection.RedisConnectionFactory;
14+
import org.springframework.data.redis.core.RedisTemplate;
15+
import org.springframework.data.redis.core.StringRedisTemplate;
16+
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
17+
18+
import java.lang.reflect.Method;
19+
20+
/**
21+
* @Author LHR
22+
* Create By 2017/8/21
23+
*/
24+
@Configuration
25+
@EnableCaching
26+
public class RedisConfig extends CachingConfigurerSupport {
27+
28+
@Bean
29+
public KeyGenerator keyGenerator() {
30+
return new KeyGenerator() {
31+
@Override
32+
public Object generate(Object target, Method method, Object... params) {
33+
StringBuilder sb = new StringBuilder();
34+
sb.append(target.getClass().getName());
35+
sb.append(method.getName());
36+
for (Object obj : params) {
37+
sb.append(obj.toString());
38+
}
39+
return sb.toString();
40+
}
41+
};
42+
}
43+
44+
@SuppressWarnings("rawtypes")
45+
@Bean
46+
public CacheManager cacheManager(RedisTemplate redisTemplate) {
47+
RedisCacheManager rcm = new RedisCacheManager(redisTemplate);
48+
//设置缓存过期时间
49+
//rcm.setDefaultExpiration(60);//秒
50+
return rcm;
51+
}
52+
53+
@Bean
54+
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {
55+
StringRedisTemplate template = new StringRedisTemplate(factory);
56+
Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
57+
ObjectMapper om = new ObjectMapper();
58+
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
59+
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
60+
jackson2JsonRedisSerializer.setObjectMapper(om);
61+
template.setValueSerializer(jackson2JsonRedisSerializer);
62+
template.afterPropertiesSet();
63+
return template;
64+
}
65+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.quark.chat.entity;
2+
3+
import com.quark.common.entity.User;
4+
import io.netty.channel.Channel;
5+
6+
/**
7+
* @Author : ChinaLHR
8+
* @Date : Create in 21:31 2017/10/23
9+
* @Email : [email protected]
10+
*/
11+
public class ChatUser {
12+
13+
private User user;
14+
15+
private boolean isAuth = false;//是否认证
16+
17+
private long time = 0;//活跃时间
18+
19+
private Channel channel;//用户对应的channel
20+
21+
private String addr; // 地址
22+
23+
public User getUser() {
24+
return user;
25+
}
26+
27+
public void setUser(User user) {
28+
this.user = user;
29+
}
30+
31+
public boolean isAuth() {
32+
return isAuth;
33+
}
34+
35+
public void setAuth(boolean auth) {
36+
isAuth = auth;
37+
}
38+
39+
public long getTime() {
40+
return time;
41+
}
42+
43+
public void setTime(long time) {
44+
this.time = time;
45+
}
46+
47+
public Channel getChannel() {
48+
return channel;
49+
}
50+
51+
public void setChannel(Channel channel) {
52+
this.channel = channel;
53+
}
54+
55+
public String getAddr() {
56+
return addr;
57+
}
58+
59+
public void setAddr(String addr) {
60+
this.addr = addr;
61+
}
62+
}

0 commit comments

Comments
 (0)