87 lines
2.8 KiB
Java
87 lines
2.8 KiB
Java
/*
|
||
* The MIT License (MIT)
|
||
*
|
||
* Copyright © 2020 xrv <xrg@live.com>
|
||
*
|
||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||
* of this software and associated documentation files (the "Software"), to deal
|
||
* in the Software without restriction, including without limitation the rights
|
||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||
* copies of the Software, and to permit persons to whom the Software is
|
||
* furnished to do so, subject to the following conditions:
|
||
*
|
||
* The above copyright notice and this permission notice shall be included in
|
||
* all copies or substantial portions of the Software.
|
||
*
|
||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||
* THE SOFTWARE.
|
||
*/
|
||
|
||
package io.github.ehlxr.springamq.controller;
|
||
|
||
import io.github.ehlxr.springamq.mq.producer.queue.QueueSender;
|
||
import io.github.ehlxr.springamq.mq.producer.topic.TopicSender;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RequestParam;
|
||
import org.springframework.web.bind.annotation.ResponseBody;
|
||
|
||
import javax.annotation.Resource;
|
||
|
||
|
||
/**
|
||
* @description controller测试
|
||
*/
|
||
// @Controller
|
||
// @RequestMapping("/activemq")
|
||
public class ActivemqController {
|
||
|
||
@Resource
|
||
QueueSender queueSender;
|
||
@Resource
|
||
TopicSender topicSender;
|
||
|
||
/**
|
||
* 发送消息到队列
|
||
* Queue队列:仅有一个订阅者会收到消息,消息一旦被处理就不会存在队列中
|
||
* @param message
|
||
* @return String
|
||
*/
|
||
@ResponseBody
|
||
@RequestMapping("queueSender")
|
||
public String queueSender(@RequestParam("message")String message){
|
||
String opt="";
|
||
try {
|
||
queueSender.send("test.queue", message);
|
||
opt = "suc";
|
||
} catch (Exception e) {
|
||
opt = e.getCause().toString();
|
||
}
|
||
return opt;
|
||
}
|
||
|
||
/**
|
||
* 发送消息到主题
|
||
* Topic主题 :放入一个消息,所有订阅者都会收到
|
||
* 这个是主题目的地是一对多的
|
||
* @param message
|
||
* @return String
|
||
*/
|
||
@ResponseBody
|
||
@RequestMapping("topicSender")
|
||
public String topicSender(@RequestParam("message")String message){
|
||
String opt = "";
|
||
try {
|
||
topicSender.send("test.topic", message);
|
||
opt = "suc";
|
||
} catch (Exception e) {
|
||
opt = e.getCause().toString();
|
||
}
|
||
return opt;
|
||
}
|
||
}
|