Code Monkey home page Code Monkey logo

non-blocking-client's Introduction

Non blocking API client

It is basically a servlet exposed as a REST endpoint via Apache Sling framework. It in turn fires multiple HTTP calls in parallel and caching response in memory based on OSGi configuration. It then sends a consolidated response to the invoker.

Features

  • Use of Service Contract pattern to define a Service Interface which should be implemented by all services
  • A service represents a third party REST API and encapsulates the logic to connect to the endpoint using its own set of configuration
  • Each service exposes a ServiceWorker which handles the request data and is called by the invoker.
  • Response is cache in-memory using Google Guava library by passing the executor function to cache

Use Case

Here the use case is for Lead Generation, where website visitors can express interest in certain products and can submit their information by a contact form which will be treated as Lead by the website business owners. There are three steps which are necessary to generate a lead:

  1. Validate the form submission using Google Recaptcha
  2. Validate if user is entering valid email by performing verification with ZeroBounce service
  3. Obtain auth token from Authentication service by passing client ID and client secret to be sent along with form data to lead generation service

Instead of waiting for each step to complete and sending the response back to the client, we execute all three steps in parallel by firing simultaneous HTTP calls and after verification in step 1 & 2, we send form data along with token received in step 3. Based on if submission is successful or not, we send back proper response to the client. We also cache the response of ZeroBounce validation since we don't want to validate the same email again and again and consume API calls thereby reducing billed usage of the service

Important Classes

  • Entrypoint/Invoker: com.myorg.core.servlets.LeadGenerationServlet
  • Service Interface: com.myorg.core.servlets.RestClientService<T>
  • Cache: com.myorg.core.servlets.ServiceCache - buildCache method
  • Cache registry: com.myorg.core.servlets.CacheRegistry

How to build

To build the bundle run in the project root directory the following command with Maven 3:

mvn clean install

Testing

mvn clean test

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.