将 Pulsar appender 与 Ignite 记录器一起使用时,具有名称的生产者已连接到主题
Producer with name is already connected to topic when using Pulsar appender with Ignite logger
我有一个使用 Ignite 的复杂项目,并且安装了 Ignite 版本的 log4j2。
我也想安装一个 Pulsar appender 到 log4j2,但是,当我启动应用程序时,出现以下错误:
log4j:WARN No appenders could be found for logger (org.apache.pulsar.shade.io.netty.util.internal.logging.InternalLoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
2020-07-28 15:58:47,732 main ERROR Failed to start pulsar manager org.apache.pulsar.client.api.PulsarClientException$ProducerBusyException: Producer with name 'pulsar-log4j2-appender-json_persistor4' is already connected to topic
at org.apache.pulsar.client.api.PulsarClientException.unwrap(PulsarClientException.java:849)
at org.apache.pulsar.client.impl.ProducerBuilderImpl.create(ProducerBuilderImpl.java:93)
at org.apache.pulsar.log4j2.appender.PulsarManager.startup(PulsarManager.java:127)
at org.apache.pulsar.log4j2.appender.PulsarAppender.start(PulsarAppender.java:187)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:266)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:548)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:620)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:637)
at org.apache.ignite.logger.log4j2.Log4J2Logger.apply(Log4J2Logger.java:405)
at org.apache.ignite.logger.log4j2.Log4J2Logger.apply(Log4J2Logger.java:402)
at org.apache.ignite.logger.log4j2.Log4J2Logger.addConsoleAppenderIfNeeded(Log4J2Logger.java:302)
at org.apache.ignite.logger.log4j2.Log4J2Logger.setNodeId(Log4J2Logger.java:402)
at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.initLogger(IgnitionEx.java:2568)
at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.initializeConfiguration(IgnitionEx.java:2206)
at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start(IgnitionEx.java:1697)
at org.apache.ignite.internal.IgnitionEx.start0(IgnitionEx.java:1117)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:637)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:563)
at org.apache.ignite.Ignition.start(Ignition.java:321)
at com.coinflex.service.release.ReleaseApplication.main(ReleaseApplication.java:39)
显然,这两个依赖项之间存在冲突。当我将 Pulsar appender 导入我的 pom.xml 时,我已经排除了大部分:
<dependencies>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-zookeeper</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-urideploy</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-log4j2</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-client</artifactId>
<version>${pulsar.version}</version>
</dependency>
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.3.8</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<!-- Pulsar logging -->
<dependency>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-log4j2-appender</artifactId>
<version>2.6.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-client</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
这就是我的 log4j2.xml 的样子:
<Configuration monitorInterval="60">
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%d{hh:mm:ss,SSS} [%t] %-5p %c %x - %m%n"/>
<ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="ACCEPT"/>
</Console>
<Console name="CONSOLE_ERR" target="SYSTEM_ERR">
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n"/>
</Console>
<Routing name="FILE">
<Routes pattern="$${sys:nodeId}">
<Route>
<RollingFile name="Rolling-${sys:nodeId}" fileName="ignite/work/log/ignite-${sys:nodeId}.log"
filePattern="ignite/work/log/ignite-${sys:nodeId}-%i-%d{yyyy-MM-dd}.log.gz">
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true" />
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>
</RollingFile>
</Route>
</Routes>
</Routing>
<Pulsar name="PULSAR" serviceUrl="pulsar://172.21.11.82:6650" topic="json_persistor" avoidRecursive="false">
<PatternLayout pattern="%msg%n"/>
</Pulsar>
</Appenders>
<Loggers>
<Logger name="org.apache.ignite" level="ERROR"/>
<Logger name="org.springframework" level="WARN"/>
<Logger name="org.eclipse.jetty" level="WARN"/>
<Logger name="org.eclipse.jetty.util.log" level="ERROR"/>
<Logger name="org.eclipse.jetty.util.component" level="ERROR"/>
<Logger name="com.amazonaws" level="WARN"/>
<Root level="INFO">
<AppenderRef ref="CONSOLE" level="INFO"/>
<AppenderRef ref="CONSOLE_ERR" level="ERROR"/>
<AppenderRef ref="FILE" level="DEBUG"/>
</Root>
</Loggers>
</Configuration>
问题不在于 log4j 依赖项,而是与尝试连接到 Pulsar 主题的生产者的名称冲突。堆栈跟踪显示“名称为 'pulsar-log4j2-appender-json_persistor4' 的生产者已连接到主题”,我假设这是您的应用程序用于生产者之一的名称。
因此,您只需停止应用程序的先前 运行 实例即可终止现有生产者,以便新生产者可以连接。
long-term 解决方案是避免明确命名您的生产者并让 Pulsar 为您处理。然后保证名称是唯一的。有关详细信息,请参阅
我有一个使用 Ignite 的复杂项目,并且安装了 Ignite 版本的 log4j2。
我也想安装一个 Pulsar appender 到 log4j2,但是,当我启动应用程序时,出现以下错误:
log4j:WARN No appenders could be found for logger (org.apache.pulsar.shade.io.netty.util.internal.logging.InternalLoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
2020-07-28 15:58:47,732 main ERROR Failed to start pulsar manager org.apache.pulsar.client.api.PulsarClientException$ProducerBusyException: Producer with name 'pulsar-log4j2-appender-json_persistor4' is already connected to topic
at org.apache.pulsar.client.api.PulsarClientException.unwrap(PulsarClientException.java:849)
at org.apache.pulsar.client.impl.ProducerBuilderImpl.create(ProducerBuilderImpl.java:93)
at org.apache.pulsar.log4j2.appender.PulsarManager.startup(PulsarManager.java:127)
at org.apache.pulsar.log4j2.appender.PulsarAppender.start(PulsarAppender.java:187)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:266)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:548)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:620)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:637)
at org.apache.ignite.logger.log4j2.Log4J2Logger.apply(Log4J2Logger.java:405)
at org.apache.ignite.logger.log4j2.Log4J2Logger.apply(Log4J2Logger.java:402)
at org.apache.ignite.logger.log4j2.Log4J2Logger.addConsoleAppenderIfNeeded(Log4J2Logger.java:302)
at org.apache.ignite.logger.log4j2.Log4J2Logger.setNodeId(Log4J2Logger.java:402)
at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.initLogger(IgnitionEx.java:2568)
at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.initializeConfiguration(IgnitionEx.java:2206)
at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start(IgnitionEx.java:1697)
at org.apache.ignite.internal.IgnitionEx.start0(IgnitionEx.java:1117)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:637)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:563)
at org.apache.ignite.Ignition.start(Ignition.java:321)
at com.coinflex.service.release.ReleaseApplication.main(ReleaseApplication.java:39)
显然,这两个依赖项之间存在冲突。当我将 Pulsar appender 导入我的 pom.xml 时,我已经排除了大部分:
<dependencies>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-zookeeper</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-urideploy</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-log4j2</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-client</artifactId>
<version>${pulsar.version}</version>
</dependency>
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.3.8</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<!-- Pulsar logging -->
<dependency>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-log4j2-appender</artifactId>
<version>2.6.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-client</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
这就是我的 log4j2.xml 的样子:
<Configuration monitorInterval="60">
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%d{hh:mm:ss,SSS} [%t] %-5p %c %x - %m%n"/>
<ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="ACCEPT"/>
</Console>
<Console name="CONSOLE_ERR" target="SYSTEM_ERR">
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n"/>
</Console>
<Routing name="FILE">
<Routes pattern="$${sys:nodeId}">
<Route>
<RollingFile name="Rolling-${sys:nodeId}" fileName="ignite/work/log/ignite-${sys:nodeId}.log"
filePattern="ignite/work/log/ignite-${sys:nodeId}-%i-%d{yyyy-MM-dd}.log.gz">
<PatternLayout pattern="[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy interval="6" modulate="true" />
<SizeBasedTriggeringPolicy size="10 MB" />
</Policies>
</RollingFile>
</Route>
</Routes>
</Routing>
<Pulsar name="PULSAR" serviceUrl="pulsar://172.21.11.82:6650" topic="json_persistor" avoidRecursive="false">
<PatternLayout pattern="%msg%n"/>
</Pulsar>
</Appenders>
<Loggers>
<Logger name="org.apache.ignite" level="ERROR"/>
<Logger name="org.springframework" level="WARN"/>
<Logger name="org.eclipse.jetty" level="WARN"/>
<Logger name="org.eclipse.jetty.util.log" level="ERROR"/>
<Logger name="org.eclipse.jetty.util.component" level="ERROR"/>
<Logger name="com.amazonaws" level="WARN"/>
<Root level="INFO">
<AppenderRef ref="CONSOLE" level="INFO"/>
<AppenderRef ref="CONSOLE_ERR" level="ERROR"/>
<AppenderRef ref="FILE" level="DEBUG"/>
</Root>
</Loggers>
</Configuration>
问题不在于 log4j 依赖项,而是与尝试连接到 Pulsar 主题的生产者的名称冲突。堆栈跟踪显示“名称为 'pulsar-log4j2-appender-json_persistor4' 的生产者已连接到主题”,我假设这是您的应用程序用于生产者之一的名称。
因此,您只需停止应用程序的先前 运行 实例即可终止现有生产者,以便新生产者可以连接。
long-term 解决方案是避免明确命名您的生产者并让 Pulsar 为您处理。然后保证名称是唯一的。有关详细信息,请参阅