Giter VIP home page Giter VIP logo

rsocket-composingbackpressure-example's Introduction

rsocket-composingbackpressure-example

Build

An example showing how backpressure composes between multiple microservices with RSocket.

In this example the client requests a stream from the letter-service and explicitly states that it can handle 10 items at a time. The letter-service then requests a stream of numbers from the number-service and propagates the demand (backpressure) from the client. The letter-service combines the numbers with a random letter and streams them to the client.

Building the Example

Run the following command to build the example:

./gradlew clean build

Running the Example

Follow the steps below to run the example:

  1. Run the following command to start the number-service:

     ./gradlew :number-service:run
    

    If the service has started successfully, you will see the following in the terminal:

     > Task :number-service:run
     [main] INFO example.number.service.NumberService - RSocket server started on port: 7002
    
  2. In a new terminal, run the following command to start the letter-service:

     ./gradlew :letter-service:run
    

    If the service has started successfully, you will see the following in the terminal:

     > Task :letter-service:run
     [main] INFO example.letter.service.LetterService - RSocket server started on port: 7001
    
  3. In a new terminal, run the following command to start streaming data with the client:

     ./gradlew :client:run
    

    If successful, you will see the client receives 10,000 letter and number pairs in the terminal:

     [reactor-tcp-nio-1] INFO example.client.Client - Received: f9996
     [reactor-tcp-nio-1] INFO example.client.Client - Received: R9997
     [reactor-tcp-nio-1] INFO example.client.Client - Received: t9998
     [reactor-tcp-nio-1] INFO example.client.Client - Received: O9999
     [reactor-tcp-nio-1] INFO example.client.Client - Received: G10000
     [reactor-tcp-nio-1] INFO example.client.Client - Done
    

    Notice in the letter-service terminal that the client is requesting 8 combinations at a time:

     [reactor-tcp-nio-1] INFO example.letter.service.LetterService - Sending: t9993
     [reactor-tcp-nio-1] INFO example.letter.service.LetterService - Sending: n9994
     [reactor-tcp-nio-3] INFO example.letter.service.LetterService - Received Request For: 8
     [reactor-tcp-nio-1] INFO example.letter.service.LetterService - Sending: H9995
     [reactor-tcp-nio-1] INFO example.letter.service.LetterService - Sending: f9996
     [reactor-tcp-nio-1] INFO example.letter.service.LetterService - Sending: R9997
     [reactor-tcp-nio-1] INFO example.letter.service.LetterService - Sending: t9998
     [reactor-tcp-nio-1] INFO example.letter.service.LetterService - Sending: O9999
     [reactor-tcp-nio-1] INFO example.letter.service.LetterService - Sending: G10000
    

    Notice in the number-service terminal the client's demand of 8 combinations is propagated to the number service:

     [reactor-tcp-nio-2] INFO example.number.service.NumberService - Sending: 9993
     [reactor-tcp-nio-2] INFO example.number.service.NumberService - Sending: 9994
     [reactor-tcp-nio-2] INFO example.number.service.NumberService - Received Request For: 8
     [reactor-tcp-nio-2] INFO example.number.service.NumberService - Sending: 9995
     [reactor-tcp-nio-2] INFO example.number.service.NumberService - Sending: 9996
     [reactor-tcp-nio-2] INFO example.number.service.NumberService - Sending: 9997
     [reactor-tcp-nio-2] INFO example.number.service.NumberService - Sending: 9998
     [reactor-tcp-nio-2] INFO example.number.service.NumberService - Sending: 9999
     [reactor-tcp-nio-2] INFO example.number.service.NumberService - Sending: 10000
    

    Note: The 8 items comes from the limitRate(10) on the client. The limitRate algorithm proactively fills the buffer when it is 75% exhausted. That is why you are seeing it request 8 instead of 10.

Bugs and Feedback

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

License

MIT License

Copyright (c) 2020 Greg Whitaker

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

rsocket-composingbackpressure-example's People

Contributors

gregwhitaker avatar

Watchers

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