Messages
Write calls, replies and async messages in sequence code, with slow messages, crosses, lost messages and messages from outside.
A message is a line with a sender, an arrow, a receiver, then a colon and its text. The arrow says what kind of message it is.
Write a message
Shopper->Shop: Pay for order
Shop-->Shopper: Order placed
Shop->>Queue: Order paid
Worker->Worker: Wait before retrying| Arrow | Kind | Drawn as |
|---|---|---|
-> | Call | Solid line, filled head. The sender waits for an answer. |
--> | Reply | Dashed line. It answers an earlier call. |
->> | Async | Solid line, open head. Nobody waits. |
A message can go from a participant to itself. In message text, \n starts a new line in the label.
Text after the colon is all message text, so it can hold URLs, paths and //: Client->API: GET https://api.example.com/v1.
Arrows that point left
An arrow can also point left, as sequencediagram.org writes it. Shopper<--Shop: Order placed is the same message as Shop-->Shopper: Order placed.
<- is a call, <-- a reply and <<- an async message. -->> reads as a reply too. When you change the diagram on the canvas, the app writes the line left to right.
Messages that take time
Shop->(2)Bank: Transfer fundsA number in brackets after the arrow means the message takes time to arrive. Its line slants down to the receiver by that many steps, from 1 to 20. Use it for slow hops, such as a bank transfer or a letter in the post.
Message ends
Shop<->Payments: Sync order
Payments->x Bank: Refund card
Payments-->o Bank: Refund later
[->Shop: Refund requested
Shop->]: Refunded| Code | Drawn as |
|---|---|
A<->B | A head at both ends: the message goes both ways. <--> and <->> work too. |
A->x B | A cross at the end: the message fails. |
A->o B | A filled circle at the end, short of the receiver: the message is lost. |
A o->B | A filled circle at the start: the message is found, from a sender the diagram doesn't show. |
[->B | From outside the diagram, with a circle at the left edge. |
A->] | Out of the diagram, with a circle past the column. |
How the app reads x and o
The x or o after the arrow needs a space after it, so A->xavier is still a message to xavier.
When the name after the x is a participant the diagram has, declared anywhere in it, the x is the cross. So A->xB fails at B.
Mermaid's -x and --x are a call and a reply that end in a cross: A-xB: Retry.