Explorar el Código

Merge pull request #2 from liukaixiong/2.0.4.15-SNAPSHOT

2.0.4.15 snapshot
liukaixiong hace 4 años
padre
commit
8e982e2e75

+ 1 - 0
README.md

@@ -6,5 +6,6 @@
 - [elab-log](./elab-log/README.md) : 日志服务框架,基于携程的CAT客户端开发。用于收集每个服务请求的日志信息。
 - [elab-mongodb](./elab-mongodb/README.md) : 基于mongodb客户端封装。
 - [elab-mq](./elab-mq/README.md) : 基于阿里云的商用版RocketMQ开发,为每个请求植入了CAT日志监控。
+- [elab-redis](./elab-redis/README.md) : 基于redis的一些简单封装
 - elab-spring : 对Spring的一些拓展封装
 

+ 53 - 0
elab-mq/src/test/java/com/elab/mq/rocketmq/ConsumerTest.java

@@ -0,0 +1,53 @@
+package com.elab.mq.rocketmq;
+
+import com.aliyun.openservices.ons.api.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Properties;
+
+public class ConsumerTest {
+    private static Logger logger = LoggerFactory.getLogger(ConsumerTest.class);
+
+    public static void main(String[] args) {
+        Properties properties = new Properties();
+        // 您在控制台创建的 Group ID
+//        properties.put(PropertyKeyConst., "GID-producer1");
+        // AccessKey 阿里云身份验证,在阿里云服务器管理控制台创建
+        properties.put(PropertyKeyConst.AccessKey, "LTAImNZed054h0YV");
+        // SecretKey 阿里云身份验证,在阿里云服务器管理控制台创建
+        properties.put(PropertyKeyConst.SecretKey, "8hmhlhiQ2ikmVeLKujwMNWsktFpSzm");
+        // 设置 TCP 接入域名,进入控制台的实例管理页面的“获取接入点信息”区域查看
+        properties.put(PropertyKeyConst.NAMESRV_ADDR,
+                "http://MQ_INST_1819241776271348_Bak3xjk0.mq-internet-access.mq-internet.aliyuncs.com:80");
+        // 集群订阅方式 (默认)
+        // properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.CLUSTERING);
+        // 广播订阅方式
+        // properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.BROADCASTING);
+        Consumer consumer = ONSFactory.createConsumer(properties);
+        consumer.subscribe("test", "mq_test", new MessageListener() { //订阅多个 Tag
+            private int count = 0;
+
+            public Action consume(Message message, ConsumeContext context) {
+                count++;
+                if (count > 3) {
+                    logger.info("消息被确认了..." + message.getKey() + "\t" + message.getMsgID());
+                    count = 0;
+                    return Action.CommitMessage;
+                } else {
+                    logger.info("------消息不想被确认-------" + count + "\t" + message.getKey() + "\t" + message.getMsgID());
+                    return Action.ReconsumeLater;
+                }
+            }
+        });
+        //订阅另外一个 Topic
+//        consumer.subscribe("TopicTestMQ-Other", "*", new MessageListener() { //订阅全部 Tag
+//            public Action consume(Message message, ConsumeContext context) {
+//                System.out.println("Receive: " + message);
+//                return Action.CommitMessage;
+//            }
+//        });
+        consumer.start();
+        logger.info("Consumer Started");
+    }
+}

+ 54 - 0
elab-mq/src/test/java/com/elab/mq/rocketmq/ProducerTest.java

