| | |
| | | import org.quartz.SchedulerException; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.amqp.core.Message; |
| | | import org.springframework.amqp.core.MessageProperties; |
| | | import org.springframework.amqp.rabbit.core.RabbitTemplate; |
| | | import org.springframework.cache.ehcache.EhCacheCacheManager; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.*; |
| | | import java.math.BigDecimal; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.*; |
| | | |
| | | @Controller |
| | |
| | | |
| | | @Resource |
| | | private TaoBaoCouponCacheService taoBaoCouponCacheService; |
| | | |
| | | @Resource |
| | | private RabbitTemplate rabbitTemplate; |
| | | |
| | | @RequestMapping(value = "kefu") |
| | | public void kefu(HttpServletRequest request, PrintWriter out) { |
| | |
| | | out.print("success"); |
| | | } |
| | | |
| | | @RequestMapping("testRabbit") |
| | | public void testRabbit(){ |
| | | String msg = "你好:"+TimeUtil.getGernalTime(System.currentTimeMillis(),"yyyy-MM-dd HH:mm:ss"); |
| | | // 向队列发送消息 |
| | | // rabbitTemplate.convertAndSend("order-all-fanli",msg); |
| | | // 向exchange发送消息 |
| | | // rabbitTemplate.convertAndSend("topic_place_order", "*", msg); |
| | | |
| | | // Message message = MessageBuilder.withBody(msg.getBytes()).setDeliveryMode(MessageDeliveryMode.PERSISTENT).setExpiration("10000").build(); |
| | | rabbitTemplate.convertAndSend("test_queue",msg); |
| | | } |
| | | @RequestMapping("testRabbitDelay") |
| | | public void testRabbitDelay(){ |
| | | String msg = "这是测试的一条延时消息"; |
| | | int time = 5; |
| | | MessageProperties messageProperties = new MessageProperties(); |
| | | messageProperties.setHeader("x-delay", 1000 * time);//延迟5秒被删除 |
| | | Message message = new Message(msg.getBytes(StandardCharsets.UTF_8), messageProperties); |
| | | rabbitTemplate.convertAndSend("delay_exchange", "delay", message);//交换机和路由键必须和配置文件类中保持一致 |
| | | System.out.println(TimeUtil.getGernalTime(System.currentTimeMillis(),"yyyy-MM-dd HH:mm:ss") + " 发送一条消息"); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |