From 9de6cb78bab4c791ee2bdba6130606cb61b562d9 Mon Sep 17 00:00:00 2001 From: cengfeng lzy Date: Wed, 3 Apr 2019 16:58:27 +0800 Subject: [PATCH] Modify for building native image --- client/pom.xml | 32 ++++++++++++++++ .../org/apache/rocketmq/client/Producer.java | 38 +++++++++++++++++++ .../rocketmq/client/log/ClientLogger.java | 5 +++ client/svm.sh | 21 ++++++++++ pom.xml | 1 + 5 files changed, 97 insertions(+) create mode 100644 client/src/main/java/org/apache/rocketmq/client/Producer.java create mode 100755 client/svm.sh diff --git a/client/pom.xml b/client/pom.xml index 35908f20..afa47c07 100644 --- a/client/pom.xml +++ b/client/pom.xml @@ -63,4 +63,36 @@ test + + + + org.apache.maven.plugins + maven-assembly-plugin + 2.4.1 + + + + jar-with-dependencies + + + + + org.apache.rocketmq.client.Producer + + + + + + + make-assembly + + package + + single + + + + + + diff --git a/client/src/main/java/org/apache/rocketmq/client/Producer.java b/client/src/main/java/org/apache/rocketmq/client/Producer.java new file mode 100644 index 00000000..6751d40f --- /dev/null +++ b/client/src/main/java/org/apache/rocketmq/client/Producer.java @@ -0,0 +1,38 @@ +/* +Main entry for building native image +*/ +package org.apache.rocketmq.client; + +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.common.RemotingHelper; +import io.netty.handler.logging.LoggingHandler; +import io.netty.handler.logging.LogLevel; + +public class Producer { + private static final LoggingHandler log = new LoggingHandler(LogLevel.DEBUG); + public static void main(String[] args) throws MQClientException, InterruptedException { + + DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName"); + producer.start(); + + for (int i = 0; i < 128; i++) + try { + { + Message msg = new Message("TopicTest", + "TagA", + "OrderID188", + "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET)); + SendResult sendResult = producer.send(msg); + System.out.printf("%s%n", sendResult); + } + + } catch (Exception e) { + e.printStackTrace(); + } + + producer.shutdown(); + } +} diff --git a/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java b/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java index c62b385b..1903903e 100644 --- a/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java +++ b/client/src/main/java/org/apache/rocketmq/client/log/ClientLogger.java @@ -71,9 +71,14 @@ public class ClientLogger { Layout layout = LoggingBuilder.newLayoutBuilder().withDefaultLayout().build(); +/* rocketmqClientAppender = LoggingBuilder.newAppenderBuilder() .withRollingFileAppender(logFileName, maxFileSize, maxFileIndex) .withAsync(false, queueSize).withName(ROCKETMQ_CLIENT_APPENDER_NAME).withLayout(layout).build(); +*/ + rocketmqClientAppender = LoggingBuilder.newAppenderBuilder() + .withConsoleAppender("System.out") + .withName(ROCKETMQ_CLIENT_APPENDER_NAME).withLayout(layout).build(); Logger.getRootLogger().addAppender(rocketmqClientAppender); } diff --git a/client/svm.sh b/client/svm.sh new file mode 100755 index 00000000..5a094339 --- /dev/null +++ b/client/svm.sh @@ -0,0 +1,21 @@ +#!/bin/bash +SVM_OPT="--allow-incomplete-classpath --report-unsupported-elements-at-runtime" +SVM_OPT="${SVM_OPT} --delay-class-initialization-to-runtime=com.alibaba.fastjson.serializer.JodaCodec" +SVM_OPT="${SVM_OPT} --delay-class-initialization-to-runtime=io.netty.handler.ssl.util.BouncyCastleSelfSignedCertGenerator" +SVM_OPT="${SVM_OPT} --delay-class-initialization-to-runtime=io.netty.handler.ssl.JdkAlpnApplicationProtocolNegotiator" +SVM_OPT="${SVM_OPT} --delay-class-initialization-to-runtime=io.netty.handler.ssl.JdkNpnApplicationProtocolNegotiator" +SVM_OPT="${SVM_OPT} --delay-class-initialization-to-runtime=io.netty.handler.ssl.JdkNpnSslEngine" +SVM_OPT="${SVM_OPT} --delay-class-initialization-to-runtime=io.netty.handler.ssl.JdkAlpnSslEngine" +# testing +#SVM_OPT="${SVM_OPT} --delay-class-initialization-to-runtime=io.netty.handler.ssl.util.SelfSignedCertificate" +#SVM_OPT="${SVM_OPT} --delay-class-initialization-to-runtime=io.netty.handler.ssl.util.ThreadLocalInsecureRandom" +SVM_OPT="${SVM_OPT} --rerun-class-initialization-at-runtime=io.netty.handler.ssl.util.SelfSignedCertificate" +SVM_OPT="${SVM_OPT} --rerun-class-initialization-at-runtime=io.netty.handler.ssl.util.ThreadLocalInsecureRandom" +SVM_OPT="${SVM_OPT} --enable-url-protocols=http" + + +WORKDIR=`pwd` +CONFIG_OPT=" -Dio.netty.noUnsafe=true -H:+ReportExceptionStackTraces --allow-incomplete-classpath" +#native_image=/home/cengfeng.lzy/GraalDev/graal/vm/mxbuild/linux-amd64/GRAALVM_LIBGRAAL/graalvm-libgraal-1.0.0-rc15-dev/bin/native-image +native_image=~/tools/graalvm-ce-1.0.0-rc14/bin/native-image +$native_image $CONFIG_OPT $SVM_OPT -jar target/rocketmq-client-4.4.1-SNAPSHOT-jar-with-dependencies.jar diff --git a/pom.xml b/pom.xml index bb83a16a..d96dfbbe 100644 --- a/pom.xml +++ b/pom.xml @@ -93,6 +93,7 @@ + true UTF-8 UTF-8 -- GitLab