|
|
@ -16,9 +16,10 @@ import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.amqp.core.Message;
|
|
|
|
|
|
|
|
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
|
|
|
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
|
|
|
|
|
|
|
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
|
|
|
|
|
import org.springframework.amqp.rabbit.listener.RabbitListenerEndpointRegistry;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
|
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
@ -28,6 +29,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.concurrent.TimeoutException;
|
|
|
|
import java.util.concurrent.TimeoutException;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -39,7 +41,7 @@ import java.util.concurrent.TimeoutException;
|
|
|
|
**/
|
|
|
|
**/
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@Api(description="复杂对象服务demo")
|
|
|
|
@Api(description="复杂对象服务demo")
|
|
|
|
@RequestMapping(PlatformConstWords.BASE_URL + "/demo")
|
|
|
|
@RequestMapping(PlatformConstWords.BASE_URL + "/demo-redis-mq")
|
|
|
|
public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(DemoRedisMqController.class);
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(DemoRedisMqController.class);
|
|
|
|
|
|
|
|
|
|
|
@ -57,12 +59,33 @@ public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
private RabbitTemplate rabbitTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private RabbitListenerEndpointRegistry rabbitRegistry;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private ConnectionFactory connectionFactory;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* mq工厂,用于生产ack消息
|
|
|
|
* mq工厂,用于生产ack消息
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private CachingConnectionFactory mqFactory;
|
|
|
|
private CachingConnectionFactory mqFactory;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/get-mq-info")
|
|
|
|
|
|
|
|
@ApiOperation(value="获取队列信息")
|
|
|
|
|
|
|
|
public ResultBean getMqInfo(){
|
|
|
|
|
|
|
|
System.out.println(rabbitRegistry.isAutoStartup() + " " + rabbitRegistry.isRunning());
|
|
|
|
|
|
|
|
System.out.println(mqFactory.isPublisherConfirms() + " " + mqFactory.isPublisherReturns());
|
|
|
|
|
|
|
|
System.out.println(connectionFactory);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set<String> ids = rabbitRegistry.getListenerContainerIds();
|
|
|
|
|
|
|
|
for(String id : ids){
|
|
|
|
|
|
|
|
System.out.println("id = "+id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new ResultBean(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/put-cache")
|
|
|
|
@GetMapping(value="/put-cache")
|
|
|
|
@ApiOperation(value="缓存",notes="放入数据")
|
|
|
|
@ApiOperation(value="缓存",notes="放入数据")
|
|
|
|
public ResultBean putCache(){
|
|
|
|
public ResultBean putCache(){
|
|
|
@ -83,7 +106,7 @@ public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
return new ResultBean(true);
|
|
|
|
return new ResultBean(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/send-mq")
|
|
|
|
/*@GetMapping(value="/send-mq")
|
|
|
|
@ApiOperation(value="队列",notes="发送")
|
|
|
|
@ApiOperation(value="队列",notes="发送")
|
|
|
|
public ResultBean sendMQ(String data){
|
|
|
|
public ResultBean sendMQ(String data){
|
|
|
|
String context = "hello : " + data;
|
|
|
|
String context = "hello : " + data;
|
|
|
@ -98,9 +121,9 @@ public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
//this.rabbitTemplate.convertAndSend(I3CoreQueueConfig.DEMO_OBJ_QUEUE, new MachineFactory("111mq","rabbit"));
|
|
|
|
//this.rabbitTemplate.convertAndSend(I3CoreQueueConfig.DEMO_OBJ_QUEUE, new MachineFactory("111mq","rabbit"));
|
|
|
|
|
|
|
|
|
|
|
|
return new ResultBean(true,"操作成功");
|
|
|
|
return new ResultBean(true,"操作成功");
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/get-mq-handle")
|
|
|
|
/*@GetMapping(value="/get-mq-handle")
|
|
|
|
@ApiOperation(value="手动获取队列",notes="接收队列")
|
|
|
|
@ApiOperation(value="手动获取队列",notes="接收队列")
|
|
|
|
public ResultBean getHandleMQ(){
|
|
|
|
public ResultBean getHandleMQ(){
|
|
|
|
Object data = this.rabbitTemplate.receiveAndConvert(I3CoreQueueConfig.DEMO_HANDLE_QUEUE);
|
|
|
|
Object data = this.rabbitTemplate.receiveAndConvert(I3CoreQueueConfig.DEMO_HANDLE_QUEUE);
|
|
|
@ -119,7 +142,7 @@ public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return new ResultBean(true,"");
|
|
|
|
return new ResultBean(true,"");
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 有确认或返回的队列
|
|
|
|
* 有确认或返回的队列
|
|
|
@ -129,7 +152,7 @@ public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
* @throws IOException
|
|
|
|
* @throws IOException
|
|
|
|
* @throws TimeoutException
|
|
|
|
* @throws TimeoutException
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@GetMapping(value="/send-returnmsg")
|
|
|
|
/*@GetMapping(value="/send-returnmsg")
|
|
|
|
@ApiOperation(value="队列返回信息",notes="发送")
|
|
|
|
@ApiOperation(value="队列返回信息",notes="发送")
|
|
|
|
public ResultBean sendReturnMQ(int type,String data) throws IOException, TimeoutException {
|
|
|
|
public ResultBean sendReturnMQ(int type,String data) throws IOException, TimeoutException {
|
|
|
|
if(type == 1) {
|
|
|
|
if(type == 1) {
|
|
|
@ -152,16 +175,15 @@ public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
String returnMsg = (String) rabbitTemplate.convertSendAndReceive(I3CoreQueueConfig.DEMO_RETURN_QUEUE, data);
|
|
|
|
String returnMsg = (String) rabbitTemplate.convertSendAndReceive(I3CoreQueueConfig.DEMO_RETURN_QUEUE, data);
|
|
|
|
System.out.println("===返回数据==="+returnMsg);
|
|
|
|
System.out.println("===返回数据==="+returnMsg);
|
|
|
|
return new ResultBean(true,"操作成功");
|
|
|
|
return new ResultBean(true,"操作成功");
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 如果需要进行ack操作,需要添加RabbitListener方法
|
|
|
|
* 如果需要进行ack操作,需要添加RabbitListener方法
|
|
|
|
* @param data
|
|
|
|
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
* @throws IOException
|
|
|
|
* @throws IOException
|
|
|
|
* @throws TimeoutException
|
|
|
|
* @throws TimeoutException
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@GetMapping(value="/send-ackmsg")
|
|
|
|
/*@GetMapping(value="/send-ackmsg")
|
|
|
|
@ApiOperation(value="ack队列",notes="发送")
|
|
|
|
@ApiOperation(value="ack队列",notes="发送")
|
|
|
|
public ResultBean sendAckMQ(String data) throws IOException, TimeoutException {
|
|
|
|
public ResultBean sendAckMQ(String data) throws IOException, TimeoutException {
|
|
|
|
System.out.println("发送ack数据 : " + data);
|
|
|
|
System.out.println("发送ack数据 : " + data);
|
|
|
@ -181,13 +203,13 @@ public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
Message message = rabbitTemplate.receive(I3CoreQueueConfig.DEMO_ACK_QUEUE);
|
|
|
|
Message message = rabbitTemplate.receive(I3CoreQueueConfig.DEMO_ACK_QUEUE);
|
|
|
|
System.out.println("3=============="+message);
|
|
|
|
System.out.println("3=============="+message);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
/*String data = (String) this.rabbitTemplate.receiveAndConvert(I3CoreQueueConfig.DEMO_ACK_QUEUE);
|
|
|
|
*//*String data = (String) this.rabbitTemplate.receiveAndConvert(I3CoreQueueConfig.DEMO_ACK_QUEUE);
|
|
|
|
System.out.println("【client】数据接收成功:" + data);
|
|
|
|
System.out.println("【client】数据接收成功:" + data);
|
|
|
|
|
|
|
|
|
|
|
|
if("ack".equals(data)){
|
|
|
|
if("ack".equals(data)){
|
|
|
|
System.out.println("【client】数据抛出异常");
|
|
|
|
System.out.println("【client】数据抛出异常");
|
|
|
|
throw new RuntimeException("【队列抛出异常】" + data);
|
|
|
|
throw new RuntimeException("【队列抛出异常】" + data);
|
|
|
|
}*/
|
|
|
|
}*//*
|
|
|
|
|
|
|
|
|
|
|
|
String data = (String) this.rabbitTemplate.receiveAndConvert(I3CoreQueueConfig.DEMO_ACK_QUEUE);
|
|
|
|
String data = (String) this.rabbitTemplate.receiveAndConvert(I3CoreQueueConfig.DEMO_ACK_QUEUE);
|
|
|
|
System.out.println("【client】数据接收成功:" + data);
|
|
|
|
System.out.println("【client】数据接收成功:" + data);
|
|
|
@ -211,7 +233,7 @@ public class DemoRedisMqController extends CoreBaseController{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new ResultBean(true,"操作成功");
|
|
|
|
return new ResultBean(true,"操作成功");
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping(value="/exception-demo")
|
|
|
|
@GetMapping(value="/exception-demo")
|
|
|
|
@ApiOperation(value="异常demo",notes="异常demo")
|
|
|
|
@ApiOperation(value="异常demo",notes="异常demo")
|
|
|
|