Data exchange
What is an exchange? What are routing keys? How are exchanges and stations associated with each other? When should I use them and how? This page explains it all
Last updated
What is an exchange? What are routing keys? How are exchanges and stations associated with each other? When should I use them and how? This page explains it all
Last updated
All rights reserved to Memphis.dev 2023
Exchange is a well-familiar concept in RabbitMQ and refers to a mechanism where a message is sent to a kind of router instead of directly to some queue. This router then directs the message to a specific queue, depending on a defined policy or, more precisely, based on a routing key.
Exchange is an excellent tool for scenarios where each message needs to be streamed to a different destination based on certain conditions or payload.
Memphis provides the functionality to route specific messages to one or several stations, depending on predefined headers.
This can be accomplished by implementing tagging at the producer level or through a tagging function, which adds tags and headers to each message according to a highly customizable policy.
Create a station that will be designated as the "exchange" station
Add a Memphis station sink
Two routing strategies can be selected: Header-based or Station-name-based. The Header-based strategy involves dynamic routing for each message, determined by a specific header attached to the message. In this method, the receiving system (sink) interprets the header's value to identify the destination station and routes the message accordingly. The Station Name strategy involves routing all new messages directly to a predetermined station.
If the destination station does not exist, it will be automatically created
Example: We implemented a station-type sink that utilizes a header-based routing strategy, keyed by "station."
The following code will produce a message to the station "exchange"
which will reroute it to a station called "destination1"
Another enhancement involves employing a custom Memphis Function, which tags each message at the broker level using a unique logic tailored for every message.