socket Java 服务_RSocket-Java

RSocket

reactivesocket-java.svg

RSocket is a binary protocol for use on byte stream transports such as TCP, WebSockets, and Aeron.

It enables the following symmetric interaction models via async message passing over a single connection:

request/response (stream of 1)

request/stream (finite stream of many)

fire-and-forget (no response)

event subscription (infinite stream of many)

Build and Binaries

rsocket-java.svg?branch=1.0.x

Releases are available via Maven Central.

Example:

dependencies {

implementation 'io.rsocket:rsocket-core:0.11.5'

implementation 'io.rsocket:rsocket-transport-netty:0.11.5'

}

Development

Install the google-java-format in Intellij, from Plugins preferences.

Enable under Preferences -> Other Settings -> google-java-format Settings

Format automatically with

$./gradlew goJF

Debugging

Frames can be printed out to help debugging. Set the logger io.rsocket.FrameLogger to debug to print the frames.

Requirements

Java 8 - heavy dependence on Java 8 functional APIs and java.time, also on Reactor

Trivial Client

package io.rsocket.transport.netty;

import io.rsocket.Payload;

import io.rsocket.RSocket;

import io.rsocket.RSocketFactory;

import io.rsocket.transport.netty.client.WebsocketClientTransport;

import io.rsocket.util.DefaultPayload;

import reactor.core.publisher.Flux;

import java.net.URI;

public class ExampleClient {

public static void main(String[] args) {

WebsocketClientTransport ws = WebsocketClientTransport.create(URI.create("ws://rsocket-demo.herokuapp.com/ws"));

RSocket client = RSocketFactory.connect().keepAlive().transport(ws).start().block();

try {

Flux s = client.requestStream(DefaultPayload.create("peace"));

s.take(10).doOnNext(p -> System.out.println(p.getDataUtf8())).blockLast();

} finally {

client.dispose();

}

}

}

Bugs and Feedback

For bugs, questions and discussions please use the Github Issues.

LICENSE

Copyright 2015-2018 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值