| @@ -3,6 +3,7 @@ package com.iformall.controller; | |||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxFlowRecord; | import com.iformall.domain.po.WxFlowRecord; | ||||
| import com.iformall.enums.EnumFlowRecordStatus; | import com.iformall.enums.EnumFlowRecordStatus; | ||||
| import com.iformall.mq.MqProducer; | |||||
| import com.iformall.service.WxFlowService; | import com.iformall.service.WxFlowService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| @@ -26,7 +27,14 @@ public class WxFlowAbleController extends BaseController { | |||||
| private WxFlowService wxFlowService; | private WxFlowService wxFlowService; | ||||
| @Autowired | @Autowired | ||||
| RuntimeService runtimeService; | RuntimeService runtimeService; | ||||
| private MqProducer mqProducer; | |||||
| @ApiOperation(value = "mqSend",notes = "") | |||||
| @PostMapping("/mqSend") | |||||
| public ResultData mqSend() { | |||||
| mqProducer.sendMessage("aaaa","topic-1","tag-1","key1"); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation(value = "启动流程",notes = "{\"businessId\":\"221178539888607232\",\"businessType\":1,\"remark\":\"意见意见。\",\"taskAssignee\":[{\"taskKey\":\"firstTaskUser\",\"assignee\":\"243650055783841792\"},{\"taskKey\":\"secondTaskUser\",\"assignee\":\"\"}],\"variables\":[{\"key\":\"contractType\",\"value\":\"1\"},{\"key\":\"contractNumber\",\"value\":\"1111\"}]}") | @ApiOperation(value = "启动流程",notes = "{\"businessId\":\"221178539888607232\",\"businessType\":1,\"remark\":\"意见意见。\",\"taskAssignee\":[{\"taskKey\":\"firstTaskUser\",\"assignee\":\"243650055783841792\"},{\"taskKey\":\"secondTaskUser\",\"assignee\":\"\"}],\"variables\":[{\"key\":\"contractType\",\"value\":\"1\"},{\"key\":\"contractNumber\",\"value\":\"1111\"}]}") | ||||
| @PostMapping("/start") | @PostMapping("/start") | ||||
| public ResultData start(@RequestBody Map<String, Object> params) { | public ResultData start(@RequestBody Map<String, Object> params) { | ||||
| @@ -53,6 +53,16 @@ spring: | |||||
| auth: true | auth: true | ||||
| starttls: | starttls: | ||||
| enable: true | enable: true | ||||
| rocketmq: | |||||
| nameServer: 127.0.0.1:9876 | |||||
| producer: | |||||
| retry-times-when-send-async-failed: 0 | |||||
| send-msg-timeout: 300000 | |||||
| compress-msg-body-over-howmuch: 4096 | |||||
| max-message-size: 4194304 | |||||
| retry-another-broker-when-not-store-ok: false | |||||
| retry-times-when-send-failed: 2 | |||||
| aws: | aws: | ||||
| clientRegion: cn-northwest-1 | clientRegion: cn-northwest-1 | ||||
| bucketName: iformall-net | bucketName: iformall-net | ||||
| @@ -5,6 +5,7 @@ import com.iformall.mq.MQConfig; | |||||
| import com.iformall.mq.MqBaseProducer; | import com.iformall.mq.MqBaseProducer; | ||||
| import com.iformall.mq.impl.RabbitMqMessageProducer; | import com.iformall.mq.impl.RabbitMqMessageProducer; | ||||
| import com.iformall.mq.impl.RocketMqMessageProducer; | import com.iformall.mq.impl.RocketMqMessageProducer; | ||||
| import com.iformall.mq.MqProducer; | |||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| @@ -29,6 +30,7 @@ public class HomeController { | |||||
| @Autowired | @Autowired | ||||
| private RabbitMqMessageProducer rabbitMqMessageProducer; | private RabbitMqMessageProducer rabbitMqMessageProducer; | ||||
| private MqProducer mqProducer; | |||||
| @ApiOperation("获取后端版本号") | @ApiOperation("获取后端版本号") | ||||
| @@ -40,6 +42,7 @@ public class HomeController { | |||||
| @GetMapping("/mqtest") | @GetMapping("/mqtest") | ||||
| public ResultData mqtest() { | public ResultData mqtest() { | ||||
| mqBaseProducer.sendMessage("mq test 1", "topic-1", "tag-1", "key-1"); | mqBaseProducer.sendMessage("mq test 1", "topic-1", "tag-1", "key-1"); | ||||
| mqProducer.sendMessage("mq test 1", "topic-1", "tag-1", "key-1"); | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,62 @@ | |||||
| package com.iformall.mq; | |||||
| import lombok.extern.slf4j.Slf4j; | |||||
| import org.apache.rocketmq.client.producer.DefaultMQProducer; | |||||
| import org.apache.rocketmq.client.producer.SendCallback; | |||||
| import org.apache.rocketmq.client.producer.SendResult; | |||||
| import org.apache.rocketmq.common.message.Message; | |||||
| import org.apache.rocketmq.remoting.common.RemotingHelper; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Value; | |||||
| import org.springframework.stereotype.Service; | |||||
| import javax.annotation.PostConstruct; | |||||
| /** | |||||
| * @Auther: luozukai | |||||
| * @Date: 2019-01-31 | |||||
| * @Description: RocketMQ消息生产者 | |||||
| */ | |||||
| @Service | |||||
| @Slf4j | |||||
| public class MqProducer { | |||||
| private final Logger log = LoggerFactory.getLogger(this.getClass()); | |||||
| private static final DefaultMQProducer producer = new DefaultMQProducer("DefaultProducer"); | |||||
| @Value("${spring.rocketmq.nameServer}") | |||||
| private String namesrvAddr; | |||||
| @PostConstruct | |||||
| public void start(){ | |||||
| try { | |||||
| producer.setNamesrvAddr(namesrvAddr); | |||||
| producer.start(); | |||||
| log.info("Message Producer Start..."); | |||||
| }catch (Exception e){ | |||||
| log.error("Message Producer Start Error!!",e); | |||||
| } | |||||
| } | |||||
| public void sendMessage(String data, String topic, String tags, String keys) { | |||||
| try { | |||||
| byte[] messageBody = data.getBytes(RemotingHelper.DEFAULT_CHARSET); | |||||
| Message mqMsg = new Message(topic, tags, keys, messageBody); | |||||
| producer.send(mqMsg, new SendCallback() { | |||||
| @Override | |||||
| public void onSuccess(SendResult sendResult) { | |||||
| log.info("Message Producer: Send Message Success {}", sendResult); | |||||
| } | |||||
| @Override | |||||
| public void onException(Throwable throwable) { | |||||
| log.error("Message Producer: Send Message Error ", throwable); | |||||
| } | |||||
| }); | |||||
| } catch (Exception e) { | |||||
| log.error("Message Producer: Send Message Error ", e); | |||||
| } | |||||
| } | |||||
| } | |||||