Giter Club home page Giter Club logo

jsonrpc's Introduction

jsonrpc

high-performance RPC framework.

jsonrpc is a high-performance, Java based open source RPC framework.

example

Maven dependency

<dependency>
    <groupId>com.github.xincao9</groupId>
    <artifactId>jsonrpc-spring-boot-starter</artifactId>
    <version>1.2.1</version>
</dependency>

object


public class Say {

    private Integer id;
    private String body;

    public Say(Integer id, String body) {
        this.id = id;
        this.body = body;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this, SerializerFeature.DisableCircularReferenceDetect);
    }
}

interface

public interface SayService {

    Say perform(Say say);
}

service

public class SayServiceImpl implements SayService {

    @Override
    public Say perform(Say say) {
        return say;
    }

}

service provider

@SpringBootApplication
@EnableJsonRPC(server = true)
public class ApplicationProvider {

    @Autowired
    private JsonRPCServer jsonRPCServer;

    @Bean
    public SayService sayService () {
        SayService sayService = new SayServiceImpl();
        jsonRPCServer.register(sayService);
        return sayService;
    }

    public static void main(String... args) {
        SpringApplication.run(ApplicationProvider.class, args);
    }
}

service consumer

@SpringBootApplication
@EnableJsonRPC(client = true)
public class ApplicationConsumer {

    @Autowired
    private JsonRPCClient jsonRPCClient;
    @Autowired
    private SayService sayService;

    @Bean
    public SayService sayService() {
        return jsonRPCClient.proxy(SayService.class);
    }

    public static void main(String... args) {
        SpringApplication.run(ApplicationConsumer.class, args);
    }

    @Bean
    public CommandLineRunner commandLineRunner() {
        return (String... args) -> {
            for (int no = 0; no < 100; no++) {
                String value = RandomStringUtils.randomAscii(128);
                Say say = new Say(no, value);
                System.out.println(sayService.perform(say));
            }
        };
    }

}

application.properties

## consumer
jsonrpc.client.serverList=localhost:12306
jsonrpc.client.connectionTimeoutMS=5000
jsonrpc.client.invokeTimeoutMS=1000

## provider
jsonrpc.server.port=12306
jsonrpc.server.ioThreadBoss=1
jsonrpc.server.ioThreadWorker=4

benchmark

1.Get the pressure measurement component
wget https://oss.sonatype.org/service/local/repositories/releases/content/com/github/xincao9/jsonrpc-benchmark/1.2.1/jsonrpc-benchmark-1.2.1.jar
2.Start service provider
java -Drole=provider -jar jsonrpc-benchmark-1.2.jar
3.Start service consumer
java -Drole=consumer -jar jsonrpc-benchmark-1.2.jar
4.Service providers that simulate IO-intensive applications perform stress tests (blocking time is pseudo-random at 0 to 50 ms)
wrk -c 128 -t 10 -d 30s 'http://localhost:8080/sleep'
5.Service providers that simulate computationally intensive applications perform stress tests (handling pseudo-random, Fibonacci numbers between 0 and 16)
wrk -c 128 -t 10 -d 30s 'http://localhost:8080/fibonacci_sequence'

tips

  • Welcome to see detailed examples examples
  • Not only supports the boot mode of springboot
  • Native boot mode, the default configuration file is named config.properties
  • @EnableJsonRPC(server = true, client = true) Indicates that the service is a consumer even if the provider

Contact

jsonrpc's People

Contributors

upliveapp avatar xincao9 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.