@@ -0,0 +1,54 @@
+package com.elab.mq.rocketmq;
+
+import com.aliyun.openservices.ons.api.*;
+import com.elab.core.utils.RandomUtils;
+
+import java.util.Date;
+import java.util.Properties;
+
+public class ProducerTest {
+    public static void main(String[] args) {
+        Properties properties = new Properties();
+        // AccessKey 阿里云身份验证,在阿里云服务器管理控制台创建
+        properties.put(PropertyKeyConst.AccessKey, "");
+        // SecretKey 阿里云身份验证,在阿里云服务器管理控制台创建
+        properties.put(PropertyKeyConst.SecretKey, "");
+        //设置发送超时时间,单位毫秒
+        properties.setProperty(PropertyKeyConst.SendMsgTimeoutMillis, "3000");
+        // 设置 TCP 接入域名,进入控制台的实例管理页面的“获取接入点信息”区域查看
+        properties.put(PropertyKeyConst.NAMESRV_ADDR,
+                "http://MQ_INST_1819241776271348_Bak3xjk0.mq-internet-access.mq-internet.aliyuncs.com:80");
+        Producer producer = ONSFactory.createProducer(properties);
+        // 在发送消息前,必须调用 start 方法来启动 Producer,只需调用一次即可
+        producer.start();
+        //循环发送消息
+        for (int i = 0; i < 1; i++) {
+            Message msg = new Message( //
+                    // Message 所属的 Topic
+                    "test",
+                    // Message Tag 可理解为 Gmail 中的标签,对消息进行再归类,方便 Consumer 指定过滤条件在消息队列 RocketMQ 的服务器过滤
+                    "mq_test",
+                    // Message Body 可以是任何二进制形式的数据, 消息队列 RocketMQ 不做任何干预,
+                    // 需要 Producer 与 Consumer 协商好一致的序列化和反序列化方式
+                    "Hello MQ".getBytes());
+            // 设置代表消息的业务关键属性,请尽可能全局唯一。
+            // 以方便您在无法正常收到消息情况下,可通过阿里云服务器管理控制台查询消息并补发
+            // 注意:不设置也不会影响消息正常收发
+            msg.setKey("ORDERID_" + RandomUtils.randomString(10));
+            try {
+                SendResult sendResult = producer.send(msg);
+                // 同步发送消息,只要不抛异常就是成功
+                if (sendResult != null) {
+                    System.out.println(new Date() + " Send mq message success. Topic is:" + msg.getTopic() + " msgId is: " + sendResult.getMessageId());
+                }
+            } catch (Exception e) {
+                // 消息发送失败,需要进行重试处理,可重新发送这条消息或持久化这条数据进行补偿处理
+                System.out.println(new Date() + " Send mq message failed. Topic is:" + msg.getTopic());
+                e.printStackTrace();
+            }
+        }
+        // 在应用退出前,销毁 Producer 对象
+        // 注意:如果不销毁也没有问题
+        producer.shutdown();
+    }
+}

+ 1 - 1
elab-rocketMQ/REDERME.md

@@ -27,7 +27,7 @@
 rocketmq:
     name-server: 192.168.0.24:9876;192.168.0.25:9876
     producer:
