srpc-parent

Fast Spring container-managed RPC services

Supports TCP and WebSocket

The background,

In the development process, in order to realize the server-side and client-side invocation, simplify the Web invocation process and quickly complete the third-party interface interconnection. The integration based on NETty integrated RPC scheme is sorted out. In order to provide message push, the implementation of Websocket protocol is provided for service monitoring.

Ii. Composition of Rpc Service Framework

Client: service caller.

Client Stub: stores the address information of the server, packages the request parameters of the Client into network messages, and sends them to the server over the network.

The Server Stub receives and unpacks the request message sent by the client, and then invokes the local service for processing.

Server: The real provider of a service.

Network Service: Underlying transport, either TCP or HTTP.

Environmental support

Netty 4.1.8 Spring 4.0+ Kryo 4.0.2gson 2.8.5 hessian 4.0.62Copy the code

Iv. Rpc Process Sequence Diagram

5. Websocke sequence Diagram

Vi. Instructions:

1. Pom dependency:

2. Project Description:

SRPC: RPC component RPC-API: interface component (Demo): encapsulates TCP interface RPC-client: client component (Demo) Rpc-server: server componentCopy the code

3, TCP use:

(1) Define interface:Copy the code

(2) Server implementation:Copy the code

(3) Start of the server:Copy the code

(4) Client call:Copy the code

4. Websocket usage:

(1) Server startup: as above (2) Server implementation:  @Service public class ServerSimpleListener implements ServerListener { @Override public void doAction(String msg, Channel channel) { log.info(msg+":"+msg); TextWebSocketFrame TWS = new TextWebSocketFrame(" Received message "); channel.writeAndFlush(tws); TextWebSocketFrame tws2 = new TextWebSocketFrame(" Everyone got the message "); NettyWebSocket.send2All(tws2); }} (3) the client calls: if (channel = = null | |! Channel. The isActive ()) {channel = WebsocketClient. ConnectToServer (" http://127.0.0.1:1232? 665887 "); } TextWebSocketFrame frame = new TextWebSocketFrame(" Hello \r\n"); channel.writeAndFlush(frame); (4) Client callback: @Service public class SimpleListener implements BaseListener { private final static Logger LOGGER = LoggerFactory.getLogger(SimpleListener.class); /** * a simple Listener method * @param event Guava specifies only one argument */ @override public void doAction(final String event){if (LOGGER.isInfoEnabled()){ LOGGER.info("Received event [{}] and will take a action", event); }} (5) Support specified channel, group sending, offline sending (6) Logic diagram is as follows:Copy the code

Github address :github.com/yeqi86/srpc…