Commit 4e9181b29f1388f7cf91014a2534966e7fe79d42

Authored by Jiang
1 parent 033bee1e

增加mq发送

dtms-client/src/main/java/com/b2c/dtms/client/domain/dto/request/DtmsProduceRequestDto.java
... ... @@ -26,6 +26,11 @@ public class DtmsProduceRequestDto implements Serializable {
26 26 private Date runtime;
27 27  
28 28 /**
  29 + * 消息主题
  30 + */
  31 + private String topic;
  32 +
  33 + /**
29 34 * 消息内容
30 35 */
31 36 private String content;
... ... @@ -77,6 +82,14 @@ public class DtmsProduceRequestDto implements Serializable {
77 82 this.runtime = runtime;
78 83 }
79 84  
  85 + public String getTopic() {
  86 + return topic;
  87 + }
  88 +
  89 + public void setTopic(String topic) {
  90 + this.topic = topic;
  91 + }
  92 +
80 93 public String getContent() {
81 94 return content;
82 95 }
... ... @@ -124,4 +137,5 @@ public class DtmsProduceRequestDto implements Serializable {
124 137 public void setType(Integer type) {
125 138 this.type = type;
126 139 }
  140 +
127 141 }
... ...
dtms-dao/src/main/resources/sqlmap-config.xml
... ... @@ -11,7 +11,7 @@
11 11 <setting name="useColumnLabel" value="true" />
12 12 <!-- 数据库超过25000秒仍未响应则超时 -->
13 13 <setting name="defaultStatementTimeout" value="25000" />
14   - <setting name="logImpl" value="STDOUT_LOGGING" />
  14 + <!-- <setting name="logImpl" value="STDOUT_LOGGING" /> -->
15 15 </settings>
16 16  
17 17 <!-- 全局别名设置,在映射文件中只需写别名,而不必写出整个类路径 -->
... ...
dtms-domain/pom.xml
... ... @@ -10,6 +10,11 @@
10 10  
11 11 <dependencies>
12 12 <dependency>
  13 + <groupId>${project.groupId}</groupId>
  14 + <artifactId>dtms-rpc</artifactId>
  15 + <version>${project.parent.version}</version>
  16 + </dependency>
  17 + <dependency>
13 18 <groupId>org.springframework</groupId>
14 19 <artifactId>spring-webmvc</artifactId>
15 20 <exclusions>
... ...
dtms-rpc/pom.xml 0 → 100644
  1 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3 + <modelVersion>4.0.0</modelVersion>
  4 + <parent>
  5 + <groupId>com.b2c.dtms</groupId>
  6 + <artifactId>dtms-parent</artifactId>
  7 + <version>0.0.1-SNAPSHOT</version>
  8 + </parent>
  9 + <artifactId>dtms-rpc</artifactId>
  10 +
  11 + <dependencies>
  12 +
  13 + <!-- 消息中心/待办事项 -->
  14 + <dependency>
  15 + <groupId>com.yqyw.messageCenter.sdk</groupId>
  16 + <artifactId>diligrp-messageCenter-sdk</artifactId>
  17 + </dependency>
  18 + </dependencies>
  19 +
  20 +</project>
0 21 \ No newline at end of file
... ...
dtms-rpc/src/main/java/com/b2c/dtms/service/rpc/MqService.java 0 → 100644
  1 +package com.b2c.dtms.service.rpc;
  2 +
  3 +import com.alibaba.rocketmq.common.message.Message;
  4 +import com.diligrp.util.exception.DiliUtilException;
  5 +
  6 +
  7 +
  8 +/**
  9 + *
  10 + * <B>Description</B> MQ服务 <br />
  11 + * <B>Copyright</B> Copyright (c) 2014 www.diligrp.com All rights reserved. <br />
  12 + * 本软件源代码版权归地利集团,未经许可不得任意复制与传播.<br />
  13 + * <B>Company</B> 地利集团
  14 + * @createTime 2014年7月14日 下午18:15:16
  15 + * @author xiongdeqiang
  16 + */
  17 +public interface MqService {
  18 + public void sendOrderMQ(Message message, String order) throws DiliUtilException;
  19 +
  20 + public void sendMQ(Message message) throws DiliUtilException;
  21 +}
... ...
dtms-rpc/src/main/java/com/b2c/dtms/service/rpc/impl/MqServiceImpl.java 0 → 100644
  1 +package com.b2c.dtms.service.rpc.impl;
  2 +
  3 +import javax.annotation.Resource;
  4 +
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
  7 +import org.springframework.stereotype.Service;
  8 +
  9 +import com.alibaba.fastjson.JSONObject;
  10 +import com.alibaba.rocketmq.common.message.Message;
  11 +import com.b2c.dtms.service.rpc.MqService;
  12 +import com.diligrp.util.exception.DiliUtilException;
  13 +import com.diligrp.util.rocketMQUtil.DiliMQProducer;
  14 +
  15 +@Service("rpcMqService")
  16 +public class MqServiceImpl implements MqService {
  17 +
  18 + private static final Logger LOGGER = LoggerFactory.getLogger(MqServiceImpl.class);
  19 +
  20 + @Resource
  21 + private DiliMQProducer diliMQProducer;
  22 + // @Resource
  23 + // private ConfigurationInfoService rpcConfigInfoService;
  24 + // private String hotLine;
  25 +
  26 + /*
  27 + * @PostConstruct public void init() { hotLine =
  28 + * rpcConfigInfoService.getHotLineNo(); }
  29 + */
  30 + @Override
  31 + public void sendOrderMQ(Message message, String order) throws DiliUtilException {
  32 + LOGGER.info("发送有序MQ");
  33 + LOGGER.info("发送有序MQ:" + JSONObject.toJSONString(message));
  34 + diliMQProducer.sendOrderMsg(message, order);
  35 + }
  36 +
  37 + @Override
  38 + public void sendMQ(Message message) throws DiliUtilException {
  39 + LOGGER.info("发送MQ");
  40 + diliMQProducer.sendMsg(message);
  41 + }
  42 +}
... ...
dtms-service/src/main/java/com/b2c/dtms/handler/MqHandlerImpl.java 0 → 100644
  1 +package com.b2c.dtms.handler;
  2 +
  3 +import java.nio.charset.Charset;
  4 +import java.util.Map;
  5 +
  6 +import javax.annotation.Resource;
  7 +
  8 +import org.apache.commons.lang3.StringUtils;
  9 +import org.nutz.json.Json;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.stereotype.Service;
  13 +
  14 +import com.alibaba.fastjson.JSON;
  15 +import com.alibaba.rocketmq.common.message.Message;
  16 +import com.b2c.dtms.common.enums.dtms.DtmsMessageTopic;
  17 +import com.b2c.dtms.common.enums.dtms.HandleCode;
  18 +import com.b2c.dtms.domain.DtmsMessage;
  19 +import com.b2c.dtms.service.rpc.MqService;
  20 +
  21 +/**
  22 + * 发送MQ-消息转发专用
  23 + */
  24 +@Service
  25 +public class MqHandlerImpl extends DtmsHandler {
  26 + private static final Logger LOGGER = LoggerFactory.getLogger(MqHandlerImpl.class);
  27 + @Resource
  28 + private MqService rpcMqService;
  29 +
  30 + @Override
  31 + public boolean isSupported(DtmsMessage messsage) {
  32 + if (messsage == null) {
  33 + return false;
  34 + }
  35 + return StringUtils.equals(DtmsMessageTopic.SendMq.code(), messsage.getTopic());
  36 + }
  37 +
  38 + @SuppressWarnings("unchecked")
  39 + @Override
  40 + public boolean doExecute(DtmsHandleContext ctx) {
  41 + DtmsMessage dtmsMessage = ctx.getWaitHandleDtmsMessage();
  42 + String logMsg = null;
  43 + try {
  44 + Map<String, Object> contentMap = (Map<String, Object>) JSON.parse(dtmsMessage.getContent());
  45 + String topic = (String) contentMap.get("topic");
  46 + String tag = (String) contentMap.get("tag");
  47 + contentMap.remove("topic");
  48 + contentMap.remove("tag");
  49 +
  50 + String order = String.valueOf(contentMap.get("orderId"));
  51 + String jsonBpdy = Json.toJson(contentMap);
  52 + LOGGER.info("mq body:" + jsonBpdy);
  53 +
  54 + byte[] body = jsonBpdy.getBytes(Charset.forName("UTF8"));
  55 + Message message = new Message(topic, tag, body);
  56 + rpcMqService.sendOrderMQ(message, order);
  57 +
  58 + logMsg = String.format("[DTMS]消息ID%s:处理成功,发送mq", dtmsMessage.getId());
  59 + ctx.setReturnCode(HandleCode.SUCCESS.code());
  60 + ctx.setReturnMessage(logMsg);
  61 + return true;
  62 + } catch (Exception e) {
  63 + ctx.setReturnCode(HandleCode.FAILED.code());
  64 + logMsg = String.format("[DTMS]消息ID%s:处理失败,发生异常[%s],需等待再次执行", dtmsMessage.getId(), e.getMessage());
  65 + ctx.setReturnMessage(logMsg);
  66 + loggerException(dtmsMessage, e);
  67 + return false;
  68 + }
  69 + }
  70 +}
... ...
dtms-web/src/main/java/com/b2c/dtms/web/restful/DtmsRestController.java
... ... @@ -28,7 +28,6 @@ public class DtmsRestController {
28 28 DtmsMessage message = new DtmsMessage();
29 29 copier.copy(request, message, null);
30 30 message.setVersion(1L);
31   - message.setTopic("CallUrl");
32 31 Long id;
33 32 try {
34 33 id = this.producer.produce(message);
... ...
dtms-web/src/main/resources/spring-rpc.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<beans xmlns="http://www.springframework.org/schema/beans"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  4 + xmlns:aop="http://www.springframework.org/schema/aop" xmlns:cache="http://www.springframework.org/schema/cache"
  5 + xsi:schemaLocation="http://www.springframework.org/schema/beans
  6 + http://www.springframework.org/schema/beans/spring-beans.xsd
  7 + http://www.springframework.org/schema/context
  8 + http://www.springframework.org/schema/context/spring-context.xsd
  9 + http://www.springframework.org/schema/aop
  10 + http://www.springframework.org/schema/aop/spring-aop.xsd
  11 + http://www.springframework.org/schema/cache
  12 + http://www.springframework.org/schema/cache/spring-cache.xsd"
  13 + default-autowire="byName">
  14 +
  15 + <bean id="diliMQProducer" class="com.diligrp.util.rocketMQUtil.impl.DiliMQProducerImpl" />
  16 +</beans>
0 17 \ No newline at end of file
... ...
dtms-web/src/main/resources/spring.xml
... ... @@ -57,4 +57,5 @@
57 57 <import resource="classpath*:spring-dao.xml" />
58 58 <import resource="classpath*:spring-redis.xml" />
59 59 <import resource="classpath*:spring-dtms.xml" />
  60 + <import resource="classpath*:spring-rpc.xml" />
60 61 </beans>
61 62 \ No newline at end of file
... ...
... ... @@ -427,7 +427,7 @@
427 427 <!-- 店铺接口签名 -->
428 428 <orders.rpc.shopClient.sign>FzZGZxd2VycXdlYXNzZHZzdnp4Y3Z</orders.rpc.shopClient.sign>
429 429 <!-- 消息中心配置 -->
430   - <mq.namesrvAddr>10.28.11.158:9876</mq.namesrvAddr>
  430 + <mq.namesrvAddr>10.28.10.215:9876</mq.namesrvAddr>
431 431 <mq.producerGroup>orders</mq.producerGroup>
432 432 </properties>
433 433 </profile>
... ... @@ -514,5 +514,6 @@
514 514 <module>dtms-dao</module>
515 515 <module>dtms-web</module>
516 516 <module>dtms-client</module>
  517 + <module>dtms-rpc</module>
517 518 </modules>
518 519 </project>
519 520 \ No newline at end of file
... ...