Skip to content

Commit

Permalink
add netty websocket server
Browse files Browse the repository at this point in the history
  • Loading branch information
leelance committed Jun 21, 2017
1 parent 7cf0bad commit d9436b1
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 0 deletions.
4 changes: 4 additions & 0 deletions spring-boot-websocket-netty-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/target/
.settings/
.classpath
.project
29 changes: 29 additions & 0 deletions spring-boot-websocket-netty-server/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.lance</groupId>
<artifactId>spring-boot-parent</artifactId>
<version>1.1</version>
<relativePath>../spring-boot-parent/pom.xml</relativePath>
</parent>
<artifactId>spring-boot-websocket-netty-server</artifactId>
<packaging>war</packaging>
<name>spring-boot-websocket-netty-server</name>
<url>http://maven.apache.org</url>

<dependencies>
<!-- Netty4.1.12 -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.12.Final</version>
</dependency>
</dependencies>

<build>
<finalName>spring-boot-websocket-netty-server</finalName>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# IDENTITY (ContextIdApplicationContextInitializer)
spring.application.index=YiDouIndex.v1.1
spring.application.name=YiDouName

#Server
server.port=80
server.jsp-servlet.class-name=org.apache.jasper.servlet.JspServlet

security.basic.enabled=false
management.security.enabled=false

#MVC
spring.mvc.view.prefix=/WEB-INF/views/

#LOG
logging.config=classpath:log4j2.xml
61 changes: 61 additions & 0 deletions spring-boot-websocket-netty-server/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="off">
<!-- 日志文件目录和压缩文件 -->
<Properties>
<Property name="fileName">/tmp/logs</Property>
<Property name="fileGz">/tmp/logs/7z</Property>
</Properties>
<Appenders>
<!--这个输出控制台的配置 -->
<Console name="console" target="SYSTEM_OUT">
<!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch) -->
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="NEUTRAL" />
<ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="NEUTRAL" />
<!--输出日志的格式 -->
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} %L %M - %msg%xEx%n" />
</Console>

<!--这个会打印出所有的信息,每次大小超过size,则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩,作为存档 -->
<RollingRandomAccessFile name="rollingInfoFile" fileName="${fileName}/netty-socket.log" immediateFlush="false"
filePattern="${fileGz}/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.netty-socket.gz">
<PatternLayout pattern="%d{yyyy-MM-dd 'at' HH:mm:ss z} [%t] %-5level %logger{36} %L %M - %msg%xEx%n" />
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true" />
<SizeBasedTriggeringPolicy size="50 MB"/>
</Policies>
<Filters>
<!-- 只记录info级别信息 -->
<ThresholdFilter level="error" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY" />
</Filters>
<!-- 指定每天的最大压缩包个数,默认7个,超过了会覆盖之前的 -->
<DefaultRolloverStrategy max="50"/>
</RollingRandomAccessFile>


<RollingRandomAccessFile name="rollingErrorFile" fileName="${fileName}netty-socket-error.log" immediateFlush="false"
filePattern="${fileGz}/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.netty-socket-error.gz">
<PatternLayout pattern="%d{yyyy-MM-dd 'at' HH:mm:ss z} [%t] %-5level %logger{36} %L %M - %msg%xEx%n" />
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true" />
<SizeBasedTriggeringPolicy size="50 MB"/>
</Policies>
<Filters>
<!-- 只记录error级别信息 -->
<ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY" />
</Filters>
<!-- 指定每天的最大压缩包个数,默认7个,超过了会覆盖之前的 -->
<DefaultRolloverStrategy max="50"/>
</RollingRandomAccessFile>

</Appenders>

<Loggers>
<!-- 全局配置,默认所有的Logger都继承此配置 -->
<AsyncRoot level="debug" additivity="false">
<AppenderRef ref="console"/>
<AppenderRef ref="rollingInfoFile"/>
<AppenderRef ref="rollingErrorFile"/>
</AsyncRoot>
</Loggers>
</Configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
5 changes: 5 additions & 0 deletions spring-boot-websocket-netty-server/src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>

0 comments on commit d9436b1

Please sign in to comment.