Skip to main content

Defining messages

Consider the steps involved when ordering a product through our system:

  1. The user creates an order and sends the details to the Order Chain (OC).
  2. OC sends details on what needs to be produced to the Factory Chain (FC).
  3. OC also sends details on what needs to be delivered to the Delivery Chain (DC).
  4. The factory manufactures the products that were ordered.
  5. Delivery prepares for delivering the products when they are ready.
  6. FC notifies DC that the order is ready for shipping.
  7. Delivery delivers the order to the user (off-chain).
  8. The user accepts the delivery.

Let's model this in rell by defining three topics, one for each message we want to send between the chains and the content for each message. Open up a new file called src/messages.rell and add the following.

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;
}
}
info

The initial L_ is required for icmf and indicates that the messages can be accessed only within the same cluster as the sender. Sending global messages (using the G_) prefix is only allowed by system blockchains.