Git Product home page Git Product logo

fpush's Introduction

fpush

fpush是即时消息推送服务程序.
旨在做一个类似于极光推送,小米推送之类的Java程序开源实现。基于Netty + protobuf
👉 fpush源码解析与使用(中文)

fpush监控后台,点击进入演示
👉 http://fpush-admin.appjishu.com
如果该项目对您有帮忙,您可以右上角'star'支持一下,谢谢!


技术栈

  1. JDK1.8
  2. Netty-4.1.31.Final
  3. protobuf-java 3.6.1

代码简介

fpush-core 核心类库,protobuf原型类
fpush-server server端, 接受来自自己的应用服务器的http推送请求,并把请求转换成netty的socket发送给fpush-client 实现消息推送,即时通讯技术。
fpush-client 客户端,模拟App或者网页,或者桌面应用的客户端

系统架构

1.系统部署架构图如下:






源码和技术架构分析详情见

👉 fpush源码解析与使用(中文)

运行

eclipse/IDEA里
Step1 右键run as--java application-- FpushServerApp.java
Step2 右键run as--java application-- FpushClientApp.java

Step3 后台发送消息给fpush-client (用来模拟android,ios或者网页,或者java应用的消息客户端) 浏览器访问 http://localhost:10200
显示Welcome to fpush application!, 说明server运行起来了
然后浏览器请求 http://localhost:10200/app/push?receiverAlias=lsm001&title=系统提醒&desc=消息内容001&data=abc


如果浏览器返回OK 并且fpush-client打印出下面的信息,说明推送消息成功

2018-11-19 14:28:44.792  INFO 27780 --- [ntLoopGroup-2-1] c.a.f.client.handler.PushConfirmHandler  : --->>>这是推送到客户端的消息:title=fpush-Demo
2018-11-19 14:29:17.067  INFO 27780 --- [ntLoopGroup-2-1] c.a.f.client.handler.PushConfirmHandler  : --->>>这是推送到客户端的消息:description=这是一条推送给lsm001的消息!

Step4 Android演示

演示视频如下demo.mp4

server效果图


client在eclipse上调试的效果图-eclipse console可以显示中文字符



测试

注册一个应用账号,手机号是15600000000
http://localhost:10200/app/registerAccount?mobilePhone=15600000000

http://localhost:10200/app/secretToken?appId=517723931931574272&appSecretKey=cb2eb85b362941f1b3e1


http://localhost:10200/app/keyToken?appId=517723931931574272&appKey=9f5d74bb0f68

然后浏览器请求 http://localhost:10200/app/push?receiverAlias=lsm001&title=系统提醒&desc=消息内容001&data=abc

查看所有的netty channel连接情况, 浏览器输入下面的网址 http://appjishu.com:10200/monitor/channelList

Android客户端演示可以直接使用apk文件装到自己的android手机上去
fpush-android-demo.apk
里面的测试host就是我个人的服务器host:appjishu.com

fpush监控后台
👉 http://fpush-admin.appjishu.com

Done List

🚩🚩🚩

  1. netty+protobuf
    protobuf的解码ProtobufVarint32FrameDecoder,ProtobufDecoder
    protobuf的编码ProtobufVarint32LengthFieldPrepender,ProtobufEncoder

  2. 心跳机制的实现
    client端经过HeartBeatResponseHandler新建线程,定期发出心跳请求
    server端的HeartBeatResponseHandler监听心跳并作出响应

  3. 客户端长连接的鉴权
    客户端(即fpush-client)发送appId + appKey,经后台鉴定权限通过后,获取到clientToken
    fpush-client与fpush-server通信的时候, RegisterRequestHandler和HeartBeatRequestHandler里面需要带上
    appId+clientToken 建立长连接后,最好所有的RequestHandler需要带上appId+clientToken

  4. 应用服务端的http连接的鉴权
    应用服务端(即app server)发送appId + appSecretKey,经后台鉴定权限通过后,获取到appToken 应用服务端每次调用fpush-server的api都需要带上appId+appToken


TODO list

  1. 需要在FHeader里增加msgId

2. 增加IdleStateHandler来对heartbeat进行监控,设定的时间间隔内没有收到心跳,就断开连接 Netty的IdleStateHandler会根据用户的使用场景,启动三类定时任务,分别是:ReaderIdleTimeoutTask、WriterIdleTimeoutTask和AllIdleTimeoutTask,它们都会被加入到NioEventLoop的Task队列中被调度和执行。
3. server端长连接的超时时间的设置
我们是长连接服务,手机端和服务端要维持这个长连接,需要定期的发送心跳消息,我们为了节约电量和流量,手机端采用的是智能心跳模式。那么对服务端来说,它是不知道手机端下次是几分钟之后会发送心跳上来的,那么这个连接在服务端的超时时间应该设置多久就是一个问题了。 客户端在每一次的心跳消息中携带下一次的心跳时间。服务端就根据这个时间来设置连接的超时时间。

如果该项目对您有帮忙,您可以右上角'star'支持一下,谢谢!
有代码改进优化的建议的可以提issue
加群讨论
![](doc/image/group-qrcode.png)

fpush's People

Contributors

bootsrc avatar dependabot[bot] avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.