autonumber '第一个参与者 participant participant as Foo #red '角色 actor actor as Foo1 '边界 boundary boundary as Foo2 '控制 control control as Foo3 '实体 entity entity as Foo4 '数据库 database database as Foo5 '集合 collections collections as Foo6 '队列 queue Queue
Foo -> Foo1 : To actor Foo -> Foo2 : To boundary Foo -> Foo3 : To control Foo -> Foo4 : To entity Foo -> Foo5 : To database Foo -> Foo6 : To collections Foo -> Queue : To queue Foo5 <- Queue : back database
@startuml 'https://plantuml.com/sequence-diagram ' 5和7对齐 skinparam responseMessageBelowArrow true autonumber participant participant as Foo #ff00ff actor actor as Foo1 participant Foo4 order 30 #00ff00 participant Foo3 order 20 participant Foo2 order 10
Foo -> Foo1 : To actor Foo -> Foo2 : To boundary Foo2 -> Foo3: to foo3 Foo2--> Foo3: again to foo3 Foo3--> Foo4: to foo4 Foo -> Foo: loop Foo3 <- Foo4: back Foo3
Bob ->x Alice: hello Alice -> June June ->> Leo Leo -[#00ffff]\ Eric Leo \\[#ff0000]- Eric June //-[#ff00ff]- Leo June ->o Leo June o\\-- Leo June <-> Alice Bob <->o Alice
@startuml 'https://plantuml.com/sequence-diagram header Page Header footer Page %page% of %lastpage%
title Example Title Alice -> Bob : message 1 Alice -> Bob : message 2
newpage
header Page Header footer Page %page% of %lastpage%
Alice -> Bob : message 3 Alice -> Bob : message 4
newpage A title for the\nlast page
Alice -> Bob : message 5 Alice -> Bob : message 6
@enduml
组合消息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
@startuml 'https://plantuml.com/sequence-diagram Alice -> Bob: 认证请求
alt 成功情况 Bob -> Alice: 认证接受 else 某种失败情况 Bob -> Alice: 认证失败 group 我自己的标签 Alice -> Log : 开始记录攻击日志 loop 1000次数 Alice -> Bob: DNS 攻击 end end else 另一种失败 Bob -> Alice: 请重复 end
@enduml
alt/else
opt
loop
par
break
critical
group, 后面紧跟着消息内容
消息注释
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
@startuml 'https://plantuml.com/sequence-diagram Alice -> Bob: 认证请求 note left #bbbbbb : this is a first note
Bob -> Alice: 认证失败 note right : this is a second note
Bob -> Bob note left #ff00ff loop a b c end note @enduml
@startuml caller -> server : conReq hnote over caller : 空闲 caller <- server : conConf rnote over server "r"是正方形 "h"是六边形 endrnote rnote over server 多 行 文本 endrnote
hnote over server,caller 跨越多行 endhnote server -> proxy note across :跨越所有参与者
@enduml
在同一级对齐多个备注 [/]
1 2 3 4 5 6
@startuml caller -> server : conReq note over caller : call init / note over server: call init caller <- server : conConf @enduml
@startuml participant Alice participant "The **Famous** Bob" as Bob
Alice -> Bob : hello --there-- ... Some ~~long delay~~ ... Bob -> Alice : ok note left This is **bold** This is //italics// This is ""monospaced"" This is --stroked-- This is __underlined__ This is ~~waved~~ end note
Alice -> Bob : A //well formatted// message note right of Alice This is <back:cadetblue><size:18>displayed</size></back> __left of__ Alice. end note note left of Bob <u:red>This</u> is <color #118888>displayed</color> **<color purple>left of</color> <s:red>Alice</strike> Bob**. end note note over Alice, Bob <w:#FF33FF>This is hosted</w> by <img sourceforge.jpg> end note @enduml
分隔符
1 2 3 4 5 6 7
@startuml == request == participant 我是参与者A as A A -> B : request == response == A <- B : response @enduml
引用
1 2 3 4 5 6 7 8 9 10 11 12
@startuml participant Alice actor Bob
ref over Alice,Bob:init Alice -> Bob : hello
ref over Bob hi i am bob end ref @enduml
延迟
1 2 3 4 5 6 7 8 9 10
@startuml A -> B ...
B -> A
... 延迟...
A -> B @enduml
文本换行
1 2 3 4 5 6
@startuml skinparam maxMessageSize 50 A -> B : r\ne\nq\nu\ne\ns\nt
A <- B : reponse a b c d e @enduml
空间
1 2 3 4 5 6 7 8 9
@startuml A -> B: request A -> B: request A -> B: request ||| A -> B: request ||100|| A -> B: request @enduml
@startuml A -> B: request activate B #ff00ff B -> B: loop
activate B B -> C: request deactivate B
activate C C -> D: request activate D
C <- D: response destroy D B <- C: response deactivate C A <- B: response deactivate B @enduml
1 2 3 4 5 6 7 8 9 10 11 12
@startuml autoactivate on alice -> bob : hello bob -> bob : self call bill -> bob #005500 : hello from thread 2 bob -> george ** : create return done in thread 2 return rc bob -> george !! : delete return success
@startuml participant Alice as a participant Bob as b a -> b : ""-> "" a ->> b : ""->> "" a -\ b : ""-\ "" a -\\ b : ""-\\\\"" a -/ b : ""-/ "" a -// b : ""-// "" a ->x b : ""->x "" a x-> b : ""x-> "" a o-> b : ""o-> "" a ->o b : ""->o "" a o->o b : ""o->o "" a <-> b : ""<-> "" a o<->o b : ""o<->o"" a x<->x b : ""x<->x"" a ->>o b : ""->>o "" a -\o b : ""-\o "" a -\\o b : ""-\\\\o"" a -/o b : ""-/o "" a -//o b : ""-//o "" a x->o b : ""x->o "" @enduml
@startuml participant Alice as a participant Bob as b [-> b : ""[-> "" [->> b : ""[->> "" [-\ b : ""[-\ "" [-\\ b : ""[-\\\\"" [-/ b : ""[-/ "" [-// b : ""[-// "" [->x b : ""[->x "" [x-> b : ""[x-> "" [o-> b : ""[o-> "" [->o b : ""[->o "" [o->o b : ""[o->o "" [<-> b : ""[<-> "" [o<->o b : ""[o<->o"" [x<->x b : ""[x<->x"" [->>o b : ""[->>o "" [-\o b : ""[-\o "" [-\\o b : ""[-\\\\o"" [-/o b : ""[-/o "" [-//o b : ""[-//o "" [x->o b : ""[x->o "" @enduml
@startuml participant Alice as a participant Bob as b a ->] : ""->] "" a ->>] : ""->>] "" a -\] : ""-\] "" a -\\] : ""-\\\\]"" a -/] : ""-/] "" a -//] : ""-//] "" a ->x] : ""->x] "" a x->] : ""x->] "" a o->] : ""o->] "" a ->o] : ""->o] "" a o->o] : ""o->o] "" a <->] : ""<->] "" a o<->o] : ""o<->o]"" a x<->x] : ""x<->x]"" a ->>o] : ""->>o] "" a -\o] : ""-\o] "" a -\\o] : ""-\\\\o]"" a -/o] : ""-/o] "" a -//o] : ""-//o] "" a x->o] : ""x->o] "" @enduml
@startuml participant Alice as a participant Bob as b a -> b : //Long long label// ?-> b : ""?-> "" ?->> b : ""?->> "" ?-\ b : ""?-\ "" ?-\\ b : ""?-\\\\"" ?-/ b : ""?-/ "" ?-// b : ""?-// "" ?->x b : ""?->x "" ?x-> b : ""?x-> "" ?o-> b : ""?o-> "" ?->o b : ""?->o "" ?o->o b : ""?o->o "" ?<-> b : ""?<-> "" ?o<->o b : ""?o<->o"" ?x<->x b : ""?x<->x"" ?->>o b : ""?->>o "" ?-\o b : ""?-\o "" ?-\\o b : ""?-\\\\o "" ?-/o b : ""?-/o "" ?-//o b : ""?-//o "" ?x->o b : ""?x->o "" @enduml
@startuml participant Alice as a participant Bob as b a -> b : //Long long label// a ->? : ""->? "" a ->>? : ""->>? "" a -\? : ""-\? "" a -\\? : ""-\\\\?"" a -/? : ""-/? "" a -//? : ""-//? "" a ->x? : ""->x? "" a x->? : ""x->? "" a o->? : ""o->? "" a ->o? : ""->o? "" a o->o? : ""o->o? "" a <->? : ""<->? "" a o<->o? : ""o<->o?"" a x<->x? : ""x<->x?"" a ->>o? : ""->>o? "" a -\o? : ""-\o? "" a -\\o? : ""-\\\\o?"" a -/o? : ""-/o? "" a -//o? : ""-//o? "" a x->o? : ""x->o? "" @enduml