You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by lindzh <gi...@git.apache.org> on 2017/05/09 09:12:22 UTC
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
GitHub user lindzh opened a pull request:
https://github.com/apache/incubator-rocketmq/pull/101
[ROCKETMQ-194] log appender support
As Rocketmq is widely used,A log appender is also necessary.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/lindzh/incubator-rocketmq log_appender
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-rocketmq/pull/101.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #101
----
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq issue #101: [ROCKETMQ-194] log appender support
Posted by lindzh <gi...@git.apache.org>.
Github user lindzh commented on the issue:
https://github.com/apache/incubator-rocketmq/pull/101
@lizhanhui ,When we print the log to rocketmq provided for big data processing, developers usually need to write their own appender.I think this is very ordinary.Why not provide them as a core component
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq issue #101: [ROCKETMQ-194] log appender support
Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:
https://github.com/apache/incubator-rocketmq/pull/101
[](https://coveralls.io/builds/11487766)
Coverage increased (+1.03%) to 32.01% when pulling **e269dc66a1b8ea4fbc699641e0252b23fca7bc81 on lindzh:log_appender** into **fa85abcdf6ee46e56403ddf86828a38683103fd0 on apache:master**.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by zhouxinyu <gi...@git.apache.org>.
Github user zhouxinyu commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r116382123
--- Diff: logappender/src/main/java/org/apache/rocketmq/logappender/common/ProducerInstance.java ---
@@ -0,0 +1,96 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender.common;
+
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.client.producer.DefaultMQProducer;
+import org.apache.rocketmq.client.producer.MQProducer;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Common Producer component
+ */
+public class ProducerInstance {
+
+ public static final String APPENDER_TYPE = "APPENDER_TYPE";
+
+ public static final String LOG4J_APPENDER = "LOG4J_APPENDER";
+
+ public static final String LOG4J2_APPENDER = "LOG4J2_APPENDER";
+
+ public static final String LOGBACK_APPENDER = "LOGBACK_APPENDER";
+
+ public static final String DEFAULT_GROUP = "rocketmq_appender";
+
+ private static ConcurrentHashMap<String, MQProducer> producerMap = new ConcurrentHashMap<String, MQProducer>();
+
+ private static String genKey(String nameServerAddress, String group) {
+ return nameServerAddress + "_" + group;
+ }
+
+
+ public static MQProducer getInstance(String nameServerAddress, String group) throws MQClientException {
+ if (group == null) {
+ group = DEFAULT_GROUP;
+ }
+
+ String genKey = genKey(nameServerAddress, group);
+ MQProducer p = producerMap.get(genKey);
+ if (p != null) {
+ return p;
+ }
+
+ DefaultMQProducer defaultMQProducer = new DefaultMQProducer(group);
+ defaultMQProducer.setNamesrvAddr(nameServerAddress);
+ MQProducer beforeProducer = null;
+ //cas put producer
+ synchronized (producerMap) {
+ beforeProducer = producerMap.putIfAbsent(genKey, defaultMQProducer);
+ }
+ if (beforeProducer != null) {
+ return beforeProducer;
+ }
+ defaultMQProducer.start();
+ return defaultMQProducer;
+ }
+
+
+ public static void removeAndClose(String nameServerAddress, String group) {
+ if (group == null) {
+ group = DEFAULT_GROUP;
+ }
+ String genKey = genKey(nameServerAddress, group);
+ MQProducer producer = producerMap.get(genKey);
--- End diff --
```
MQProducer producer = producerMap.get(genKey);
producerMap.remove(genKey);
```
can be replaced by:
```
MQProducer producer = producerMap.remove(genKey);
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by vongosling <gi...@git.apache.org>.
Github user vongosling commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115472199
--- Diff: logappender/pom.xml ---
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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
+
+ http://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.
+ -->
+<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">
+ <parent>
+ <groupId>org.apache.rocketmq</groupId>
+ <artifactId>rocketmq-all</artifactId>
+ <version>4.1.0-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>rocketmq-logappender</artifactId>
+ <packaging>jar</packaging>
+ <name>rocketmq-logappender ${project.version}</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.test.skip>false</maven.test.skip>
+ <maven.javadoc.skip>true</maven.javadoc.skip>
+ <maven.compiler.source>1.7</maven.compiler.source>
+ <maven.compiler.target>1.7</maven.compiler.target>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.7</version>
+ <optional>true</optional>
+ </dependency>
+
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.17</version>
+ <optional>true</optional>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <version>2.7</version>
+ <optional>true</optional>
+ </dependency>
+
+
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-core</artifactId>
+ <version>1.1.2</version>
--- End diff --
The latest version ?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq issue #101: [ROCKETMQ-194] log appender support
Posted by lizhanhui <gi...@git.apache.org>.
Github user lizhanhui commented on the issue:
https://github.com/apache/incubator-rocketmq/pull/101
Hi, @lindzh could you further justify this PR? Aka, explain why it's reasonable to create a custom appender?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by vongosling <gi...@git.apache.org>.
Github user vongosling commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115887404
--- Diff: logappender/src/main/java/org/apache/rocketmq/logappender/log4j2/RocketmqLog4j2Appender.java ---
@@ -0,0 +1,232 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender.log4j2;
+
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.rocketmq.common.message.Message;
+import org.apache.rocketmq.logappender.common.ProducerInstance;
+import org.apache.logging.log4j.core.ErrorHandler;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
+import org.apache.logging.log4j.core.layout.SerializedLayout;
+import org.apache.rocketmq.client.producer.MQProducer;
+
+import java.io.Serializable;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Log4j2 Appender Component
+ */
+@Plugin(
+ name = "Rocketmq",
+ category = "Core",
--- End diff --
Core or core ?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by vongosling <gi...@git.apache.org>.
Github user vongosling commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115888858
--- Diff: logappender/src/main/java/org/apache/rocketmq/logappender/logback/RocketmqLogbackAppender.java ---
@@ -0,0 +1,184 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender.logback;
+
+import ch.qos.logback.classic.net.LoggingEventPreSerializationTransformer;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.AppenderBase;
+import ch.qos.logback.core.Layout;
+import ch.qos.logback.core.spi.PreSerializationTransformer;
+import ch.qos.logback.core.status.ErrorStatus;
+import org.apache.rocketmq.common.message.Message;
+import org.apache.rocketmq.logappender.common.ProducerInstance;
+import org.apache.rocketmq.client.producer.MQProducer;
+
+/**
+ * Logack Appender Component
--- End diff --
Logback
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by vongosling <gi...@git.apache.org>.
Github user vongosling commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115471504
--- Diff: logappender/README.md ---
@@ -0,0 +1,64 @@
+# RocketMQ-LogAppender [](https://travis-ci.org/rocketmq/rocketmq-logappender) [](https://coveralls.io/github/rocketmq/rocketmq-logappender?branch=master)
+
+
+## Introduction
+RocketMQ-LogAppender is a logging component implement of log4j,log4j2 and logback.Taking Apache RocketMQ as broker.
+All logs loged will be send to the topic you define.
+
+## Examples
+
+#### log4j example
+
+> config detail
+
+```xml
+<appender name="mqAppender1" class="org.apache.rocketmq.logappender.log4j.RocketmqLog4jAppender">
+ <param name="Tag" value="log1" />
--- End diff --
case-insensitive name ,right ?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq issue #101: [ROCKETMQ-194] log appender support
Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:
https://github.com/apache/incubator-rocketmq/pull/101
[](https://coveralls.io/builds/11433323)
Coverage increased (+0.1%) to 31.109% when pulling **bee9726ba9231b79462536f628d9ff8f88975f4f on lindzh:log_appender** into **fa85abcdf6ee46e56403ddf86828a38683103fd0 on apache:master**.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by lindzh <gi...@git.apache.org>.
Github user lindzh commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r116641839
--- Diff: logappender/src/main/java/org/apache/rocketmq/logappender/common/ProducerInstance.java ---
@@ -0,0 +1,96 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender.common;
+
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.client.producer.DefaultMQProducer;
+import org.apache.rocketmq.client.producer.MQProducer;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Common Producer component
+ */
+public class ProducerInstance {
+
+ public static final String APPENDER_TYPE = "APPENDER_TYPE";
+
+ public static final String LOG4J_APPENDER = "LOG4J_APPENDER";
+
+ public static final String LOG4J2_APPENDER = "LOG4J2_APPENDER";
+
+ public static final String LOGBACK_APPENDER = "LOGBACK_APPENDER";
+
+ public static final String DEFAULT_GROUP = "rocketmq_appender";
+
+ private static ConcurrentHashMap<String, MQProducer> producerMap = new ConcurrentHashMap<String, MQProducer>();
+
+ private static String genKey(String nameServerAddress, String group) {
+ return nameServerAddress + "_" + group;
+ }
+
+
+ public static MQProducer getInstance(String nameServerAddress, String group) throws MQClientException {
+ if (group == null) {
+ group = DEFAULT_GROUP;
+ }
+
+ String genKey = genKey(nameServerAddress, group);
+ MQProducer p = producerMap.get(genKey);
+ if (p != null) {
+ return p;
--- End diff --
As log initlizer is serializable,if it has ben started before,it must be started.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by lindzh <gi...@git.apache.org>.
Github user lindzh commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r116641020
--- Diff: logappender/src/main/java/org/apache/rocketmq/logappender/common/ProducerInstance.java ---
@@ -0,0 +1,96 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender.common;
+
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.client.producer.DefaultMQProducer;
+import org.apache.rocketmq.client.producer.MQProducer;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Common Producer component
+ */
+public class ProducerInstance {
+
+ public static final String APPENDER_TYPE = "APPENDER_TYPE";
+
+ public static final String LOG4J_APPENDER = "LOG4J_APPENDER";
+
+ public static final String LOG4J2_APPENDER = "LOG4J2_APPENDER";
+
+ public static final String LOGBACK_APPENDER = "LOGBACK_APPENDER";
+
+ public static final String DEFAULT_GROUP = "rocketmq_appender";
+
+ private static ConcurrentHashMap<String, MQProducer> producerMap = new ConcurrentHashMap<String, MQProducer>();
+
+ private static String genKey(String nameServerAddress, String group) {
+ return nameServerAddress + "_" + group;
+ }
+
+
+ public static MQProducer getInstance(String nameServerAddress, String group) throws MQClientException {
+ if (group == null) {
+ group = DEFAULT_GROUP;
+ }
+
+ String genKey = genKey(nameServerAddress, group);
+ MQProducer p = producerMap.get(genKey);
+ if (p != null) {
+ return p;
+ }
+
+ DefaultMQProducer defaultMQProducer = new DefaultMQProducer(group);
+ defaultMQProducer.setNamesrvAddr(nameServerAddress);
+ MQProducer beforeProducer = null;
+ //cas put producer
+ synchronized (producerMap) {
--- End diff --
As log initlizer is serializable,there is no need to user synchronized
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by vongosling <gi...@git.apache.org>.
Github user vongosling commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115888889
--- Diff: logappender/src/main/java/org/apache/rocketmq/logappender/logback/RocketmqLogbackAppender.java ---
@@ -0,0 +1,184 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender.logback;
+
+import ch.qos.logback.classic.net.LoggingEventPreSerializationTransformer;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.AppenderBase;
+import ch.qos.logback.core.Layout;
+import ch.qos.logback.core.spi.PreSerializationTransformer;
+import ch.qos.logback.core.status.ErrorStatus;
+import org.apache.rocketmq.common.message.Message;
+import org.apache.rocketmq.logappender.common.ProducerInstance;
+import org.apache.rocketmq.client.producer.MQProducer;
+
+/**
+ * Logack Appender Component
+ */
+public class RocketmqLogbackAppender extends AppenderBase<ILoggingEvent> {
+
+ /**
+ * Appended message tag define
+ */
+ private String tag;
+
+ /**
+ * Whitch topic to send log messages
+ */
+ private String topic;
+
+ /**
+ * Rokcetmq nameserver address
--- End diff --
RocketMQ
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq issue #101: [ROCKETMQ-194] log appender support
Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:
https://github.com/apache/incubator-rocketmq/pull/101
[](https://coveralls.io/builds/11433552)
Coverage increased (+0.1%) to 31.118% when pulling **7fcc19b6b3c40377e5a3e15ba0fbfc0a951d8773 on lindzh:log_appender** into **fa85abcdf6ee46e56403ddf86828a38683103fd0 on apache:master**.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq issue #101: [ROCKETMQ-194] log appender support
Posted by dongeforever <gi...@git.apache.org>.
Github user dongeforever commented on the issue:
https://github.com/apache/incubator-rocketmq/pull/101
@lindzh this PR is merged. You may close this PR now
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by lindzh <gi...@git.apache.org>.
Github user lindzh commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r116141459
--- Diff: logappender/src/main/java/org/apache/rocketmq/logappender/log4j2/RocketmqLog4j2Appender.java ---
@@ -0,0 +1,232 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender.log4j2;
+
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.rocketmq.common.message.Message;
+import org.apache.rocketmq.logappender.common.ProducerInstance;
+import org.apache.logging.log4j.core.ErrorHandler;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
+import org.apache.logging.log4j.core.layout.SerializedLayout;
+import org.apache.rocketmq.client.producer.MQProducer;
+
+import java.io.Serializable;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Log4j2 Appender Component
+ */
+@Plugin(
+ name = "Rocketmq",
+ category = "Core",
--- End diff --
It's Core,write as log4j2 JMSAppender,refer https://github.com/apache/logging-log4j2/blob/dbd2d252a1b4139a9bd9eb213c89f28498db6dcf/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/mom/JmsAppender.java,
has ben fix to constant.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by lindzh <gi...@git.apache.org>.
Github user lindzh commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r116140905
--- Diff: logappender/src/main/java/org/apache/rocketmq/logappender/logback/RocketmqLogbackAppender.java ---
@@ -0,0 +1,184 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender.logback;
+
+import ch.qos.logback.classic.net.LoggingEventPreSerializationTransformer;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.AppenderBase;
+import ch.qos.logback.core.Layout;
+import ch.qos.logback.core.spi.PreSerializationTransformer;
+import ch.qos.logback.core.status.ErrorStatus;
+import org.apache.rocketmq.common.message.Message;
+import org.apache.rocketmq.logappender.common.ProducerInstance;
+import org.apache.rocketmq.client.producer.MQProducer;
+
+/**
+ * Logack Appender Component
+ */
+public class RocketmqLogbackAppender extends AppenderBase<ILoggingEvent> {
+
+ /**
+ * Appended message tag define
+ */
+ private String tag;
+
+ /**
+ * Whitch topic to send log messages
+ */
+ private String topic;
+
+ /**
+ * Rokcetmq nameserver address
--- End diff --
fixed
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by zhouxinyu <gi...@git.apache.org>.
Github user zhouxinyu commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r116382074
--- Diff: logappender/src/main/java/org/apache/rocketmq/logappender/common/ProducerInstance.java ---
@@ -0,0 +1,96 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender.common;
+
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.client.producer.DefaultMQProducer;
+import org.apache.rocketmq.client.producer.MQProducer;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Common Producer component
+ */
+public class ProducerInstance {
+
+ public static final String APPENDER_TYPE = "APPENDER_TYPE";
+
+ public static final String LOG4J_APPENDER = "LOG4J_APPENDER";
+
+ public static final String LOG4J2_APPENDER = "LOG4J2_APPENDER";
+
+ public static final String LOGBACK_APPENDER = "LOGBACK_APPENDER";
+
+ public static final String DEFAULT_GROUP = "rocketmq_appender";
+
+ private static ConcurrentHashMap<String, MQProducer> producerMap = new ConcurrentHashMap<String, MQProducer>();
+
+ private static String genKey(String nameServerAddress, String group) {
+ return nameServerAddress + "_" + group;
+ }
+
+
+ public static MQProducer getInstance(String nameServerAddress, String group) throws MQClientException {
+ if (group == null) {
+ group = DEFAULT_GROUP;
+ }
+
+ String genKey = genKey(nameServerAddress, group);
+ MQProducer p = producerMap.get(genKey);
+ if (p != null) {
+ return p;
--- End diff --
Maybe `p` isn't a started producer instance momently?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq issue #101: [ROCKETMQ-194] log appender support
Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:
https://github.com/apache/incubator-rocketmq/pull/101
[](https://coveralls.io/builds/11538511)
Coverage increased (+0.3%) to 31.268% when pulling **fde2f7803500f4b4154c01c32dbfc5230e208805 on lindzh:log_appender** into **fa85abcdf6ee46e56403ddf86828a38683103fd0 on apache:master**.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by lindzh <gi...@git.apache.org>.
Github user lindzh commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115482388
--- Diff: logappender/src/main/java/org/apache/rocketmq/logappender/log4j/RocketmqLog4jAppender.java ---
@@ -0,0 +1,193 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender.log4j;
+
+import org.apache.rocketmq.common.message.Message;
+import org.apache.rocketmq.logappender.common.ProducerInstance;
+import org.apache.log4j.AppenderSkeleton;
+import org.apache.log4j.helpers.LogLog;
+import org.apache.log4j.spi.ErrorCode;
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.rocketmq.client.producer.MQProducer;
+
+/**
+ * Log4j Appender Component
+ */
+public class RocketmqLog4jAppender extends AppenderSkeleton {
+
+ /**
+ * appended message tag define
--- End diff --
ok
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by lindzh <gi...@git.apache.org>.
Github user lindzh commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115482303
--- Diff: style/rmq_checkstyle.xml ---
@@ -30,6 +30,12 @@
<!-- header -->
<module name="RegexpHeader">
<property name="header" value="/\*\nLicensed to the Apache Software Foundation*"/>
+ <property name="fileExtensions" value="java"/>
+ </module>
+
+ <module name="RegexpHeader">
--- End diff --
Old check style is not supported When we add a file such as properties config file.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by lindzh <gi...@git.apache.org>.
Github user lindzh closed the pull request at:
https://github.com/apache/incubator-rocketmq/pull/101
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by vongosling <gi...@git.apache.org>.
Github user vongosling commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115473097
--- Diff: style/rmq_checkstyle.xml ---
@@ -30,6 +30,12 @@
<!-- header -->
<module name="RegexpHeader">
<property name="header" value="/\*\nLicensed to the Apache Software Foundation*"/>
+ <property name="fileExtensions" value="java"/>
+ </module>
+
+ <module name="RegexpHeader">
--- End diff --
Why change this rule~
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by vongosling <gi...@git.apache.org>.
Github user vongosling commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115471296
--- Diff: logappender/README.md ---
@@ -0,0 +1,64 @@
+# RocketMQ-LogAppender [](https://travis-ci.org/rocketmq/rocketmq-logappender) [](https://coveralls.io/github/rocketmq/rocketmq-logappender?branch=master)
+
+
+## Introduction
+RocketMQ-LogAppender is a logging component implement of log4j,log4j2 and logback.Taking Apache RocketMQ as broker.
--- End diff --
What is "implement of " It's confused. IMO, this project is used to send log message using RocektMQ. while log4j, log4j2 and logback is just a adapter for SL4J
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq issue #101: [ROCKETMQ-194] log appender support
Posted by zhouxinyu <gi...@git.apache.org>.
Github user zhouxinyu commented on the issue:
https://github.com/apache/incubator-rocketmq/pull/101
BTW, do we use the batch feature in this appender?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq issue #101: [ROCKETMQ-194] log appender support
Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:
https://github.com/apache/incubator-rocketmq/pull/101
[](https://coveralls.io/builds/11449471)
Coverage increased (+0.3%) to 31.304% when pulling **ee05972b1f676cfa87a67fb058905b52bdd913ff on lindzh:log_appender** into **fa85abcdf6ee46e56403ddf86828a38683103fd0 on apache:master**.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by vongosling <gi...@git.apache.org>.
Github user vongosling commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115472087
--- Diff: logappender/pom.xml ---
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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
+
+ http://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.
+ -->
+<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">
+ <parent>
+ <groupId>org.apache.rocketmq</groupId>
+ <artifactId>rocketmq-all</artifactId>
+ <version>4.1.0-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>rocketmq-logappender</artifactId>
+ <packaging>jar</packaging>
+ <name>rocketmq-logappender ${project.version}</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.test.skip>false</maven.test.skip>
--- End diff --
Redundant config. we can extend from parent module.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by vongosling <gi...@git.apache.org>.
Github user vongosling commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115471708
--- Diff: logappender/README.md ---
@@ -0,0 +1,64 @@
+# RocketMQ-LogAppender [](https://travis-ci.org/rocketmq/rocketmq-logappender) [](https://coveralls.io/github/rocketmq/rocketmq-logappender?branch=master)
+
+
+## Introduction
+RocketMQ-LogAppender is a logging component implement of log4j,log4j2 and logback.Taking Apache RocketMQ as broker.
+All logs loged will be send to the topic you define.
+
+## Examples
+
+#### log4j example
+
+> config detail
+
+```xml
+<appender name="mqAppender1" class="org.apache.rocketmq.logappender.log4j.RocketmqLog4jAppender">
+ <param name="Tag" value="log1" />
+ <param name="Topic" value="TopicTest" />
+ <param name="ProducerGroup" value="log4jxml" />
+ <param name="NameServerAddress" value="127.0.0.1:9876"/>
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss}-%p %t %c - %m%n" />
+ </layout>
+</appender>
+
+<appender name="mqAsyncAppender1" class="org.apache.log4j.AsyncAppender">
+ <param name="BufferSize" value="1024" />
+ <param name="Blocking" value="false" />
+ <appender-ref ref="mqAppender1"></appender-ref>
--- End diff --
why not use single label as above?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq issue #101: [ROCKETMQ-194] log appender support
Posted by lindzh <gi...@git.apache.org>.
Github user lindzh commented on the issue:
https://github.com/apache/incubator-rocketmq/pull/101
readme has ben removed
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by vongosling <gi...@git.apache.org>.
Github user vongosling commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115889155
--- Diff: logappender/src/test/java/org/apache/rocketmq/logappender/AbstractTestCase.java ---
@@ -0,0 +1,165 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender;
+
+import org.apache.rocketmq.broker.BrokerController;
+import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
+import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
+import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
+import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.BrokerConfig;
+import org.apache.rocketmq.common.MQVersion;
+import org.apache.rocketmq.common.MixAll;
+import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
+import org.apache.rocketmq.common.message.MessageExt;
+import org.apache.rocketmq.common.namesrv.NamesrvConfig;
+import org.apache.rocketmq.logappender.common.ProducerInstance;
+import org.apache.rocketmq.namesrv.NamesrvController;
+import org.apache.rocketmq.remoting.netty.NettyClientConfig;
+import org.apache.rocketmq.remoting.netty.NettyServerConfig;
+import org.apache.rocketmq.remoting.protocol.RemotingCommand;
+import org.apache.rocketmq.store.config.MessageStoreConfig;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Basic test rocketmq broker and name server init
+ */
+public class AbstractTestCase {
+
+ private static String nameServer = "localhost:9876";
+
+ private static NamesrvController namesrvController;
+
+ private static BrokerController brokerController;
+
+ private static String topic = "TopicTest";
+
+ @BeforeClass
+ public static void startRocketmqService() throws Exception {
+
+ /*
+ Start nameserver
+ */
+ startNamesrv();
+
+ /*
+ Start broker
+ */
+ startBroker();
+
+ Thread.sleep(2000);
--- End diff --
CountDownLatch
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq issue #101: [ROCKETMQ-194] log appender support
Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:
https://github.com/apache/incubator-rocketmq/pull/101
[](https://coveralls.io/builds/11454454)
Coverage increased (+0.3%) to 31.295% when pulling **1f9851b6f9b7a4ea25722ef31a7392bccde01cc2 on lindzh:log_appender** into **fa85abcdf6ee46e56403ddf86828a38683103fd0 on apache:master**.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by vongosling <gi...@git.apache.org>.
Github user vongosling commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115887366
--- Diff: logappender/src/main/java/org/apache/rocketmq/logappender/log4j2/RocketmqLog4j2Appender.java ---
@@ -0,0 +1,232 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender.log4j2;
+
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.rocketmq.common.message.Message;
+import org.apache.rocketmq.logappender.common.ProducerInstance;
+import org.apache.logging.log4j.core.ErrorHandler;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
+import org.apache.logging.log4j.core.layout.SerializedLayout;
+import org.apache.rocketmq.client.producer.MQProducer;
+
+import java.io.Serializable;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Log4j2 Appender Component
+ */
+@Plugin(
+ name = "Rocketmq",
--- End diff --
Apache RocketMQ
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq issue #101: [ROCKETMQ-194] log appender support
Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:
https://github.com/apache/incubator-rocketmq/pull/101
[](https://coveralls.io/builds/11487751)
Coverage increased (+0.1%) to 31.114% when pulling **e269dc66a1b8ea4fbc699641e0252b23fca7bc81 on lindzh:log_appender** into **fa85abcdf6ee46e56403ddf86828a38683103fd0 on apache:master**.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq issue #101: [ROCKETMQ-194] log appender support
Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:
https://github.com/apache/incubator-rocketmq/pull/101
[](https://coveralls.io/builds/11487874)
Coverage increased (+0.4%) to 31.34% when pulling **592a0393d7361ca63fe85dd4fb58fce43809793b on lindzh:log_appender** into **fa85abcdf6ee46e56403ddf86828a38683103fd0 on apache:master**.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by vongosling <gi...@git.apache.org>.
Github user vongosling commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115472704
--- Diff: logappender/src/main/java/org/apache/rocketmq/logappender/log4j/RocketmqLog4jAppender.java ---
@@ -0,0 +1,193 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender.log4j;
+
+import org.apache.rocketmq.common.message.Message;
+import org.apache.rocketmq.logappender.common.ProducerInstance;
+import org.apache.log4j.AppenderSkeleton;
+import org.apache.log4j.helpers.LogLog;
+import org.apache.log4j.spi.ErrorCode;
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.rocketmq.client.producer.MQProducer;
+
+/**
+ * Log4j Appender Component
+ */
+public class RocketmqLog4jAppender extends AppenderSkeleton {
+
+ /**
+ * appended message tag define
--- End diff --
Capitalize the first letter~
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by vongosling <gi...@git.apache.org>.
Github user vongosling commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115886436
--- Diff: logappender/src/main/java/org/apache/rocketmq/logappender/log4j/RocketmqLog4jAppender.java ---
@@ -0,0 +1,193 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender.log4j;
+
+import org.apache.rocketmq.common.message.Message;
+import org.apache.rocketmq.logappender.common.ProducerInstance;
+import org.apache.log4j.AppenderSkeleton;
+import org.apache.log4j.helpers.LogLog;
+import org.apache.log4j.spi.ErrorCode;
+import org.apache.log4j.spi.LoggingEvent;
+import org.apache.rocketmq.client.producer.MQProducer;
+
+/**
+ * Log4j Appender Component
+ */
+public class RocketmqLog4jAppender extends AppenderSkeleton {
+
+ /**
+ * Appended message tag define
+ */
+ private String tag;
+
+ /**
+ * Whitch topic to send log messages
+ */
+ private String topic;
+
+ private boolean locationInfo;
+
+ /**
+ * Log producer send instance
+ */
+ private MQProducer producer;
+
+ /**
+ * Lokcetmq nameserver address
--- End diff --
Lokcetmq?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by zhouxinyu <gi...@git.apache.org>.
Github user zhouxinyu commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r116381299
--- Diff: logappender/src/main/java/org/apache/rocketmq/logappender/log4j2/RocketmqLog4j2Appender.java ---
@@ -0,0 +1,233 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender.log4j2;
+
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.ErrorHandler;
+import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.Node;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderAttribute;
+import org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
+import org.apache.logging.log4j.core.config.plugins.PluginElement;
+import org.apache.rocketmq.common.message.Message;
+import org.apache.rocketmq.logappender.common.ProducerInstance;
+import org.apache.logging.log4j.core.appender.AbstractAppender;
+import org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
+import org.apache.logging.log4j.core.layout.SerializedLayout;
+import org.apache.rocketmq.client.producer.MQProducer;
+
+import java.io.Serializable;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Log4j2 Appender Component
+ */
+@Plugin(name = "RocketMQ",
+ category = Node.CATEGORY,
+ elementType = Appender.ELEMENT_TYPE,
+ printObject = true)
+public class RocketmqLog4j2Appender extends AbstractAppender {
+
+ /**
+ * RocketMQ nameserver address
+ */
+ private String nameServerAddress;
+
+ /**
+ * Log producer group
+ */
+ private String producerGroup;
+
+ /**
+ * Log producer send instance
+ */
+ private MQProducer producer;
+
+ /**
+ * Appended message tag define
+ */
+ private String tag;
+
+ /**
+ * Whitch topic to send log messages
+ */
+ private String topic;
+
+
+ protected RocketmqLog4j2Appender(String name, Filter filter, Layout<? extends Serializable> layout,
+ boolean ignoreExceptions, String nameServerAddress, String producerGroup,
+ String topic, String tag) {
+ super(name, filter, layout, ignoreExceptions);
+ this.producer = producer;
+ this.topic = topic;
+ this.tag = tag;
+ this.nameServerAddress = nameServerAddress;
+ this.producerGroup = producerGroup;
+ try {
+ this.producer = ProducerInstance.getInstance(this.nameServerAddress, this.producerGroup);
+ } catch (Exception e) {
+ ErrorHandler handler = this.getHandler();
+ if (handler != null) {
+ handler.error("Starting RocketmqLog4j2Appender [" + this.getName()
+ + "] nameServerAddress:" + nameServerAddress + " group:" + producerGroup + " " + e.getMessage());
+ }
+ }
+ }
+
+ /**
+ * Info,error,warn,callback method implementation
+ *
+ * @param event
+ */
+ public void append(LogEvent event) {
+ if (null == producer) {
+ return;
+ }
+
+ try {
+ byte[] bytes = this.getLayout().toByteArray(event);
+ Message msg = new Message(topic, tag, bytes);
+ msg.getProperties().put(ProducerInstance.APPENDER_TYPE, ProducerInstance.LOG4J2_APPENDER);
+
+ //Send message and do not wait for the ack from the message broker.
+ producer.sendOneway(msg);
+ } catch (Exception e) {
+ ErrorHandler handler = this.getHandler();
+ if (handler != null) {
+ handler.error("Could not send message in RocketmqLog4j2Appender [" + this.getName() + "].", e);
--- End diff --
May be we want to know which log message isn't send to server?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by vongosling <gi...@git.apache.org>.
Github user vongosling commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115471844
--- Diff: logappender/README.md ---
@@ -0,0 +1,64 @@
+# RocketMQ-LogAppender [](https://travis-ci.org/rocketmq/rocketmq-logappender) [](https://coveralls.io/github/rocketmq/rocketmq-logappender?branch=master)
+
+
+## Introduction
+RocketMQ-LogAppender is a logging component implement of log4j,log4j2 and logback.Taking Apache RocketMQ as broker.
+All logs loged will be send to the topic you define.
+
+## Examples
+
+#### log4j example
+
+> config detail
+
+```xml
+<appender name="mqAppender1" class="org.apache.rocketmq.logappender.log4j.RocketmqLog4jAppender">
+ <param name="Tag" value="log1" />
+ <param name="Topic" value="TopicTest" />
+ <param name="ProducerGroup" value="log4jxml" />
+ <param name="NameServerAddress" value="127.0.0.1:9876"/>
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss}-%p %t %c - %m%n" />
+ </layout>
+</appender>
+
+<appender name="mqAsyncAppender1" class="org.apache.log4j.AsyncAppender">
+ <param name="BufferSize" value="1024" />
+ <param name="Blocking" value="false" />
+ <appender-ref ref="mqAppender1"></appender-ref>
+</appender>
+
+<logger name="testLogger" additivity="false">
+ <level value="INFO" />
+ <appender-ref ref="mqAsyncAppender1" />
+</logger>
+
+```
+
+#### logback example
+
+```xml
+<appender name="mqAppender1" class="org.apache.rocketmq.logappender.logback.RocketmqLogbackAppender">
+ <tag>log1</tag>
+ <topic>TopicTest</topic>
+ <producerGroup>logback</producerGroup>
+ <nameServerAddress>127.0.0.1:9876</nameServerAddress>
+ <layout>
+ <pattern>%date %p %t - %m%n</pattern>
+ </layout>
+</appender>
+
+<appender name="mqAsyncAppender1" class="ch.qos.logback.classic.AsyncAppender">
+ <queueSize>1024</queueSize>
+ <discardingThreshold>80</discardingThreshold>
+ <maxFlushTime>2000</maxFlushTime>
+ <neverBlock>true</neverBlock>
+ <appender-ref ref="mqAppender1"/>
+</appender>
+<logger name="testLogger" level="debug" additivity="false">
+ <appender-ref ref="mqAsyncAppender1"/>
+</logger>
+
+```
+
+More example,like log4j2,please see Test case.
--- End diff --
Could we give the example link for user ?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by vongosling <gi...@git.apache.org>.
Github user vongosling commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115470775
--- Diff: logappender/README.md ---
@@ -0,0 +1,64 @@
+# RocketMQ-LogAppender [](https://travis-ci.org/rocketmq/rocketmq-logappender) [](https://coveralls.io/github/rocketmq/rocketmq-logappender?branch=master)
--- End diff --
Could we remove it if we want it into parent modue, we can reuse rocektmq existing infra.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by zhouxinyu <gi...@git.apache.org>.
Github user zhouxinyu commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r116382010
--- Diff: logappender/src/main/java/org/apache/rocketmq/logappender/common/ProducerInstance.java ---
@@ -0,0 +1,96 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender.common;
+
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.client.producer.DefaultMQProducer;
+import org.apache.rocketmq.client.producer.MQProducer;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Common Producer component
+ */
+public class ProducerInstance {
+
+ public static final String APPENDER_TYPE = "APPENDER_TYPE";
+
+ public static final String LOG4J_APPENDER = "LOG4J_APPENDER";
+
+ public static final String LOG4J2_APPENDER = "LOG4J2_APPENDER";
+
+ public static final String LOGBACK_APPENDER = "LOGBACK_APPENDER";
+
+ public static final String DEFAULT_GROUP = "rocketmq_appender";
+
+ private static ConcurrentHashMap<String, MQProducer> producerMap = new ConcurrentHashMap<String, MQProducer>();
+
+ private static String genKey(String nameServerAddress, String group) {
+ return nameServerAddress + "_" + group;
+ }
+
+
+ public static MQProducer getInstance(String nameServerAddress, String group) throws MQClientException {
+ if (group == null) {
+ group = DEFAULT_GROUP;
+ }
+
+ String genKey = genKey(nameServerAddress, group);
+ MQProducer p = producerMap.get(genKey);
+ if (p != null) {
+ return p;
+ }
+
+ DefaultMQProducer defaultMQProducer = new DefaultMQProducer(group);
+ defaultMQProducer.setNamesrvAddr(nameServerAddress);
+ MQProducer beforeProducer = null;
+ //cas put producer
+ synchronized (producerMap) {
--- End diff --
It seems that there is no need to use `synchronized `?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by lindzh <gi...@git.apache.org>.
Github user lindzh commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r116638805
--- Diff: logappender/src/main/java/org/apache/rocketmq/logappender/common/ProducerInstance.java ---
@@ -0,0 +1,96 @@
+/*
+ * 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
+ *
+ * http://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.
+ */
+package org.apache.rocketmq.logappender.common;
+
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.client.producer.DefaultMQProducer;
+import org.apache.rocketmq.client.producer.MQProducer;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Common Producer component
+ */
+public class ProducerInstance {
+
+ public static final String APPENDER_TYPE = "APPENDER_TYPE";
+
+ public static final String LOG4J_APPENDER = "LOG4J_APPENDER";
+
+ public static final String LOG4J2_APPENDER = "LOG4J2_APPENDER";
+
+ public static final String LOGBACK_APPENDER = "LOGBACK_APPENDER";
+
+ public static final String DEFAULT_GROUP = "rocketmq_appender";
+
+ private static ConcurrentHashMap<String, MQProducer> producerMap = new ConcurrentHashMap<String, MQProducer>();
+
+ private static String genKey(String nameServerAddress, String group) {
+ return nameServerAddress + "_" + group;
+ }
+
+
+ public static MQProducer getInstance(String nameServerAddress, String group) throws MQClientException {
+ if (group == null) {
+ group = DEFAULT_GROUP;
+ }
+
+ String genKey = genKey(nameServerAddress, group);
+ MQProducer p = producerMap.get(genKey);
+ if (p != null) {
+ return p;
+ }
+
+ DefaultMQProducer defaultMQProducer = new DefaultMQProducer(group);
+ defaultMQProducer.setNamesrvAddr(nameServerAddress);
+ MQProducer beforeProducer = null;
+ //cas put producer
+ synchronized (producerMap) {
+ beforeProducer = producerMap.putIfAbsent(genKey, defaultMQProducer);
+ }
+ if (beforeProducer != null) {
+ return beforeProducer;
+ }
+ defaultMQProducer.start();
+ return defaultMQProducer;
+ }
+
+
+ public static void removeAndClose(String nameServerAddress, String group) {
+ if (group == null) {
+ group = DEFAULT_GROUP;
+ }
+ String genKey = genKey(nameServerAddress, group);
+ MQProducer producer = producerMap.get(genKey);
--- End diff --
Yes,makes it more simple.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq pull request #101: [ROCKETMQ-194] log appender support
Posted by vongosling <gi...@git.apache.org>.
Github user vongosling commented on a diff in the pull request:
https://github.com/apache/incubator-rocketmq/pull/101#discussion_r115472312
--- Diff: logappender/pom.xml ---
@@ -0,0 +1,122 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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
+
+ http://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.
+ -->
+<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">
+ <parent>
+ <groupId>org.apache.rocketmq</groupId>
+ <artifactId>rocketmq-all</artifactId>
+ <version>4.1.0-incubating-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>rocketmq-logappender</artifactId>
+ <packaging>jar</packaging>
+ <name>rocketmq-logappender ${project.version}</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.test.skip>false</maven.test.skip>
+ <maven.javadoc.skip>true</maven.javadoc.skip>
+ <maven.compiler.source>1.7</maven.compiler.source>
+ <maven.compiler.target>1.7</maven.compiler.target>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.7</version>
+ <optional>true</optional>
--- End diff --
We must consider the suitable dependency here.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---
[GitHub] incubator-rocketmq issue #101: [ROCKETMQ-194] log appender support
Posted by coveralls <gi...@git.apache.org>.
Github user coveralls commented on the issue:
https://github.com/apache/incubator-rocketmq/pull/101
[](https://coveralls.io/builds/11454454)
Coverage increased (+0.3%) to 31.295% when pulling **1f9851b6f9b7a4ea25722ef31a7392bccde01cc2 on lindzh:log_appender** into **fa85abcdf6ee46e56403ddf86828a38683103fd0 on apache:master**.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---