|  | @@ -1,11 +1,15 @@
 | 
												
													
														
															|  |  package com.elab.mq.rocket.template;
 |  |  package com.elab.mq.rocket.template;
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | 
 |  | +import com.elab.mq.rocket.utils.MsgConstants;
 | 
												
													
														
															|  |  import org.apache.rocketmq.client.exception.MQBrokerException;
 |  |  import org.apache.rocketmq.client.exception.MQBrokerException;
 | 
												
													
														
															|  |  import org.apache.rocketmq.client.exception.MQClientException;
 |  |  import org.apache.rocketmq.client.exception.MQClientException;
 | 
												
													
														
															|  |  import org.apache.rocketmq.client.producer.DefaultMQProducer;
 |  |  import org.apache.rocketmq.client.producer.DefaultMQProducer;
 | 
												
													
														
															|  |  import org.apache.rocketmq.client.producer.SendResult;
 |  |  import org.apache.rocketmq.client.producer.SendResult;
 | 
												
													
														
															|  |  import org.apache.rocketmq.common.message.Message;
 |  |  import org.apache.rocketmq.common.message.Message;
 | 
												
													
														
															|  |  import org.apache.rocketmq.remoting.exception.RemotingException;
 |  |  import org.apache.rocketmq.remoting.exception.RemotingException;
 | 
												
													
														
															|  | 
 |  | +import org.slf4j.Logger;
 | 
												
													
														
															|  | 
 |  | +import org.slf4j.LoggerFactory;
 | 
												
													
														
															|  | 
 |  | +import org.springframework.beans.factory.annotation.Value;
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |  /**
 |  |  /**
 | 
												
													
														
															|  |   * 消息发送模版拓展
 |  |   * 消息发送模版拓展
 | 
												
											
												
													
														
															|  | @@ -15,8 +19,14 @@ import org.apache.rocketmq.remoting.exception.RemotingException;
 | 
												
													
														
															|  |   */
 |  |   */
 | 
												
													
														
															|  |  public class DefaultMQProducerExt {
 |  |  public class DefaultMQProducerExt {
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | 
 |  | +    private Logger logger = LoggerFactory.getLogger(DefaultMQProducerExt.class);
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  |      private DefaultMQProducer defaultMQProducer;
 |  |      private DefaultMQProducer defaultMQProducer;
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | 
 |  | +    @Value("${spring.profiles.active:dev}")
 | 
												
													
														
															|  | 
 |  | +    private String profiles;
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  |      public DefaultMQProducerExt(DefaultMQProducer defaultMQProducer) {
 |  |      public DefaultMQProducerExt(DefaultMQProducer defaultMQProducer) {
 | 
												
													
														
															|  |          this.defaultMQProducer = defaultMQProducer;
 |  |          this.defaultMQProducer = defaultMQProducer;
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
											
												
													
														
															|  | @@ -25,23 +35,29 @@ public class DefaultMQProducerExt {
 | 
												
													
														
															|  |          return defaultMQProducer;
 |  |          return defaultMQProducer;
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -    public SendResult send(String topic, String tag, String key, byte[] body, int delayTimeLevel) throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
 |  | 
 | 
												
													
														
															|  | 
 |  | +    public SendResult send(String project, String tag, String key, byte[] body, int delayTimeLevel) throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
 | 
												
													
														
															|  |          Message message = new Message();
 |  |          Message message = new Message();
 | 
												
													
														
															|  |          message.setBody(body);
 |  |          message.setBody(body);
 | 
												
													
														
															|  | -        message.setTopic(topic);
 |  | 
 | 
												
													
														
															|  | 
 |  | +        message.setTopic(getTopic(project));
 | 
												
													
														
															|  |          message.setTags(tag);
 |  |          message.setTags(tag);
 | 
												
													
														
															|  |          message.setKeys(key);
 |  |          message.setKeys(key);
 | 
												
													
														
															|  |          message.setDelayTimeLevel(delayTimeLevel);
 |  |          message.setDelayTimeLevel(delayTimeLevel);
 | 
												
													
														
															|  |          return defaultMQProducer.send(message);
 |  |          return defaultMQProducer.send(message);
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -    public SendResult send(String topic, String tag, String key, byte[] body) throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
 |  | 
 | 
												
													
														
															|  | -        return send(topic, tag, key, body, 0);
 |  | 
 | 
												
													
														
															|  | 
 |  | +    public SendResult send(String project, String tag, String key, byte[] body) throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
 | 
												
													
														
															|  | 
 |  | +        return send(project, tag, key, body, 0);
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -    public SendResult send(String topic, String key, byte[] body) throws InterruptedException, RemotingException,
 |  | 
 | 
												
													
														
															|  | 
 |  | +    public SendResult send(String project, String key, byte[] body) throws InterruptedException, RemotingException,
 | 
												
													
														
															|  |              MQClientException, MQBrokerException {
 |  |              MQClientException, MQBrokerException {
 | 
												
													
														
															|  | -        return send(topic, "*", key, body, 0);
 |  | 
 | 
												
													
														
															|  | 
 |  | +        return send(project, "*", key, body, 0);
 | 
												
													
														
															|  | 
 |  | +    }
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  | 
 |  | +    public String getTopic(String project) {
 | 
												
													
														
															|  | 
 |  | +        String topic = project + "-" + profiles + "-" + MsgConstants.TOPIC_SUFFIX;
 | 
												
													
														
															|  | 
 |  | +        logger.info(" topic : " + topic);
 | 
												
													
														
															|  | 
 |  | +        return topic;
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |  }
 |  |  }
 |