About Microservices.io

Microservices.io is brought to you by Chris Richardson. Experienced software architect, author of POJOs in Action and the creator of the original CloudFoundry.com. His latest startup is eventuate.io, a microservices application platform.


Learn more about microservices

Chris offers a comprehensive set of resources for learning about microservices including articles, an O'Reilly training video, and example code. Learn more


Microservices consulting and training

Chris offers a comprehensive consulting services, workshops and hands on training classes to help you use microservices effectively. Get advice


Example microservices applications

Want to see an example? Check out Chris Richardson's example applications. See code


Get the book: Microservice patterns


Signup for the newsletter

A new microservices application platform that solves distributed data management problems.

Join the microservices google group

Pattern: Remote Procedure Invocation (RPI)

Context

You have applied the Microservice architecture pattern. Services must handle requests from the application’s clients. Furthermore, services must sometimes collaborate to handle those requests. They must use an inter-process communication protocol.

Forces

Solution

Use RPI for inter-service communication. The client uses a request/reply-based protocol to make requests to a service.

Examples

There are numerous examples of RPI technologies

RegistrationServiceProxy from the Microservices Example application is an example of a component, which is written in Scala, that makes a REST request using the Spring Framework’s RestTemplate:

@Component
class RegistrationServiceProxy @Autowired()(restTemplate: RestTemplate) extends RegistrationService {

  @Value("${user_registration_url}")
  var userRegistrationUrl: String = _

  @HystrixCommand(commandProperties=Array(new HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds", value="800")))
  override def registerUser(emailAddress: String, password: String): Either[RegistrationError, String] = {
    try {
      val response = restTemplate.postForEntity(userRegistrationUrl,
        RegistrationBackendRequest(emailAddress, password),
        classOf[RegistrationBackendResponse])
      response.getStatusCode match {
        case HttpStatus.OK =>
          Right(response.getBody.id)
      }
    } catch {
      case e: HttpClientErrorException if e.getStatusCode == HttpStatus.CONFLICT =>
        Left(DuplicateRegistrationError)
    }
  }
}

The value of user_registration_url is supplied using Externalized configuration.

Resulting context

This pattern has the following benefits:

  • Simple and familiar
  • Request/reply is easy
  • Simpler system since there in no intermediate broker

This pattern has the following drawbacks:

  • Usually only supports request/reply and not other interaction patterns such as notifications, request/async response, publish/subscribe, publish/async response
  • Reduced availability since the client and the service must be available for the duration of the interaction

This pattern has the following issues:

  • Client needs to discover locations of service instances

Copyright © 2017 Chris Richardson • All rights reserved • Supported by Kong.