-        group: ${profiles.active}-${spring.application.name}
+        group: ${spring.application.name}-${profiles.active}
         sendMessageTimeout: 300000
 ```
 

+ 2 - 1
elab-rocketMQ/src/main/java/com/elab/mq/rocket/listener/DefaultRocketMQListener.java

@@ -23,7 +23,7 @@ import java.util.Date;
  * @author : liukx
  * @time : 2019/7/18 - 13:54
  */
-@RocketMQMessageListener(topic = "topic-${rocketmq.producer.group}", consumerGroup = "group-${rocketmq.producer.group}")
+@RocketMQMessageListener(topic = "${rocketmq.producer.group}-topic", consumerGroup = "${rocketmq.producer.group}-group")
 public class DefaultRocketMQListener implements RocketMQListener<MessageExt> {
 
     private Logger logger = LoggerFactory.getLogger(getClass());
@@ -100,6 +100,7 @@ public class DefaultRocketMQListener implements RocketMQListener<MessageExt> {
             throw new MsgProcessException(e.getMessage());
         }
     }
+
     private void saveData(RmqConsumerEntity entity, boolean isInsert) throws Exception {
         // 如果没有异常发生
         entity.setConsumerStatus(MsgConstants.MSG_OK);

+ 0 - 17
elab-rocketMQ/src/main/java/com/elab/mq/rocket/producer/DefaultMQProducerExt.java

@@ -1,17 +0,0 @@
-package com.elab.mq.rocket.producer;
-
-/**
- * 拓展消息发送者
- *
- * @author : liukx
- * @time : 2019/7/18 - 16:21
- */
-public class DefaultMQProducerExt {
-
-
-
-
-
-
-
-}

+ 22 - 6
elab-rocketMQ/src/main/java/com/elab/mq/rocket/template/DefaultMQProducerExt.java

@@ -1,11 +1,15 @@
 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.MQClientException;
 import org.apache.rocketmq.client.producer.DefaultMQProducer;
 import org.apache.rocketmq.client.producer.SendResult;
 import org.apache.rocketmq.common.message.Message;
 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 {
 
+    private Logger logger = LoggerFactory.getLogger(DefaultMQProducerExt.class);
+
     private DefaultMQProducer defaultMQProducer;
 
+    @Value("${spring.profiles.active:dev}")
+    private String profiles;
+
+
     public DefaultMQProducerExt(DefaultMQProducer defaultMQProducer) {
         this.defaultMQProducer = defaultMQProducer;
     }
@@ -25,23 +35,29 @@ public class DefaultMQProducerExt {
         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.setBody(body);
-        message.setTopic(topic);
+        message.setTopic(getTopic(project));
         message.setTags(tag);
         message.setKeys(key);
         message.setDelayTimeLevel(delayTimeLevel);
         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 {
-        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;
     }
 
 }

+ 4 - 0
elab-rocketMQ/src/main/java/com/elab/mq/rocket/utils/MsgConstants.java

@@ -21,5 +21,9 @@ public class MsgConstants {
      */
     public static int MSG_WAIT = 0;
 
+    /**
+     * topic 后缀
+     */
+    public static String TOPIC_SUFFIX = "topic";
 
 }

+ 286 - 0
springboot-demo/mvnw

@@ -0,0 +1,286 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#    https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ----------------------------------------------------------------------------
+
+# ----------------------------------------------------------------------------
+# Maven2 Start Up Batch script
+#
+# Required ENV vars:
+# ------------------
+#   JAVA_HOME - location of a JDK home dir
+#
+# Optional ENV vars
+# -----------------
+#   M2_HOME - location of maven2's installed home dir
+#   MAVEN_OPTS - parameters passed to the Java VM when running Maven
+#     e.g. to debug Maven itself, use
+#       set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+#   MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+# ----------------------------------------------------------------------------
+
+if [ -z "$MAVEN_SKIP_RC" ] ; then
+
+  if [ -f /etc/mavenrc ] ; then
+    . /etc/mavenrc
+  fi
+
+  if [ -f "$HOME/.mavenrc" ] ; then
+    . "$HOME/.mavenrc"
+  fi
+
+fi
+
+# OS specific support.  $var _must_ be set to either true or false.
+cygwin=false;
+darwin=false;
+mingw=false
+case "`uname`" in
+  CYGWIN*) cygwin=true ;;
+  MINGW*) mingw=true;;
+  Darwin*) darwin=true
+    # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
+    # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
+    if [ -z "$JAVA_HOME" ]; then
+      if [ -x "/usr/libexec/java_home" ]; then
+        export JAVA_HOME="`/usr/libexec/java_home`"
+      else
+        export JAVA_HOME="/Library/Java/Home"
+      fi
+    fi
+    ;;
+esac
+
+if [ -z "$JAVA_HOME" ] ; then
+  if [ -r /etc/gentoo-release ] ; then
+    JAVA_HOME=`java-config --jre-home`
+  fi
+fi
+
+if [ -z "$M2_HOME" ] ; then
+  ## resolve links - $0 may be a link to maven's home
+  PRG="$0"
+
+  # need this for relative symlinks
+  while [ -h "$PRG" ] ; do
+    ls=`ls -ld "$PRG"`
+    link=`expr "$ls" : '.*-> \(.*\)$'`
+    if expr "$link" : '/.*' > /dev/null; then
+      PRG="$link"
+    else
+      PRG="`dirname "$PRG"`/$link"
+    fi
+  done
+
+  saveddir=`pwd`
+
+  M2_HOME=`dirname "$PRG"`/..
+
+  # make it fully qualified
+  M2_HOME=`cd "$M2_HOME" && pwd`
+
+  cd "$saveddir"
+  # echo Using m2 at $M2_HOME
+fi
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin ; then
+  [ -n "$M2_HOME" ] &&
+    M2_HOME=`cygpath --unix "$M2_HOME"`
+  [ -n "$JAVA_HOME" ] &&
+    JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+  [ -n "$CLASSPATH" ] &&
+    CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
+fi
+
+# For Mingw, ensure paths are in UNIX format before anything is touched
+if $mingw ; then
+  [ -n "$M2_HOME" ] &&
+    M2_HOME="`(cd "$M2_HOME"; pwd)`"
+  [ -n "$JAVA_HOME" ] &&
+    JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
+  # TODO classpath?
+fi
+
+if [ -z "$JAVA_HOME" ]; then
+  javaExecutable="`which javac`"
+  if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
+    # readlink(1) is not available as standard on Solaris 10.
+    readLink=`which readlink`
+    if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
+      if $darwin ; then
+        javaHome="`dirname \"$javaExecutable\"`"
+        javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
+      else
+        javaExecutable="`readlink -f \"$javaExecutable\"`"
+      fi
+      javaHome="`dirname \"$javaExecutable\"`"
+      javaHome=`expr "$javaHome" : '\(.*\)/bin'`
+      JAVA_HOME="$javaHome"
+      export JAVA_HOME
+    fi
+  fi
+fi
+
+if [ -z "$JAVACMD" ] ; then
+  if [ -n "$JAVA_HOME"  ] ; then
+    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+      # IBM's JDK on AIX uses strange locations for the executables
+      JAVACMD="$JAVA_HOME/jre/sh/java"
+    else
+      JAVACMD="$JAVA_HOME/bin/java"
+    fi
+  else
+    JAVACMD="`which java`"
+  fi
+fi
+
+if [ ! -x "$JAVACMD" ] ; then
+  echo "Error: JAVA_HOME is not defined correctly." >&2
+  echo "  We cannot execute $JAVACMD" >&2
+  exit 1
+fi
+
+if [ -z "$JAVA_HOME" ] ; then
+  echo "Warning: JAVA_HOME environment variable is not set."
+fi
+
+CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
+
+# traverses directory structure from process work directory to filesystem root
+# first directory with .mvn subdirectory is considered project base directory
+find_maven_basedir() {
+
+  if [ -z "$1" ]
+  then
+    echo "Path not specified to find_maven_basedir"
+    return 1
+  fi
+
+  basedir="$1"
+  wdir="$1"
+  while [ "$wdir" != '/' ] ; do
+    if [ -d "$wdir"/.mvn ] ; then
+      basedir=$wdir
+      break
+    fi
+    # workaround for JBEAP-8937 (on Solaris 10/Sparc)
+    if [ -d "${wdir}" ]; then
+      wdir=`cd "$wdir/.."; pwd`
+    fi
+    # end of workaround
+  done
+  echo "${basedir}"
+}
+
+# concatenates all lines of a file
+concat_lines() {
+  if [ -f "$1" ]; then
+    echo "$(tr -s '\n' ' ' < "$1")"
+  fi
+}
+
+BASE_DIR=`find_maven_basedir "$(pwd)"`
+if [ -z "$BASE_DIR" ]; then
+  exit 1;
+fi
+
+##########################################################################################
+# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
+# This allows using the maven wrapper in projects that prohibit checking in binary data.
+##########################################################################################
+if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
+    if [ "$MVNW_VERBOSE" = true ]; then
+      echo "Found .mvn/wrapper/maven-wrapper.jar"
+    fi
+else
+    if [ "$MVNW_VERBOSE" = true ]; then
+      echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
+    fi
+    jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
+    while IFS="=" read key value; do
+      case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
+      esac
+    done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
+    if [ "$MVNW_VERBOSE" = true ]; then
+      echo "Downloading from: $jarUrl"
+    fi
+    wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
+
+    if command -v wget > /dev/null; then
+        if [ "$MVNW_VERBOSE" = true ]; then
+          echo "Found wget ... using wget"
+        fi
+        wget "$jarUrl" -O "$wrapperJarPath"
+    elif command -v curl > /dev/null; then
+        if [ "$MVNW_VERBOSE" = true ]; then
+          echo "Found curl ... using curl"
+        fi
+        curl -o "$wrapperJarPath" "$jarUrl"
+    else
+        if [ "$MVNW_VERBOSE" = true ]; then
+          echo "Falling back to using Java to download"
+        fi
+        javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
+        if [ -e "$javaClass" ]; then
+            if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
+                if [ "$MVNW_VERBOSE" = true ]; then
+                  echo " - Compiling MavenWrapperDownloader.java ..."
+                fi
+                # Compiling the Java class
+                ("$JAVA_HOME/bin/javac" "$javaClass")
+            fi
+            if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
+                # Running the downloader
+                if [ "$MVNW_VERBOSE" = true ]; then
+                  echo " - Running MavenWrapperDownloader.java ..."
+                fi
+                ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
+            fi
+        fi
+    fi
+fi
+##########################################################################################
+# End of extension
+##########################################################################################
+
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
+if [ "$MVNW_VERBOSE" = true ]; then
+  echo $MAVEN_PROJECTBASEDIR
+fi
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+  [ -n "$M2_HOME" ] &&
+    M2_HOME=`cygpath --path --windows "$M2_HOME"`
+  [ -n "$JAVA_HOME" ] &&
+    JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+  [ -n "$CLASSPATH" ] &&
+    CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
+  [ -n "$MAVEN_PROJECTBASEDIR" ] &&
+    MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
+fi
+
+WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+exec "$JAVACMD" \
+  $MAVEN_OPTS \
+  -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
+  "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
+  ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"

