package com.ktg.web.controller.common;

import com.ktg.common.utils.rocketmq.RocketMQProducerManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "mq测试")
@RestController
@RequestMapping("/test")
public class OrderController {
    private final RocketMQProducerManager producerManager;

    // 通过构造函数注入生产者管理器
    public OrderController(RocketMQProducerManager producerManager) {
        this.producerManager = producerManager;
    }

    @ApiOperation("发送消息测试")
    @GetMapping("/create-order")
    public String createOrder() throws Exception {
        // 使用order-producer发送订单创建消息
        producerManager.sendSync(
                "order-producer", // 生产者名称
                "order_topic",    // Topic
                "create",         // Tag
                "order_123",      // Key
                "订单创建内容".getBytes() // 消息体
        );
        return "Order created";
    }
}
