0% found this document useful (0 votes)
4 views22 pages

CS10 Communication

The document discusses Service Oriented Computing, focusing on service invocations, communication methods, and interaction styles such as synchronous and asynchronous communication. It covers HTTP request/response patterns, long-running transactions, polling, webhooks, and messaging systems like RabbitMQ and Apache Kafka. The document also highlights the role of message brokers in facilitating communication between services through message-oriented middleware.

Uploaded by

mohit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views22 pages

CS10 Communication

The document discusses Service Oriented Computing, focusing on service invocations, communication methods, and interaction styles such as synchronous and asynchronous communication. It covers HTTP request/response patterns, long-running transactions, polling, webhooks, and messaging systems like RabbitMQ and Apache Kafka. The document also highlights the role of message brokers in facilitating communication between services through message-oriented middleware.

Uploaded by

mohit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Service Oriented Computing

Akshaya Ganesan
Assistant Professor[Off-Campus]
BITS-Pilani
Agenda

• Service invocations
• Communication between services
• Synchronous and Asynchronous communication
• HTTP Request Response
• HTTP Polling
• Messaging based communication
Service invocations
How do you call a service from a client
Axios is a Javascript library used to make HTTP requests
Fetch API is built into most modern browsers to make HTTP requests
Communication in a service based

• Services must interact using an inter-process communication protocol such as HTTP, AMQP, or
a binary protocol, depending on the nature of each service.

Interaction Styles
• Synchronous—The client expects a timely response from the service and might even block
while it waits.
• Asynchronous—The client doesn’t block, and the response, if any, isn’t necessarily sent
immediately.
Request/response communication
with HTTP and REST
Long running Transactions
API that performs tasks that could run longer than the request timeout limit.
• Optimize requests and responses that involve large objects
• Implement partial responses for clients that don't support asynchronous operations
• Support pagination for requests that may return large numbers of objects

• Provide asynchronous support for long-running requests


• HTTP Polling, Webhooks
• Message Queues
Polling Pattern
HTTP Polling

• An HTTP 202 response should indicate the location and frequency that the client should poll for
the response.
• It should have the following additional headers:
• Location: A URL the client should poll for a response status.
• Retry-After: This header is designed to prevent polling clients from overwhelming the back-end with
retries.
Webhook
The webhook pattern for long-running tasks and asynchronous processing.
• A webhook is an HTTP-based callback function that allows lightweight, event-driven
communication between 2 application programming interfaces (APIs).
• This callback is an HTTP POST that sends a message to a URL when an event happens.
Webhooks Example
Source: The Design of Web APIs by Arnaud Lauret
More on Webhooks

• “client-side” application is the one making the request to the API on the “server-side”.
• The “client-side” must be running a server, and the “server-side” must be running a server.
• The “client-side” application makes an API request to the “server-side” server, and sends the “server-
side” server a “webhook” to call once the “server-side” wants to notify the “client-side” application of
some “event”.
• Once the “event” occurs, and the “server-side” application calls the “webhook” url, the server that is
running on the “client-side” application will “receive” that “webhook” notification.
• Front end applications eg. pure React JS, AngularJS, Mobile Apps, cannot use webhooks
directly.

• Webhooks basically are APIs implemented by API consumers but defined and used by API providers
to send notifications of events.
Websockets and SSE
How could an API server send a stream of events requested by a consumer
• Using SSE, a server can send event data to consumers.
• The server-side script that sends events using the MIME type text/event-stream. Each
notification is sent as a block of text terminated by a pair of newlines
• WebSocket is bidirectional, a full-duplex protocol used in the same scenario of client-server
communication, unlike HTTP it starts from ws:// or wss://.

javascript.info/article/server-sent-events/eventsource/
event: userconnect
data: {"username": "bobby", "time": "02:33:48"}
Communication across services
Asynchronous event-driven communication

14
Messaging

• Refactor the solution and introduce a queue between the client and the service.
• The client and the service run asynchronously

• A message broker is an intermediary through which all messages flow. A sender writes the message
to the message broker, and the message broker delivers it to the receiver
• Examples of popular open-source message brokers include the following:
• ActiveMQ (http://activemq.apache.org)
• RabbitMQ (https://www.rabbitmq.com)
• Apache Kafka (http://kafka.apache.org)
Messaging

• Refactor the solution and introduce a queue between the client and the service.
• The client and the service run asynchronously

• A message broker is an intermediary through which all messages flow. A sender writes the message
to the message broker, and the message broker delivers it to the receiver
• Examples of popular open-source message brokers include the following:
• ActiveMQ (http://activemq.apache.org)
• RabbitMQ (https://www.rabbitmq.com)
• Apache Kafka (http://kafka.apache.org)
Message Oriented Middleware
A message broker is a software that enables services and applications to communicate through messages.

• The message structure is independent of the services that send them.


• Producer — The application or service responsible for sending the messages.
• Consumer — The application or service that will receive the message.
• Queue/ Topic — Message brokers used them to store the messages
Queues/Topics
RabbitMQ

• The simple cycle of RabbitMQ message is as follows:


• The producer publishes a message to exchange.
• After receiving the message, the exchange is responsible for forwarding it. The exchange routes
the message to the queues, exchanges bound to it.
• Queue receives the message and keeps it until the consumer consumes it.
• Lastly, the consumer handles the message.
RabbitMQ
RabbitMQ has four different types of exchanges; Direct, Topic, Fanout, Headers.
References

• T2: Restful Web services – Chapter2, 11


• https://docs.microsoft.com/en-us/dotnet/architecture/microservices/architect-
microservicecontainer-applications/communication-in-microservice-architecture
Thank You!
In our next session:

You might also like