+ 161 - 0
springboot-demo/mvnw.cmd

@@ -0,0 +1,161 @@
+@REM ----------------------------------------------------------------------------
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements.  See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership.  The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License.  You may obtain a copy of the License at
+@REM
+@REM    https://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied.  See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+@REM ----------------------------------------------------------------------------
+
+@REM ----------------------------------------------------------------------------
+@REM Maven2 Start Up Batch script
+@REM
+@REM Required ENV vars:
+@REM JAVA_HOME - location of a JDK home dir
+@REM
+@REM Optional ENV vars
+@REM M2_HOME - location of maven2's installed home dir
+@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
+@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
+@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
+@REM     e.g. to debug Maven itself, use
+@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+@REM ----------------------------------------------------------------------------
+
+@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
+@echo off
+@REM set title of command window
+title %0
+@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
+@if "%MAVEN_BATCH_ECHO%" == "on"  echo %MAVEN_BATCH_ECHO%
+
+@REM set %HOME% to equivalent of $HOME
+if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
+
+@REM Execute a user defined script before this one
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
+@REM check for pre script, once with legacy .bat ending and once with .cmd ending
+if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
+if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
+:skipRcPre
+
+@setlocal
+
+set ERROR_CODE=0
+
+@REM To isolate internal variables from possible post scripts, we use another setlocal
+@setlocal
+
+@REM ==== START VALIDATION ====
+if not "%JAVA_HOME%" == "" goto OkJHome
+
+echo.
+echo Error: JAVA_HOME not found in your environment. >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+goto error
+
+:OkJHome
+if exist "%JAVA_HOME%\bin\java.exe" goto init
+
+echo.
+echo Error: JAVA_HOME is set to an invalid directory. >&2
+echo JAVA_HOME = "%JAVA_HOME%" >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+goto error
+
+@REM ==== END VALIDATION ====
+
+:init
+
+@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
+@REM Fallback to current working directory if not found.
+
+set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
+IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
+
+set EXEC_DIR=%CD%
+set WDIR=%EXEC_DIR%
+:findBaseDir
+IF EXIST "%WDIR%"\.mvn goto baseDirFound
+cd ..
+IF "%WDIR%"=="%CD%" goto baseDirNotFound
+set WDIR=%CD%
+goto findBaseDir
+
+:baseDirFound
+set MAVEN_PROJECTBASEDIR=%WDIR%
+cd "%EXEC_DIR%"
+goto endDetectBaseDir
+
+:baseDirNotFound
+set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
+cd "%EXEC_DIR%"
+
+:endDetectBaseDir
+
+IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
+
+@setlocal EnableExtensions EnableDelayedExpansion
+for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
+@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
+
+:endReadAdditionalConfig
+
+SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
+set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
+set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
+FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
+	IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 
+)
+
+@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
+@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
+if exist %WRAPPER_JAR% (
+    echo Found %WRAPPER_JAR%
+) else (
+    echo Couldn't find %WRAPPER_JAR%, downloading it ...
+	echo Downloading from: %DOWNLOAD_URL%
+    powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
+    echo Finished downloading %WRAPPER_JAR%
+)
+@REM End of extension
+
+%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
+if ERRORLEVEL 1 goto error
+goto end
+
+:error
+set ERROR_CODE=1
+
+:end
+@endlocal & set ERROR_CODE=%ERROR_CODE%
+
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
+@REM check for post script, once with legacy .bat ending and once with .cmd ending
+if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
+if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
+:skipRcPost
+
+@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
+if "%MAVEN_BATCH_PAUSE%" == "on" pause
+
+if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
+
+exit /B %ERROR_CODE%

