代码拉取完成,页面将自动刷新
Magician is a small HTTP service package based on Netty that makes it very easy to start an http service, and also supports WebSocket, using annotated configuration Handler.
If you want to develop an http service with netty but find it cumbersome, then Magician may help you.
JDK11+
The Jar package for the maven central library supports at least JDK11, but the source code can support at least jdk8, if you need to run on 8, you can download the latest tag and compile it yourself
<dependency>
<groupId>com.github.yuyenews</groupId>
<artifactId>Magician</artifactId>
<version>2.0.7</version>
</dependency>
<!-- This is the logging package, you must have it or the console will not see anything, any logging package that can bridge with slf4j is supported -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.12</version>
</dependency>
Create a Handler
@HttpHandler(path="/")
public class DemoHandler implements HttpBaseHandler {
@Override
public void request(MagicianRequest magicianRequest, MagicianResponse response) {
// response data
magicianRequest.getResponse()
.sendJson(200, "{'status':'ok'}");
}
}
Start the http service
Magician.createHttp()
.scan("handler所在的包名")
.bind(8080);
@WebSocketHandler(path = "/websocket")
public class DemoSocketHandler implements WebSocketBaseHandler {
@Override
public void onOpen(WebSocketSession webSocketSession) {
}
@Override
public void onClose(WebSocketSession webSocketSession) {
}
@Override
public void onMessage(WebSocketSession webSocketSession, byte[] message) {
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型