This commit is contained in:
xiangwb
2018-05-02 15:12:39 +08:00
parent 9738f5684d
commit 6a7421a320
7 changed files with 61 additions and 40 deletions
@@ -1,14 +1,17 @@
package com.xwbing.rabbit;
import com.xwbing.service.rest.MailService;
import com.xwbing.util.RestMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.text.MessageFormat;
import static com.xwbing.rabbit.RabbitConstant.EMAIL_QUEUE;
import static com.xwbing.rabbit.RabbitConstant.HTTP_REQUEST_QUEUE;
import static com.xwbing.rabbit.RabbitConstant.SERVER_INVOKE_QUEUE;
/**
* 项目名称: boot-module-demo
@@ -18,18 +21,22 @@ import static com.xwbing.rabbit.RabbitConstant.SERVER_INVOKE_QUEUE;
*/
@Component
public class Receiver {
@Resource
private MailService mailService;
private final Logger logger = LoggerFactory.getLogger(Receiver.class);
/**
* 处理server队列信息
* 处理邮件队列信息
*
* @param msg
* @return
*/
@RabbitListener(queues = SERVER_INVOKE_QUEUE)
public String processServer(String msg) {
String response = MessageFormat.format("收到{0}队列的消息:{1}", SERVER_INVOKE_QUEUE, msg);
return response.toUpperCase();
@RabbitListener(queues = EMAIL_QUEUE)
public String processEmail(String[] msg) {
String format = MessageFormat.format("你的用户名是:{0},密码是:{1}", msg[1], msg[2]);
RestMessage restMessage = mailService.sendSimpleMail(msg[0], "注册成功", format);
boolean success = restMessage.isSuccess();
return MessageFormat.format("成功发送邮件给{0}:{1}", msg[1], success);
}
/**
@@ -38,7 +45,7 @@ public class Receiver {
* @param msg
*/
@RabbitListener(queues = HTTP_REQUEST_QUEUE)
public String processHttp(String msg) {
public String processHttp(String[] msg) {
String response = MessageFormat.format("收到{0}队列的消息:{1}", HTTP_REQUEST_QUEUE, msg);
return response.toUpperCase();
}