1
zhang
1 天以前 23182f2c951df5fa55e70e30ff70ddaf91199a2e
zy-acs-hex/src/main/java/com/zy/acs/hex/controller/TestController.java
@@ -1,10 +1,13 @@
package com.zy.acs.hex.controller;
import com.zy.acs.hex.constant.RabbitConstant;
import com.zy.acs.hex.domain.Device;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Slf4j
@@ -16,21 +19,27 @@
    /**
     * 发送消息test1
     *
     * @return
     */
    @GetMapping(value = "/test1")
    public void sendTest1() {
        String router = RabbitConstant.ROUTING_KEY_UP.replaceFirst("\\*", "1").replaceFirst("\\*", "2");
        rabbitTemplate.convertAndSend(RabbitConstant.TOPIC_EXCHANGE,router,"1212321323");
        Device device = new Device();
        //device.setEvent("online");
        //device.setDeviceId("123");
        device.setProtocol("212121212121212");
        String router = RabbitConstant.ROUTING_KEY_UP.replaceFirst("\\*", "123").replaceFirst("\\*", "online");
        rabbitTemplate.convertAndSend(RabbitConstant.TOPIC_EXCHANGE, router, device);
    }
    /**
     * 发送消息test2
     *
     * @return
     */
    @GetMapping(value = "/test2")
    public void sendTest2() {
        rabbitTemplate.convertAndSend(RabbitConstant.TOPIC_EXCHANGE, RabbitConstant.ROUTING_KEY_DOWN,  "qswaqsaasas");
        rabbitTemplate.convertAndSend(RabbitConstant.TOPIC_EXCHANGE, RabbitConstant.ROUTING_KEY_DOWN, "qswaqsaasas");
    }
}