budd/src/main/java/osc/git/eh3/springamq/controller/ActivemqController.java

66 lines
1.5 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package osc.git.eh3.springamq.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import osc.git.eh3.springamq.mq.producer.queue.QueueSender;
import osc.git.eh3.springamq.mq.producer.topic.TopicSender;
import javax.annotation.Resource;
/**
*
* @author liang
* @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;
}
}