{"id":2575,"date":"2025-06-05T01:17:33","date_gmt":"2025-06-05T01:17:33","guid":{"rendered":"https:\/\/diznr.com\/?p=2575"},"modified":"2025-06-05T01:17:33","modified_gmt":"2025-06-05T01:17:33","slug":"multicast-ordering-fifo-ordering-algorithm-in-distributed-systems-maker-client-activemq","status":"publish","type":"post","link":"https:\/\/www.reilsolar.com\/pdf\/multicast-ordering-fifo-ordering-algorithm-in-distributed-systems-maker-client-activemq\/","title":{"rendered":"Multicast Ordering FIFO Ordering algorithm in distributed systems-Maker Activemq Client"},"content":{"rendered":"<p>Multicast Ordering FIFO Ordering algorithm in distributed systems-Maker Activemq Client<\/p>\n\n<div class=\"wp-block-fv-player-gutenberg-basic\">[fvplayer id=&#8221;75&#8243;]<\/div>\n<div>\n<h3 data-start=\"0\" data-end=\"102\"><strong data-start=\"4\" data-end=\"100\">Multicast Ordering and FIFO Ordering in Distributed Systems \u2013 ActiveMQ Client Implementation<\/strong><\/h3>\n<p data-start=\"104\" data-end=\"470\">In distributed systems, <strong data-start=\"128\" data-end=\"148\">message ordering<\/strong> is crucial for maintaining consistency across different nodes. Two common ordering guarantees in <strong data-start=\"246\" data-end=\"273\">message passing systems<\/strong> are <strong data-start=\"278\" data-end=\"300\">Multicast Ordering<\/strong> and <strong data-start=\"305\" data-end=\"322\">FIFO Ordering<\/strong>. These concepts are widely used in <strong data-start=\"358\" data-end=\"377\">message brokers<\/strong> like <strong data-start=\"383\" data-end=\"395\">ActiveMQ<\/strong>, which supports reliable message delivery across distributed components.<\/p>\n<h3 data-start=\"477\" data-end=\"516\"><strong data-start=\"480\" data-end=\"514\">\u00a0What is Multicast Ordering?<\/strong><\/h3>\n<h3 data-start=\"518\" data-end=\"541\"><strong data-start=\"522\" data-end=\"539\">\u00a0Definition<\/strong><\/h3>\n<p data-start=\"542\" data-end=\"778\">Multicast ordering ensures that <strong data-start=\"574\" data-end=\"646\">all nodes in a distributed system receive messages in the same order<\/strong> when sent to a group. This is essential for applications requiring <strong data-start=\"714\" data-end=\"747\">synchronized message delivery<\/strong> across multiple subscribers.<\/p>\n<h3 data-start=\"780\" data-end=\"820\"><strong data-start=\"784\" data-end=\"818\">\u00a0Types of Multicast Ordering<\/strong><\/h3>\n<p data-start=\"821\" data-end=\"1142\"><strong data-start=\"824\" data-end=\"843\">Causal Ordering<\/strong> \u2013 Ensures messages are received <strong data-start=\"876\" data-end=\"919\">in the order they were causally related<\/strong>.<br data-start=\"920\" data-end=\"923\" \/><strong data-start=\"926\" data-end=\"944\">Total Ordering<\/strong> \u2013 Guarantees that <strong data-start=\"963\" data-end=\"1010\">all messages are received in the same order<\/strong> across all nodes.<br data-start=\"1028\" data-end=\"1031\" \/><strong data-start=\"1034\" data-end=\"1051\">FIFO Ordering<\/strong> \u2013 Ensures that messages from the <strong data-start=\"1085\" data-end=\"1100\">same sender<\/strong> arrive in the <strong data-start=\"1115\" data-end=\"1139\">order they were sent<\/strong>.<\/p>\n<h3 data-start=\"1149\" data-end=\"1183\"><strong data-start=\"1152\" data-end=\"1181\">\u00a0What is FIFO Ordering?<\/strong><\/h3>\n<h3 data-start=\"1185\" data-end=\"1208\"><strong data-start=\"1189\" data-end=\"1206\">\u00a0Definition<\/strong><\/h3>\n<p data-start=\"1209\" data-end=\"1353\"><strong data-start=\"1209\" data-end=\"1248\">FIFO (First In, First Out) Ordering<\/strong> ensures that messages sent by a <strong data-start=\"1281\" data-end=\"1298\">single sender<\/strong> are received <strong data-start=\"1312\" data-end=\"1333\">in the same order<\/strong> by all receivers.<\/p>\n<p data-start=\"1355\" data-end=\"1489\"><strong data-start=\"1358\" data-end=\"1370\">Example:<\/strong> If <strong data-start=\"1374\" data-end=\"1384\">Node A<\/strong> sends messages <strong data-start=\"1400\" data-end=\"1416\">M1 \u2192 M2 \u2192 M3<\/strong>, all receivers must receive them in the same order (<strong data-start=\"1469\" data-end=\"1485\">M1 \u2192 M2 \u2192 M3<\/strong>).<\/p>\n<p data-start=\"1491\" data-end=\"1675\"><strong data-start=\"1494\" data-end=\"1508\">Challenge:<\/strong> If messages take different network paths, <strong data-start=\"1551\" data-end=\"1569\">network delays<\/strong> can disrupt FIFO ordering. Middleware like <strong data-start=\"1613\" data-end=\"1625\">ActiveMQ<\/strong> ensures this ordering using <strong data-start=\"1654\" data-end=\"1672\">message queues<\/strong>.<\/p>\n<strong data-start=\"1685\" data-end=\"1747\">\u00a0ActiveMQ Implementation for FIFO and Multicast Ordering<\/strong>\n<p data-start=\"1751\" data-end=\"1881\">Apache ActiveMQ is a <strong data-start=\"1772\" data-end=\"1790\">message broker<\/strong> that supports <strong data-start=\"1805\" data-end=\"1822\">FIFO ordering<\/strong> and <strong data-start=\"1827\" data-end=\"1850\">multicast messaging<\/strong> using <strong data-start=\"1857\" data-end=\"1878\">topics and queues<\/strong>.<\/p>\n<h3 data-start=\"1883\" data-end=\"1920\"><strong data-start=\"1887\" data-end=\"1920\">\u00a0FIFO Ordering in ActiveMQ<\/strong><\/h3>\n<ul data-start=\"1921\" data-end=\"2083\">\n<li data-start=\"1921\" data-end=\"1989\"><strong data-start=\"1923\" data-end=\"1955\">FIFO is guaranteed in Queues<\/strong> (point-to-point communication).<\/li>\n<li data-start=\"1990\" data-end=\"2083\">Each message sent by a producer is delivered <strong data-start=\"2037\" data-end=\"2053\">exactly once<\/strong> to a consumer <strong data-start=\"2068\" data-end=\"2080\">in order<\/strong>.<\/li>\n<\/ul>\n<h4 data-start=\"2085\" data-end=\"2147\"><strong data-start=\"2090\" data-end=\"2147\">\u00a0Example: Java Implementation (ActiveMQ FIFO Queue)<\/strong><\/h4>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-java\"><span class=\"hljs-keyword\">import<\/span> org.apache.activemq.ActiveMQConnectionFactory;\n\n<span class=\"hljs-keyword\">import<\/span> javax.jms.*;\n\n<span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">FIFOProducer<\/span> {\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title function_\">main<\/span><span class=\"hljs-params\">(String[] args)<\/span> <span class=\"hljs-keyword\">throws<\/span> JMSException {\n        <span class=\"hljs-type\">ConnectionFactory<\/span> <span class=\"hljs-variable\">factory<\/span> <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">ActiveMQConnectionFactory<\/span>(<span class=\"hljs-string\">\"tcp:\/\/localhost:61616\"<\/span>);\n        <span class=\"hljs-type\">Connection<\/span> <span class=\"hljs-variable\">connection<\/span> <span class=\"hljs-operator\">=<\/span> factory.createConnection();\n        connection.start();\n        \n        <span class=\"hljs-type\">Session<\/span> <span class=\"hljs-variable\">session<\/span> <span class=\"hljs-operator\">=<\/span> connection.createSession(<span class=\"hljs-literal\">false<\/span>, Session.AUTO_ACKNOWLEDGE);\n        <span class=\"hljs-type\">Queue<\/span> <span class=\"hljs-variable\">queue<\/span> <span class=\"hljs-operator\">=<\/span> session.createQueue(<span class=\"hljs-string\">\"FIFO_QUEUE\"<\/span>);\n\n        <span class=\"hljs-type\">MessageProducer<\/span> <span class=\"hljs-variable\">producer<\/span> <span class=\"hljs-operator\">=<\/span> session.createProducer(queue);\n        producer.setDeliveryMode(DeliveryMode.PERSISTENT);\n\n        <span class=\"hljs-keyword\">for<\/span> (<span class=\"hljs-type\">int<\/span> <span class=\"hljs-variable\">i<\/span> <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-number\">1<\/span>; i &lt;= <span class=\"hljs-number\">3<\/span>; i++) {\n            <span class=\"hljs-type\">TextMessage<\/span> <span class=\"hljs-variable\">message<\/span> <span class=\"hljs-operator\">=<\/span> session.createTextMessage(<span class=\"hljs-string\">\"Message \"<\/span> + i);\n            producer.send(message);\n            System.out.println(<span class=\"hljs-string\">\"Sent: \"<\/span> + message.getText());\n        }\n\n        connection.close();\n    }\n}\n<\/code><\/div>\n<\/div>\n<h4 data-start=\"3049\" data-end=\"3074\"><strong data-start=\"3054\" data-end=\"3074\">\u00a0FIFO Consumer<\/strong><\/h4>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-java\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">FIFOConsumer<\/span> {\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title function_\">main<\/span><span class=\"hljs-params\">(String[] args)<\/span> <span class=\"hljs-keyword\">throws<\/span> JMSException {\n        <span class=\"hljs-type\">ConnectionFactory<\/span> <span class=\"hljs-variable\">factory<\/span> <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">ActiveMQConnectionFactory<\/span>(<span class=\"hljs-string\">\"tcp:\/\/localhost:61616\"<\/span>);\n        <span class=\"hljs-type\">Connection<\/span> <span class=\"hljs-variable\">connection<\/span> <span class=\"hljs-operator\">=<\/span> factory.createConnection();\n        connection.start();\n\n        <span class=\"hljs-type\">Session<\/span> <span class=\"hljs-variable\">session<\/span> <span class=\"hljs-operator\">=<\/span> connection.createSession(<span class=\"hljs-literal\">false<\/span>, Session.AUTO_ACKNOWLEDGE);\n        <span class=\"hljs-type\">Queue<\/span> <span class=\"hljs-variable\">queue<\/span> <span class=\"hljs-operator\">=<\/span> session.createQueue(<span class=\"hljs-string\">\"FIFO_QUEUE\"<\/span>);\n\n        <span class=\"hljs-type\">MessageConsumer<\/span> <span class=\"hljs-variable\">consumer<\/span> <span class=\"hljs-operator\">=<\/span> session.createConsumer(queue);\n        <span class=\"hljs-keyword\">while<\/span> (<span class=\"hljs-literal\">true<\/span>) {\n            <span class=\"hljs-type\">TextMessage<\/span> <span class=\"hljs-variable\">message<\/span> <span class=\"hljs-operator\">=<\/span> (TextMessage) consumer.receive();\n            <span class=\"hljs-keyword\">if<\/span> (message != <span class=\"hljs-literal\">null<\/span>) {\n                System.out.println(<span class=\"hljs-string\">\"Received: \"<\/span> + message.getText());\n            }\n        }\n    }\n}\n<\/code><\/div>\n<\/div>\n<p data-start=\"3799\" data-end=\"3850\"><strong data-start=\"3801\" data-end=\"3834\">Ensures FIFO message delivery<\/strong> to consumers.<\/p>\n<h3 data-start=\"3857\" data-end=\"3921\"><strong data-start=\"3861\" data-end=\"3919\">\u00a0Multicast Ordering in ActiveMQ (Publish\/Subscribe)<\/strong><\/h3>\n<ul data-start=\"3922\" data-end=\"4029\">\n<li data-start=\"3922\" data-end=\"3960\">Uses <strong data-start=\"3929\" data-end=\"3939\">Topics<\/strong> instead of Queues.<\/li>\n<li data-start=\"3961\" data-end=\"4029\">Messages are <strong data-start=\"3976\" data-end=\"4007\">delivered in the same order<\/strong> to all subscribers.<\/li>\n<\/ul>\n<h4 data-start=\"4031\" data-end=\"4101\"><strong data-start=\"4036\" data-end=\"4101\">\u00a0Example: Java Implementation (Multicast Topic in ActiveMQ)<\/strong><\/h4>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-java\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">MulticastProducer<\/span> {\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title function_\">main<\/span><span class=\"hljs-params\">(String[] args)<\/span> <span class=\"hljs-keyword\">throws<\/span> JMSException {\n        <span class=\"hljs-type\">ConnectionFactory<\/span> <span class=\"hljs-variable\">factory<\/span> <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">ActiveMQConnectionFactory<\/span>(<span class=\"hljs-string\">\"tcp:\/\/localhost:61616\"<\/span>);\n        <span class=\"hljs-type\">Connection<\/span> <span class=\"hljs-variable\">connection<\/span> <span class=\"hljs-operator\">=<\/span> factory.createConnection();\n        connection.start();\n\n        <span class=\"hljs-type\">Session<\/span> <span class=\"hljs-variable\">session<\/span> <span class=\"hljs-operator\">=<\/span> connection.createSession(<span class=\"hljs-literal\">false<\/span>, Session.AUTO_ACKNOWLEDGE);\n        <span class=\"hljs-type\">Topic<\/span> <span class=\"hljs-variable\">topic<\/span> <span class=\"hljs-operator\">=<\/span> session.createTopic(<span class=\"hljs-string\">\"MULTICAST_TOPIC\"<\/span>);\n\n        <span class=\"hljs-type\">MessageProducer<\/span> <span class=\"hljs-variable\">producer<\/span> <span class=\"hljs-operator\">=<\/span> session.createProducer(topic);\n\n        <span class=\"hljs-keyword\">for<\/span> (<span class=\"hljs-type\">int<\/span> <span class=\"hljs-variable\">i<\/span> <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-number\">1<\/span>; i &lt;= <span class=\"hljs-number\">3<\/span>; i++) {\n            <span class=\"hljs-type\">TextMessage<\/span> <span class=\"hljs-variable\">message<\/span> <span class=\"hljs-operator\">=<\/span> session.createTextMessage(<span class=\"hljs-string\">\"Multicast Message \"<\/span> + i);\n            producer.send(message);\n            System.out.println(<span class=\"hljs-string\">\"Sent: \"<\/span> + message.getText());\n        }\n\n        connection.close();\n    }\n}\n<\/code><\/div>\n<\/div>\n<h4 data-start=\"4880\" data-end=\"4912\"><strong data-start=\"4885\" data-end=\"4912\">\u00a0Multicast Subscriber<\/strong><\/h4>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre language-java\"><span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title class_\">MulticastConsumer<\/span> {\n    <span class=\"hljs-keyword\">public<\/span> <span class=\"hljs-keyword\">static<\/span> <span class=\"hljs-keyword\">void<\/span> <span class=\"hljs-title function_\">main<\/span><span class=\"hljs-params\">(String[] args)<\/span> <span class=\"hljs-keyword\">throws<\/span> JMSException {\n        <span class=\"hljs-type\">ConnectionFactory<\/span> <span class=\"hljs-variable\">factory<\/span> <span class=\"hljs-operator\">=<\/span> <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">ActiveMQConnectionFactory<\/span>(<span class=\"hljs-string\">\"tcp:\/\/localhost:61616\"<\/span>);\n        <span class=\"hljs-type\">Connection<\/span> <span class=\"hljs-variable\">connection<\/span> <span class=\"hljs-operator\">=<\/span> factory.createConnection();\n        connection.start();\n\n        <span class=\"hljs-type\">Session<\/span> <span class=\"hljs-variable\">session<\/span> <span class=\"hljs-operator\">=<\/span> connection.createSession(<span class=\"hljs-literal\">false<\/span>, Session.AUTO_ACKNOWLEDGE);\n        <span class=\"hljs-type\">Topic<\/span> <span class=\"hljs-variable\">topic<\/span> <span class=\"hljs-operator\">=<\/span> session.createTopic(<span class=\"hljs-string\">\"MULTICAST_TOPIC\"<\/span>);\n\n        <span class=\"hljs-type\">MessageConsumer<\/span> <span class=\"hljs-variable\">consumer<\/span> <span class=\"hljs-operator\">=<\/span> session.createConsumer(topic);\n        <span class=\"hljs-keyword\">while<\/span> (<span class=\"hljs-literal\">true<\/span>) {\n            <span class=\"hljs-type\">TextMessage<\/span> <span class=\"hljs-variable\">message<\/span> <span class=\"hljs-operator\">=<\/span> (TextMessage) consumer.receive();\n            <span class=\"hljs-keyword\">if<\/span> (message != <span class=\"hljs-literal\">null<\/span>) {\n                System.out.println(<span class=\"hljs-string\">\"Received: \"<\/span> + message.getText());\n            }\n        }\n    }\n}\n<\/code><\/div>\n<\/div>\n<p data-start=\"5647\" data-end=\"5714\"><strong data-start=\"5649\" data-end=\"5711\">Ensures all subscribers receive messages in the same order<\/strong>.<\/p>\n<h3 data-start=\"5721\" data-end=\"5746\"><strong data-start=\"5724\" data-end=\"5744\">\u00a0Key Takeaways<\/strong><\/h3>\n<p data-start=\"5747\" data-end=\"6076\"><strong data-start=\"5749\" data-end=\"5766\">FIFO Ordering<\/strong> ensures that <strong data-start=\"5780\" data-end=\"5813\">messages from a single sender<\/strong> are received <strong data-start=\"5827\" data-end=\"5839\">in order<\/strong>.<br data-start=\"5840\" data-end=\"5843\" \/><strong data-start=\"5845\" data-end=\"5867\">Multicast Ordering<\/strong> guarantees that <strong data-start=\"5884\" data-end=\"5932\">all receivers get messages in the same order<\/strong> in a publish-subscribe system.<br data-start=\"5963\" data-end=\"5966\" \/><strong data-start=\"5968\" data-end=\"6006\">ActiveMQ provides built-in support<\/strong> for <strong data-start=\"6011\" data-end=\"6037\">FIFO ordering (Queues)<\/strong> and <strong data-start=\"6042\" data-end=\"6073\">Multicast ordering (Topics)<\/strong>.<\/p>\n<p data-start=\"6078\" data-end=\"6240\" data-is-last-node=\"\" data-is-only-node=\"\">\u00a0<strong data-start=\"6081\" data-end=\"6237\">ActiveMQ makes distributed messaging efficient and reliable, ensuring order preservation in real-time applications like finance, IoT, and cloud systems.<\/strong><\/p>\n<p data-start=\"0\" data-end=\"230\">Here\u2019s a detailed explanation of <strong data-start=\"33\" data-end=\"107\">Multicast Ordering and FIFO Ordering algorithms in Distributed Systems<\/strong>, especially in the context of <strong data-start=\"138\" data-end=\"187\">ActiveMQ (or any message-oriented middleware)<\/strong> using a <strong data-start=\"196\" data-end=\"229\">Maker-Consumer (Client) model<\/strong>.<\/p>\n<hr data-start=\"232\" data-end=\"235\" \/>\n<h1 data-start=\"237\" data-end=\"292\">\ud83d\udce1 Multicast &amp; FIFO Ordering in Distributed Systems<\/h1>\n<h3 data-start=\"293\" data-end=\"351\">\ud83d\udcd8 With Maker-Consumer Model (ActiveMQ Client Example)<\/h3>\n<hr data-start=\"353\" data-end=\"356\" \/>\n<h2 data-start=\"358\" data-end=\"417\">\ud83d\udd04 <strong data-start=\"364\" data-end=\"417\">1. Multicast Communication in Distributed Systems<\/strong><\/h2>\n<p data-start=\"419\" data-end=\"540\">Multicast refers to sending a message from <strong data-start=\"462\" data-end=\"476\">one sender<\/strong> to <strong data-start=\"480\" data-end=\"522\">multiple receivers (clients\/consumers)<\/strong> at the same time.<\/p>\n<h3 data-start=\"542\" data-end=\"557\">\u2705 Use Case:<\/h3>\n<ul data-start=\"558\" data-end=\"644\">\n<li data-start=\"558\" data-end=\"586\">\n<p data-start=\"560\" data-end=\"586\">Collaborative applications<\/p>\n<\/li>\n<li data-start=\"587\" data-end=\"609\">\n<p data-start=\"589\" data-end=\"609\">Stock ticker updates<\/p>\n<\/li>\n<li data-start=\"610\" data-end=\"624\">\n<p data-start=\"612\" data-end=\"624\">Chat systems<\/p>\n<\/li>\n<li data-start=\"625\" data-end=\"644\">\n<p data-start=\"627\" data-end=\"644\">Distributed games<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"646\" data-end=\"649\" \/>\n<h2 data-start=\"651\" data-end=\"692\">\u23f3 <strong data-start=\"656\" data-end=\"692\">2. Message Ordering in Multicast<\/strong><\/h2>\n<p data-start=\"694\" data-end=\"826\">In multicast, it\u2019s important to <strong data-start=\"726\" data-end=\"756\">maintain the correct order<\/strong> of messages so that all clients interpret the system state correctly.<\/p>\n<p data-start=\"828\" data-end=\"868\">Here are the common ordering strategies:<\/p>\n<hr data-start=\"870\" data-end=\"873\" \/>\n<h3 data-start=\"875\" data-end=\"923\">\ud83d\udccc a. <strong data-start=\"885\" data-end=\"923\">FIFO Ordering (First-In-First-Out)<\/strong><\/h3>\n<p data-start=\"925\" data-end=\"1040\"><strong data-start=\"925\" data-end=\"939\">Definition<\/strong>:<br data-start=\"940\" data-end=\"943\" \/>Messages from the <strong data-start=\"961\" data-end=\"976\">same sender<\/strong> are received by all recipients <strong data-start=\"1008\" data-end=\"1039\">in the order they were sent<\/strong>.<\/p>\n<h3 data-start=\"1042\" data-end=\"1054\">Example:<\/h3>\n<p data-start=\"1055\" data-end=\"1121\">If a sender sends messages <strong data-start=\"1082\" data-end=\"1096\">M1, M2, M3<\/strong>, all receivers must see:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\">nginx<\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre!\"><span class=\"hljs-attribute\">M1<\/span> \u2192 M2 \u2192 M3\n<\/code><\/div>\n<\/div>\n<p data-start=\"1144\" data-end=\"1213\">But <strong data-start=\"1148\" data-end=\"1188\">FIFO does not guarantee global order<\/strong> across multiple senders.<\/p>\n<hr data-start=\"1215\" data-end=\"1218\" \/>\n<h3 data-start=\"1220\" data-end=\"1249\">\ud83d\udccc b. <strong data-start=\"1230\" data-end=\"1249\">Causal Ordering<\/strong><\/h3>\n<p data-start=\"1251\" data-end=\"1330\"><strong data-start=\"1251\" data-end=\"1265\">Definition<\/strong>:<br data-start=\"1266\" data-end=\"1269\" \/>Preserves the <strong data-start=\"1283\" data-end=\"1312\">cause-effect relationship<\/strong> between messages.<\/p>\n<ul data-start=\"1332\" data-end=\"1416\">\n<li data-start=\"1332\" data-end=\"1416\">\n<p data-start=\"1334\" data-end=\"1416\">If message M1 causes message M2, then all receivers must receive M1 <strong data-start=\"1402\" data-end=\"1412\">before<\/strong> M2.<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"1418\" data-end=\"1432\">Technique:<\/h3>\n<ul data-start=\"1433\" data-end=\"1471\">\n<li data-start=\"1433\" data-end=\"1471\">\n<p data-start=\"1435\" data-end=\"1471\">Implemented using <strong data-start=\"1453\" data-end=\"1470\">Vector Clocks<\/strong>.<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"1473\" data-end=\"1476\" \/>\n<h3 data-start=\"1478\" data-end=\"1506\">\ud83d\udccc c. <strong data-start=\"1488\" data-end=\"1506\">Total Ordering<\/strong><\/h3>\n<p data-start=\"1508\" data-end=\"1623\"><strong data-start=\"1508\" data-end=\"1522\">Definition<\/strong>:<br data-start=\"1523\" data-end=\"1526\" \/><strong data-start=\"1526\" data-end=\"1542\">All messages<\/strong> (from all senders) are received in <strong data-start=\"1578\" data-end=\"1604\">exactly the same order<\/strong> by all recipients.<\/p>\n<h3 data-start=\"1625\" data-end=\"1639\">Technique:<\/h3>\n<ul data-start=\"1640\" data-end=\"1731\">\n<li data-start=\"1640\" data-end=\"1731\">\n<p data-start=\"1642\" data-end=\"1731\">Use a <strong data-start=\"1648\" data-end=\"1669\">central sequencer<\/strong> or a <strong data-start=\"1675\" data-end=\"1709\">distributed consensus protocol<\/strong> (like Paxos or Raft).<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"1733\" data-end=\"1736\" \/>\n<h2 data-start=\"1738\" data-end=\"1788\">\ud83e\uddea Example with ActiveMQ (Maker-Consumer Model)<\/h2>\n<h3 data-start=\"1790\" data-end=\"1810\">\ud83e\uddf1 Architecture:<\/h3>\n<ul data-start=\"1811\" data-end=\"1939\">\n<li data-start=\"1811\" data-end=\"1880\">\n<p data-start=\"1813\" data-end=\"1880\"><strong data-start=\"1813\" data-end=\"1833\">Maker (Producer)<\/strong> sends messages to a <strong data-start=\"1854\" data-end=\"1863\">Topic<\/strong> (for multicast).<\/p>\n<\/li>\n<li data-start=\"1881\" data-end=\"1939\">\n<p data-start=\"1883\" data-end=\"1939\"><strong data-start=\"1883\" data-end=\"1896\">Consumers<\/strong> subscribe to the topic to receive updates.<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"1941\" data-end=\"1944\" \/>\n<h3 data-start=\"1946\" data-end=\"1992\">\ud83d\udca1 Implementing FIFO Ordering in ActiveMQ:<\/h3>\n<p data-start=\"1994\" data-end=\"2079\">By default, <strong data-start=\"2006\" data-end=\"2041\">ActiveMQ supports FIFO ordering<\/strong> per producer in a topic-based system.<\/p>\n<h3 data-start=\"2081\" data-end=\"2093\">\u2705 Steps:<\/h3>\n<ol data-start=\"2094\" data-end=\"2342\">\n<li data-start=\"2094\" data-end=\"2135\">\n<p data-start=\"2097\" data-end=\"2135\">Configure topic and durable consumers.<\/p>\n<\/li>\n<li data-start=\"2136\" data-end=\"2206\">\n<p data-start=\"2139\" data-end=\"2206\">Use a <strong data-start=\"2145\" data-end=\"2174\">single connection\/session<\/strong> per producer to preserve order.<\/p>\n<\/li>\n<li data-start=\"2207\" data-end=\"2270\">\n<p data-start=\"2210\" data-end=\"2270\">Set <code data-start=\"2214\" data-end=\"2230\">MessageGroupID<\/code> to group messages logically (optional).<\/p>\n<\/li>\n<li data-start=\"2271\" data-end=\"2342\">\n<p data-start=\"2274\" data-end=\"2342\">Consumers process messages in the order they arrive from the broker.<\/p>\n<\/li>\n<\/ol>\n<h3 data-start=\"2344\" data-end=\"2371\">\ud83d\udd27 Code Example (Java):<\/h3>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\">java<\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre! language-java\"><span class=\"hljs-comment\">\/\/ Producer (Maker)<\/span>\n<span class=\"hljs-type\">TextMessage<\/span> <span class=\"hljs-variable\">msg<\/span> <span class=\"hljs-operator\">=<\/span> session.createTextMessage(<span class=\"hljs-string\">\"M1\"<\/span>);\nmsg.setStringProperty(<span class=\"hljs-string\">\"JMSXGroupID\"<\/span>, <span class=\"hljs-string\">\"group-1\"<\/span>); <span class=\"hljs-comment\">\/\/ Ensures FIFO<\/span>\nproducer.send(msg);\n<\/code><\/div>\n<\/div>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none rounded-t-[5px]\">java<\/div>\n<div class=\"sticky top-9\">\n<div class=\"absolute end-0 bottom-0 flex h-9 items-center pe-2\">\n<div class=\"bg-token-sidebar-surface-primary text-token-text-secondary dark:bg-token-main-surface-secondary flex items-center rounded-sm px-2 font-sans text-xs\"><button class=\"flex gap-1 items-center select-none px-4 py-1\" aria-label=\"Copy\">Copy<\/button><span class=\"\" data-state=\"closed\"><button class=\"flex items-center gap-1 px-4 py-1 select-none\">Edit<\/button><\/span><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"whitespace-pre! language-java\"><span class=\"hljs-comment\">\/\/ Consumer<\/span>\n<span class=\"hljs-type\">MessageConsumer<\/span> <span class=\"hljs-variable\">consumer<\/span> <span class=\"hljs-operator\">=<\/span> session.createConsumer(topic);\nconsumer.setMessageListener(message -&gt; {\n    System.out.println(<span class=\"hljs-string\">\"Received: \"<\/span> + ((TextMessage) message).getText());\n});\n<\/code><\/div>\n<\/div>\n<hr data-start=\"2744\" data-end=\"2747\" \/>\n<h2 data-start=\"2749\" data-end=\"2800\">\ud83d\udee0\ufe0f Enhancing Ordering Across Multiple Producers<\/h2>\n<p data-start=\"2802\" data-end=\"2836\">For <strong data-start=\"2806\" data-end=\"2825\">global ordering<\/strong>, you must:<\/p>\n<ul data-start=\"2837\" data-end=\"2997\">\n<li data-start=\"2837\" data-end=\"2873\">\n<p data-start=\"2839\" data-end=\"2873\">Use a <strong data-start=\"2845\" data-end=\"2873\">central sequence manager<\/strong><\/p>\n<\/li>\n<li data-start=\"2874\" data-end=\"2931\">\n<p data-start=\"2876\" data-end=\"2931\">Or enforce <strong data-start=\"2887\" data-end=\"2906\">synchronization<\/strong> at the application level<\/p>\n<\/li>\n<li data-start=\"2932\" data-end=\"2997\">\n<p data-start=\"2934\" data-end=\"2997\">Or switch to <strong data-start=\"2947\" data-end=\"2969\">partitioned topics<\/strong> with ordering per partition<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"2999\" data-end=\"3002\" \/>\n<h2 data-start=\"3004\" data-end=\"3044\">\ud83d\udea7 Challenges in Distributed Ordering<\/h2>\n<ul data-start=\"3046\" data-end=\"3195\">\n<li data-start=\"3046\" data-end=\"3063\">\n<p data-start=\"3048\" data-end=\"3063\">Network latency<\/p>\n<\/li>\n<li data-start=\"3064\" data-end=\"3088\">\n<p data-start=\"3066\" data-end=\"3088\">Message delays or loss<\/p>\n<\/li>\n<li data-start=\"3089\" data-end=\"3143\">\n<p data-start=\"3091\" data-end=\"3143\">Clock synchronization (NTP or Lamport\/Vector clocks)<\/p>\n<\/li>\n<li data-start=\"3144\" data-end=\"3195\">\n<p data-start=\"3146\" data-end=\"3195\">Broker partitioning (if using clustered ActiveMQ)<\/p>\n<\/li>\n<\/ul>\n<hr data-start=\"3197\" data-end=\"3200\" \/>\n<h2 data-start=\"3202\" data-end=\"3220\">\u2705 Summary Table<\/h2>\n<div class=\"_tableContainer_16hzy_1\">\n<div class=\"_tableWrapper_16hzy_14 group flex w-fit flex-col-reverse\">\n<table class=\"w-fit min-w-(--thread-content-width)\" data-start=\"3222\" data-end=\"3576\">\n<thead data-start=\"3222\" data-end=\"3271\">\n<tr data-start=\"3222\" data-end=\"3271\">\n<th data-start=\"3222\" data-end=\"3238\" data-col-size=\"sm\">Ordering Type<\/th>\n<th data-start=\"3238\" data-end=\"3251\" data-col-size=\"sm\">Guarantees<\/th>\n<th data-start=\"3251\" data-end=\"3262\" data-col-size=\"sm\">Use Case<\/th>\n<th data-start=\"3262\" data-end=\"3271\" data-col-size=\"sm\">Tools<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"3322\" data-end=\"3576\">\n<tr data-start=\"3322\" data-end=\"3407\">\n<td data-start=\"3322\" data-end=\"3338\" data-col-size=\"sm\">FIFO<\/td>\n<td data-col-size=\"sm\" data-start=\"3338\" data-end=\"3357\">Order per sender<\/td>\n<td data-col-size=\"sm\" data-start=\"3357\" data-end=\"3377\">Simple logs, Chat<\/td>\n<td data-col-size=\"sm\" data-start=\"3377\" data-end=\"3407\">ActiveMQ w\/ MessageGroupID<\/td>\n<\/tr>\n<tr data-start=\"3408\" data-end=\"3487\">\n<td data-start=\"3408\" data-end=\"3424\" data-col-size=\"sm\">Causal<\/td>\n<td data-col-size=\"sm\" data-start=\"3424\" data-end=\"3446\">Cause-before-effect<\/td>\n<td data-col-size=\"sm\" data-start=\"3446\" data-end=\"3470\">Collaborative editing<\/td>\n<td data-col-size=\"sm\" data-start=\"3470\" data-end=\"3487\">Vector Clocks<\/td>\n<\/tr>\n<tr data-start=\"3488\" data-end=\"3576\">\n<td data-start=\"3488\" data-end=\"3504\" data-col-size=\"sm\">Total<\/td>\n<td data-col-size=\"sm\" data-start=\"3504\" data-end=\"3530\">Global consistent order<\/td>\n<td data-col-size=\"sm\" data-start=\"3530\" data-end=\"3549\">Banking, Ledgers<\/td>\n<td data-col-size=\"sm\" data-start=\"3549\" data-end=\"3576\">Sequencer, Kafka w\/ key<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"sticky end-(--thread-content-margin) h-0 self-end select-none\">\n<div class=\"absolute end-0 flex items-end\">\u00a0<\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr data-start=\"3578\" data-end=\"3581\" \/>\n<p data-start=\"3583\" data-end=\"3598\">Would you like:<\/p>\n<ul data-start=\"3599\" data-end=\"3731\">\n<li data-start=\"3599\" data-end=\"3645\">\n<p data-start=\"3601\" data-end=\"3645\">A <strong data-start=\"3603\" data-end=\"3617\">PowerPoint<\/strong> version for a presentation?<\/p>\n<\/li>\n<li data-start=\"3646\" data-end=\"3674\">\n<p data-start=\"3648\" data-end=\"3674\">A <strong data-start=\"3650\" data-end=\"3657\">PDF<\/strong> for study notes?<\/p>\n<\/li>\n<li data-start=\"3675\" data-end=\"3731\">\n<p data-start=\"3677\" data-end=\"3731\">Code in <strong data-start=\"3685\" data-end=\"3709\">Python or JavaScript<\/strong> with ActiveMQ client?<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"3733\" data-end=\"3761\" data-is-last-node=\"\" data-is-only-node=\"\">Let me know your preference!<\/p>\n<h3 data-start=\"3733\" data-end=\"3761\"><a href=\"https:\/\/courses.grainger.illinois.edu\/ece428\/sp2021\/assets\/slides\/lect9-after.pdf\" target=\"_blank\" rel=\"noopener\">Multicast Ordering FIFO Ordering algorithm in distributed systems-Maker Activemq Client<\/a><\/h3>\n<h3 class=\"LC20lb MBeuO DKV0Md\"><a href=\"https:\/\/cse.buffalo.edu\/~stevko\/courses\/cse486\/spring19\/lectures\/12-multicast2.pdf\" target=\"_blank\" rel=\"noopener\">FIFO Multicast Totally Ordered Multi<\/a><\/h3>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Multicast Ordering FIFO Ordering algorithm in distributed systems-Maker Activemq Client FIFO Multicast Totally Ordered Mult fifo ordering in distributed system fifo-total ordering algorithm distributed Algorithms based on the FIFO.<\/p>\n","protected":false},"author":64,"featured_media":2576,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[84],"tags":[1306,1307,1308,1309],"class_list":["post-2575","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-distributed-computing","tag-distributed-algorithms-based-on-the-fifo","tag-fifo-multicast-totally-ordered-mult","tag-fifo-ordering-in-distributed-system","tag-fifo-total-ordering-algorithm"],"_links":{"self":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts\/2575","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/users\/64"}],"replies":[{"embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/comments?post=2575"}],"version-history":[{"count":0,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/posts\/2575\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/media\/2576"}],"wp:attachment":[{"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/media?parent=2575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/categories?post=2575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.reilsolar.com\/pdf\/wp-json\/wp\/v2\/tags?post=2575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}