From 97247a23d5bb1168492db2d23c9a096d6d4605e4 Mon Sep 17 00:00:00 2001 From: qiurunze Date: Thu, 10 Jan 2019 18:56:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=20mq=20=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/geekq/miaosha/dao/MiaoShaMessageDao.java | 12 +++++++++--- .../java/com/geekq/miaosha/rabbitmq/MQReceiver.java | 8 +++++--- src/main/resources/application.properties | 6 +++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/geekq/miaosha/dao/MiaoShaMessageDao.java b/src/main/java/com/geekq/miaosha/dao/MiaoShaMessageDao.java index 62bec29..a55669d 100644 --- a/src/main/java/com/geekq/miaosha/dao/MiaoShaMessageDao.java +++ b/src/main/java/com/geekq/miaosha/dao/MiaoShaMessageDao.java @@ -16,7 +16,13 @@ public interface MiaoShaMessageDao { public List listMiaoShaMessage(@Param("messageId") String messageId); @Select("") public List listMiaoShaMessageUser(@Param("messageId") String messageId); -// @Insert("insert into miaosha_user (id , nickname ,password , salt ,head,register_date,last_login_date)value (#{id},#{nickname},#{password},#{salt},#{head},#{registerDate},#{lastLoginDate}) ") -// @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") -// public void insertMiaoShaUser(MiaoshaUser miaoshaUser); + @Insert("insert into miaosha_message (id , messageid ,content , create_time ,status,over_time,message_type ,send_type , goodname , price)" + + "value (#{id},#{messageId},#{content},#{createTime},#{status},#{overTime},#{messageType},#{sendType},#{goodName},#{price}) ") + @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") + public void insertMiaoShaMessage(MiaoShaMessage miaoShaMessage); + + @Insert("insert into miaosha_message_user (id , userid ,messageid , goodid ,orderid)" + + "value (#{id},#{userId},#{messageId},#{goodId},#{orderId}) ") + @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") + public void insertMiaoShaMessageUser(MiaoShaMessageUser miaoShaMessageUser); } diff --git a/src/main/java/com/geekq/miaosha/rabbitmq/MQReceiver.java b/src/main/java/com/geekq/miaosha/rabbitmq/MQReceiver.java index cbd505e..a9d3fe2 100644 --- a/src/main/java/com/geekq/miaosha/rabbitmq/MQReceiver.java +++ b/src/main/java/com/geekq/miaosha/rabbitmq/MQReceiver.java @@ -9,6 +9,7 @@ import com.geekq.miaosha.service.OrderService; import com.geekq.miaosha.vo.GoodsVo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -36,7 +37,7 @@ public class MQReceiver { MiaoshaMessage mm = RedisService.stringToBean(message, MiaoshaMessage.class); MiaoshaUser user = mm.getUser(); long goodsId = mm.getGoodsId(); - + GoodsVo goods = goodsService.getGoodsVoByGoodsId(goodsId); int stock = goods.getStockCount(); if(stock <= 0) { @@ -54,8 +55,9 @@ public class MQReceiver { @RabbitListener(queues=MQConfig.MIAOSHA_MESSAGE) - public void receiveMiaoShaMessage(String message) { - + @RabbitHandler + public void receiveMiaoShaMessage(Object message) { + System.out.println(111111); System.out.println(message); } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 2b2f63d..ff38628 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -25,10 +25,10 @@ spring.datasource.driver-class-name=com.mysql.jdbc.Driver #druid spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.filters=stat -spring.datasource.maxActive=1000 +spring.datasource.maxActive=100 spring.datasource.initialSize=100 -spring.datasource.maxWait=60000 -spring.datasource.minIdle=500 +spring.datasource.maxWait=600 +spring.datasource.minIdle=50 spring.datasource.timeBetweenEvictionRunsMillis=60000 spring.datasource.minEvictableIdleTimeMillis=300000 spring.datasource.validationQuery=select 'x'