Spring Cloud

Spring Cloud Function

  • Spring cloud function is a project with the following high-level goals.
    • Promote the implementation of business logic via functions.
    • Decouple the development cycle of business logic from any specific runtime target so that the same code can run as a web endpoint, a stream processor, or a task.
    • Support a uniform programming model across serverless providers, as well as the ability to run standalone(locally in a PaaS).
    • Enable spring boot features like auto configuration, dependency injection, metrics on server less providers.
  • We don’t need to maintain or manage server.
  • It abstracts away all of the Transport details and infrastructure, allowing the developer to keep all the familiar tools and processes, and focus firmly on business logic.
  • Spring Cloud uses supplier, predicate, consumer and function functional interfaces.
  • Spring cloud also uses Lambda expressions.
  • Using functional interface we can expose our Endpoints as a function.
  • Deploying an AWS function application jar in Lambda.
    • Open service AWS lambda
    • Go to functions dashboard and create a function
      • Select “Auther from scratch”.
      • Give function name
      • Choose Java 8 as runtime or depending on the runtime you want to deploy on.
      • Click create function.
    • Once function is created edit its basic function
      • Provide your request handler information here
        • Example “hello.handle request”.
        • com.spring implant.awslambda.SpringAws LambdaApplication.
        • Packagename.classname.
      • Click save.
    • Edit environment variables
      • Key is FUNCTION_NAME.
      • Value is function name that is orders here.
    • Next click on actions and click upload zip or jat file.
      • Upload your jar file here.
    • Next click on select a test event and configure test events.
      • Give an event name.
      • Give parameters as per need.
      • Click on create.
    • Click on test
      • this will execute the function.
    • Change function name in environment variables and we can test the second function too similarly.
  • AWS lambda can be used for server less programming.
    • AWS lambda is a server less computing service provided by Amazon to reduce the configuration of servers.
    • AWS lambda lets you run code without provisioning or managing servers, it scales automatically and only charges for the time your code is running.
    • It is used when we want to expose a Web end point, a Stream processor, Or a task to cloud without depending on server and operating system.
  • Spring cloud function is a project with the following high-level goals
    • Promote the implementation of business logic via functions.
      • In Java 8 We have functional interfaces like supplier, function, consumer, predicate etc.
      • We make use of these to create call back functions.
    • Decouple that development lifecycle Of a business logic from any specific runtime target So that the same code can run as a web endpoint, a stream processor, or a task.
    • Support a uniform programming model across server-less providers, as well as the ability to run standalone (locally or in a PaaS).
      • PaaS is platform as a service.
    • Enables spring boot features (auto configuration, dependency injection, metrics) on serverless providers.
  • Advantages
    • Zero server management.
    • Flexible scaling
    • No ideal capacity.
  • Source Code for Spring AWS Cloud app : springmvc/springboot-aws-lambda at master · gauravmatta/springmvc (github.com)
  • Source Code: springmvc/spring-cloud-function-example at master · gauravmatta/springmvc (github.com)
Spring Cloud Bus

  • All micro services register themselves with cloud bus.
  • The cloud bus is in touch with the config server.
  • If a particular instance of a micro-service updates The config server and We refresh the config server via “actuator/bus-refresh”. The cloud bus will tell the micro services for a bus refresh via message broker.
  • The message could be rabbit, MQ or Kafka or any else. By default, it is Rabbit MQ.


  • Helps in Service registry and discovery
    • Each micro SS will have to register register itself With a centralised server. Other micro services will be able to discover that micro SS And communicate with dynamically.
    • Helps in decoupling microservices
  • Load balancing
    • As the load on our micro service enquiries, we will have to have different instances of the server and load should be balanced.
    • Ribbon is used for load balancing.
  • Fault Tolerance
    • If something goes down In one of the micro services, the entire system should not go down.
  • Easy integration
    • They should be able to easily communicate with each other.
    • Feign client
    • Zool Proxy Gateway
  • Cross Cutting concerns
    • Common requirements across all micro services like authentication, authorisation, , Logging.
  • Distributed tracing
    • We should be able to twist, how request are going and how response are coming back. Where request went wrong.
    • Sluth Is used for distributed tracing.
  • Spring cloud configuration server
    • We have configuration as a separate micro service.
    • Our configuration system should be
      • Externalised 
      • Environment specific
      • Consistent
      • Version history
      • Real time management
    • All instances of a micro service should be consistent and reliable. They should be having same configuration. 
    • We have one service for providing configuration.
    • All other services connect with the same service to get configuration.
  • Options for config as a service
    • Apache zookeeper
    • ETCD-Distributed key value store
    • Hashicorp Consul
    • Spring cloud configuration server
  • Spring cloud configuration, server directly connects with git repository to get updated files.

No comments:

Post a Comment

Spring Boot

What is circular/cyclic dependency in spring boot? When two services are interdependent on each other, that is to start one service, we requ...