+ 71 - 0
springboot-demo/pom.xml

@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.1.6.RELEASE</version>
+        <relativePath/> <!-- lookup parent from repository -->
+    </parent>
+    <groupId>com.elab.example</groupId>
+    <artifactId>springboot-demo</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <name>springboot-demo</name>
+    <description>Demo project for Spring Boot</description>
+
+    <properties>
+        <java.version>1.8</java.version>
+        <elab.version>2.0.4.12-SNAPSHOT</elab.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.elab.core</groupId>
+            <artifactId>elab-es</artifactId>
+            <version>${elab.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.elab.core</groupId>
+            <artifactId>elab-spring</artifactId>
+            <version>${elab.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.elab.core</groupId>
+            <artifactId>elab-rocketMQ</artifactId>
+            <version>${elab.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.kafka</groupId>
+            <artifactId>kafka-clients</artifactId>
+            <version>0.10.0.0</version>
+        </dependency>
+
+        <!--        <dependency>-->
+        <!--            <groupId>org.zxp</groupId>-->
+        <!--            <artifactId>esclientrhl</artifactId>-->
+        <!--            <version>1.0.0</version>-->
+        <!--        </dependency>-->
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

+ 17 - 0
springboot-demo/src/main/java/com/elab/example/springbootdemo/SpringbootDemoApplication.java

@@ -0,0 +1,17 @@
+package com.elab.example.springbootdemo;
+
+import com.elab.mq.rocket.anno.EnableRocketMQ;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication()
+@EnableRocketMQ
+//@EnableESTools
+//@Import({DefaultElasticSearchTemplate.class})
+public class SpringbootDemoApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(SpringbootDemoApplication.class, args);
+    }
+
+}

+ 50 - 0
springboot-demo/src/main/resources/application.yml

@@ -0,0 +1,50 @@
+demo:
+    rocketmq:
+        extNameServer: 127.0.0.1:9876
+        msgExtTopic: demo-message-ext-topic
+        orderTopic: demo-order-paid-topic
+        topic: demo-string-topic
+        jsonTopic: demo-json-topic
+        transTopic: demo-spring-transaction-topic
+group:
+    id: CID-consumer-group-demo
+kafka:
+    bootstrap:
+        servers: 47.103.15.48:9093,47.103.17.231:9093,47.103.23.79:9093
+    topic: alikafka-topic-demo
+rocketmq:
+    name-server: 192.168.0.24:9876;192.168.0.25:9876
+    producer:
+        group: ${spring.application.name}-${spring.profiles.active}
+        sendMessageTimeout: 300000
+spring:
+    application:
+        name: elab-rocketMQ
+    elasticsearch:
+        rest:
+            uris: http://192.168.0.24:9200
+    profiles:
+      active: dev
+default:
+    minIdle: 10
+    validationQuery: SELECT 1
+    initialSize: 5
+    maxWait: 60000
+    filters: wall,stat
+    poolPreparedStatements: true
+    url: jdbc:mysql://192.168.0.13/elab_db?characterEncoding=UTF-8&connectTimeout=60000&socketTimeout=60000
+    logAbandoned: true
+    password: elab@123
+    maxOpenPreparedStatements: 1
+    testOnBorrow: false
+    testWhileIdle: true
+    removeAbandoned: true
+    minEvictableIdleTimeMillis: 300000
+    timeBetweenEvictionRunsMillis: 60000
+    testOnReturn: false
+    removeAbandonedTimeout: 3600
+    driverClassName: com.mysql.jdbc.Driver
+    querytimeout: 2400
+    maxActive: 50
+    username: root
+debug: true

+ 37 - 0
springboot-demo/src/test/java/com/elab/example/springbootdemo/SpringbootDemoApplicationTests.java

@@ -0,0 +1,37 @@
+package com.elab.example.springbootdemo;
+
+import com.alibaba.fastjson.JSON;
+import org.elasticsearch.client.Request;
+import org.elasticsearch.client.Response;
+import org.elasticsearch.client.RestClient;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class SpringbootDemoApplicationTests {
+
+
+    @Autowired
+    private RestClient restClient;
+
+    @Test
+    public void contextLoads() throws IOException {
+        Map map = new HashMap<>();
+        map.put("name", "某某某");
+        map.put("age", "16");
+        Request request = new Request("POST", "/test/user");
+        request.setJsonEntity(JSON.toJSONString(map));
+
+        Response response = restClient.performRequest(request);
+        System.out.println(response.toString());
+    }
+
+}

+ 3 - 3
springboot-demo/src/test/java/com/elab/example/springbootdemo/kafka/KafkaTest.java

@@ -33,9 +33,9 @@ public class KafkaTest {
     private static final String ENCODING = "UTF-8";
     private static final String HTTP_METHOD = "POST";
     //购买的实例所在地域的 Region ID
-    private static final String REGION_ID = "cn-shanghai";
-    private static final String ACCESS_KEY = "LTAIWRlbq9unW05V";
-    private static final String ACCESS_KEY_SECRET = "6JXciPjrzfJGPWO1enoklG88GTo9DL";
+    private static final String REGION_ID = "";
+    private static final String ACCESS_KEY = "";
+    private static final String ACCESS_KEY_SECRET = "";
 
 
     public static void main(String[] args) {

+ 1 - 5
springboot-demo/src/test/java/com/elab/example/springbootdemo/rocketmq/producerTest.java

@@ -13,7 +13,6 @@ import org.apache.rocketmq.remoting.exception.RemotingException;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
@@ -32,8 +31,6 @@ public class producerTest {
     @Autowired
     private DefaultMQProducerExt rocketMQTemplate;
 
-    @Value("${rocketmq.default.topic}")
-    private String topic;
 
     @Test
     public void sendJsonMsg() throws UnsupportedEncodingException, InterruptedException, RemotingException, MQClientException, MQBrokerException {
@@ -42,9 +39,8 @@ public class producerTest {
         jsonObject.put("msg", "my name is lkx");
         Message message = new Message();
         message.setBody(jsonObject.toJSONString().getBytes());
-        message.setTopic(topic);
         message.setTags("");
-        SendResult sendResult = rocketMQTemplate.send(topic, "tag", RandomUtils.randomString(5),
+        SendResult sendResult = rocketMQTemplate.send("elab-marketing-user", "tag", RandomUtils.randomString(5),
                 jsonObject.toJSONString().getBytes());
         SendStatus sendStatus = sendResult.getSendStatus();
         System.out.println("--->" + sendResult.toString());