Week 6
Week 6
Lecture
Message-oriented middleware --> started in stock exchange broker in 1970s
Cool to demo for project : Publisher is python based, the subscriber is javascript based, they communicate with AMQP
BTL: A connection pool is a cache (pool) of database or network connections that can be reused rather than creating a new connection every time. It is commonly used with databases, message brokers (like RabbitMQ), and HTTP clients to improve performance and reduce overhead.
The connection overall forms hub-spoke architecture patterns, in contrast to peer-to-peer connections in invocation-based communication technologies
Message Structure
Properties / metadata:
<BasicProperties(['correlation_id=8c7cf2b5-4199-4ddf-98ba-c3b43fa9f8a3', 'delivery_mode=2', 'reply_to=none'])>
RabbitMQ
A message-queuing software (message broker/queue manager) that supports AMQP (and other protocols)
2) Topic
exchange delivers a message to binding keys of queues that match with the wildcard of the routing pattern of exchange
* match only one wildcard word
# match with any number of wildcard word
3) Fanout
exchange delivers a message to queues that are bound to the exchange without utilising binding key and routing key
2. Create Channel
3. Declare Exchange
connection.close()
Subscriber
1. Create connection
2. Create Channel
3. Declare Exchange
4. Declare Queue
5. Bind Queue
channel.basic_consume(…) # sets up a consumer and binds the “on_message_callback” function to all messages to be received.
channel.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.
7. Close connection
connection.close()
Load Balancing
In reality, the queue may use a random message distribution strategy, instead of a strict round-robin mode. Then, each message may go to a random receiver.
Since each queue can only send 1 message to one container, this mechanism creates load balancing.