Communication Technologies Flashcards
w5,6
Basic terms: send/request data
- who to who?
- synonyms of send and sender?
sender (data) -> receiver
send: produce, push, publish, broadcast, …
sender: producer, publisher, caller, requestor, …
Basic terms: reply data/status/response
- from who to who
- synonyms of receive, receiver,reply
sender <- receiver (reply data)
receive: accept, consume, take, get, …
receiver: listener, consumer, subscriber, …
wait to receive: wait for, listen for, subscriber, callee, …
reply: response, feedback, return, …
How many receivers does the sender expect for the data sent?
1 receiver: one-to-one
all receivers: one-to-all
selected receivers: one-to-selected
what is MOM
- purpose?
- forms?
Message Oriented Middleware
- software which sits between 2 or more applications or (micro)services and allow them to exchange data in the form of messages
- form a hub-spoke architecture pattern, in contrast to peer-to-peer connections in invocation-based communication technologies
what is a Common Message Structure
- Networking / communication technology related info : usually protocol/technology dependent (headers)
- Properties/metadata of message : usually key-value pairs
- Body / business data : contains application-specific business data
what is AMQP
- benefits?
- supports?
Advanced Message Queuing Protocol
- open standard protocol for MOM : define a message format that allows standard and extensible representations of various types of data
- provide interoperability
- supports various communication patterns
Eg. RabbitMQ (pika is a python module for clients in python to interact with AMQP servers)
what is RabbitMQ
a message-queueing software that supports AMQP
- aka message broker/queue manager
what is RabbitMQ Messaging
- how does it work?
broker accepts and forwards messages
- producer (publisher) sends messages to the broker
- consumer (subscriber) receives messages from the broker
message: can be anything including detailed business data or event; routed to a queue(s) via an exchange in broker and key matching pattern
broker can keep message in queue until a consumer takes the message of the queue (message storage)
code: persistent message
- what does persistent message mean?
A message may or may not be persistent (delivery_mode=2 or pika.spec.PERSISTENT_DELIVERY_MODE); if not (i.e., delivery_mode=1 or pika.spec.TRANSIENT_DELIVERY_MODE), the message would be dropped if there is no receiver online when the message is sent.
*even if the broker fails or is restarted, the message will still be available for delivery to consumers once the broker is back online.
RabbitMQ Messaging - Exchange
- what happens
- Publish a message with a routing key
- Each queue is bound to some exchange(s) via a binding key
- Subscribe to a queue to receive messages
Types of exchanges (3)
- how do they work?
- Direct: delivers a message to a queue whose binding key == routing key of message sent to exchange (eg. email address)
- Topic: wildcard match between routing key of message and binding key of queues bound to the exchange (eg. select who to receive notif)
- Fanout: routes a message to all queues that are bound to it (eg. broadcast)
which communication patterns can be implemented by which type of exchanges more conveniently? (5)
- One-to-one: direct
- One-to-all: fanout
- One-to-selected many: topic
- Fire-forget: direct/fanout/topic
- Request-reply: may be implemented as two one-way messaging
how are binding keys and routing keys matched (for topic exchange)
matched 0, 1, or many words
- /* matches any 1 word
- # matches 0, 1 or many words
RabbitMQ/Pika Programming Model for Python
- 3 functions
The connection/channel to the broker needs to be set up for each/every run of a publisher or a consumer.
The set-ups of exchange/queue may need be done only once for all sessions/connections; they can be done separately via RabbitMQ management GUI or an automated script.
In the same session/connection, a publisher/a consumer can publish/consume many messages.
“on_message_callback” refers to a function that is defined in the consumer; the function can do anything with the message received according to the business requirements.
“basic_consume” sets up a consumer and binds the “on_message_callback” function to all messages to be received.
“start_consuming” starts a loop to wait to receive any message from the queue, and automatically invokes the “on_message_callback” function to process each of the messages received. Use Ctrl + C in the cmd windows to terminate it.
ref google docs
Choice of communication technologies
P1: process or user needs an immediate response => communication with all the relevant underlying microservices should use invocation-based, synchronous communication
P2: process/user does not need an immediate response => communication with all the relevant underlying microservices should use message-based, asynchronous communication