zhubaomin
2024-11-06 2129ea1fca4900b7fcf1c32505fd3929f67bee2e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.dy.pipIrrApp.workOrder;
 
import com.dy.common.aop.SsoAop;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.nio.charset.StandardCharsets;
 
/**
 * @author ZhuBaoMin
 * @date 2024-11-04 9:30
 * @LastEditTime 2024-11-04 9:30
 * @Description 工单控制类
 */
 
@Slf4j
@RestController
@RequestMapping(path = "workOrder")
@RequiredArgsConstructor
public class WorkOrderCtrl {
    private final WorkOrderSv workOrderSv;
 
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
 
 
    @GetMapping("/sendWorkOrder")
    @Transactional(rollbackFor = Exception.class)
    @SsoAop()
    public void sendWorkOrder() throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        ConsumerListener_push ConsumerListener_push = new ConsumerListener_push();
        ConsumerListener_push.receiveMessage();
 
        String topic = "workOrder";
        String tag = "王五";
        String key = "11";
        String message = "Hello World";
        //SendResult sendResult = rocketMQTemplate.syncSend(topic + ":" + tag, message);
        //System.out.println("send result:" + sendResult.toString());
 
        DefaultMQProducer producer = new DefaultMQProducer("producer_group");
        producer.setNamesrvAddr("127.0.0.1:9876");
        producer.start();
        Message msg = new Message(topic,tag,"11",message.getBytes(StandardCharsets.UTF_8));
        SendResult approveSendResult = producer.send(msg);
        System.out.println("send result:" + approveSendResult.toString());
    }
}