11package com .github .cadecode .uniboot .example .svc .controller ;
22
3+ import com .github .cadecode .uniboot .common .plugin .mq .model .TxMsg ;
34import com .github .cadecode .uniboot .common .plugin .mq .util .RabbitUtil ;
5+ import com .github .cadecode .uniboot .common .plugin .mq .util .TxMsgKit ;
46import com .github .cadecode .uniboot .example .svc .bean .data .ExampleMsgDo ;
57import com .github .cadecode .uniboot .framework .base .annotation .ApiFormat ;
68import io .swagger .annotations .Api ;
79import io .swagger .annotations .ApiOperation ;
810import lombok .RequiredArgsConstructor ;
911import lombok .extern .slf4j .Slf4j ;
12+ import org .springframework .transaction .annotation .Transactional ;
1013import org .springframework .web .bind .annotation .GetMapping ;
1114import org .springframework .web .bind .annotation .RequestMapping ;
1215import org .springframework .web .bind .annotation .RequestParam ;
2629@ RequestMapping ("demo/mq" )
2730public class MqExampleController {
2831
32+ private final TxMsgKit txMsgKit ;
33+
2934 @ ApiOperation ("发送 delay 消息" )
3035 @ GetMapping ("send_delay" )
3136 public boolean sendDelay (@ RequestParam String exchange , @ RequestParam String routingKey , @ RequestParam Integer ms ) {
@@ -47,5 +52,19 @@ public boolean sendObj(@RequestParam String exchange, @RequestParam String routi
4752 RabbitUtil .send (exchange , routingKey , msgDo );
4853 return true ;
4954 }
55+
56+ @ Transactional (rollbackFor = Exception .class )
57+ @ ApiOperation ("发送事务消息" )
58+ @ GetMapping ("send_tx" )
59+ public boolean sendTx (@ RequestParam String exchange , @ RequestParam String routingKey ) {
60+ txMsgKit .sendTx (TxMsg .builder ()
61+ .bizType ("Test biz" )
62+ .bizKey ("TestBiz001" )
63+ .exchange (exchange )
64+ .routingKey (routingKey )
65+ .message ("Test TxMsg" )
66+ .build ());
67+ return true ;
68+ }
5069}
5170
0 commit comments