03 / 07Advanced
Define messages
Here is the sequence of events when someone orders a product through the system:
- The user places an order, and its details go to the Order Chain (OC).
- The OC passes the production requirements on to the Factory Chain (FC).
- The OC also sends the delivery details to the Delivery Chain (DC).
- The factory produces the ordered items.
- Delivery gets ready to ship the items as soon as they are finished.
- The FC tells the DC that the order is ready to ship.
- Delivery brings the order to the user. This step happens off-chain.
- The user confirms that the delivery arrived.
To represent this flow in Rell, you define three topics, one per message passed between the chains, along with the payload each message carries. In the src directory, create a file named messages.rell and add this code:
module;namespace topic { val PRODUCTION_ORDER = "L_production"; val NEW_DELIVERY = "L_delivery"; val SHIPMENT_READY = "L_shipment_ready";}namespace msg { struct order_details { customer_id: integer; address: text; products: list<product>; } struct product { id: integer; quantity: integer; } // Order -> Factory struct production_details { order_id: integer; products: list<product>; } // Order -> Delivery struct delivery_details { order_id: integer; shipping_address: text; customer_id: integer; } // Factory -> Delivery struct shipment_ready { order_id: integer; }}Written for this site from Chromia’s public course. Code samples are the course’s own.