Producer with name is already connected to topic when using Pulsar appender with Ignite logger

huangapple go评论57阅读模式
英文:

Producer with name is already connected to topic when using Pulsar appender with Ignite logger

问题

I have translated the code-related portions of your text. Here they are:

我有一个复杂的项目,使用Ignite,并安装了Ignite版本的log4j2。

我还想安装[Pulsar appender](https://github.com/apache/pulsar/tree/master/pulsar-log4j2-appender/src/main/java/org/apache/pulsar/log4j2/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$5.apply(Log4J2Logger.java:405)
    at org.apache.ignite.logger.log4j2.Log4J2Logger$5.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>
    <!-- 其他依赖项 -->
    <!-- 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>
            <!-- 其他排除项 -->
        </exclusions>
    </dependency>
</dependencies>

Please note that this is the translated code portion. If you have any other specific translation requests or questions, feel free to ask.

英文:

I have a complex project that uses Ignite and has the Ignite version of log4j2 installed.

I'd also like to install a Pulsar appender to log4j2, however, when I start up the application, I get the following error:

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 &#39;pulsar-log4j2-appender-json_persistor4&#39; 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$5.apply(Log4J2Logger.java:405)
	at org.apache.ignite.logger.log4j2.Log4J2Logger$5.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)

Clearly, there is a clash between the two dependencies. I have excluded most when I imported Pulsar appender to my pom.xml however:

 &lt;dependencies&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.apache.ignite&lt;/groupId&gt;
        &lt;artifactId&gt;ignite-spring&lt;/artifactId&gt;
        &lt;version&gt;${ignite.version}&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.apache.ignite&lt;/groupId&gt;
        &lt;artifactId&gt;ignite-zookeeper&lt;/artifactId&gt;
        &lt;version&gt;${ignite.version}&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.apache.ignite&lt;/groupId&gt;
        &lt;artifactId&gt;ignite-urideploy&lt;/artifactId&gt;
        &lt;version&gt;${ignite.version}&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.apache.ignite&lt;/groupId&gt;
        &lt;artifactId&gt;ignite-log4j2&lt;/artifactId&gt;
        &lt;version&gt;${ignite.version}&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
        &lt;artifactId&gt;gson&lt;/artifactId&gt;
        &lt;version&gt;2.8.6&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.apache.pulsar&lt;/groupId&gt;
        &lt;artifactId&gt;pulsar-client&lt;/artifactId&gt;
        &lt;version&gt;${pulsar.version}&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.java-websocket&lt;/groupId&gt;
        &lt;artifactId&gt;Java-WebSocket&lt;/artifactId&gt;
        &lt;version&gt;1.3.8&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework&lt;/groupId&gt;
        &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
    &lt;/dependency&gt;

    &lt;!-- Pulsar logging --&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.apache.pulsar&lt;/groupId&gt;
        &lt;artifactId&gt;pulsar-log4j2-appender&lt;/artifactId&gt;
        &lt;version&gt;2.6.0&lt;/version&gt;
        &lt;exclusions&gt;
            &lt;exclusion&gt;
                &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
                &lt;artifactId&gt;log4j-slf4j-impl&lt;/artifactId&gt;
            &lt;/exclusion&gt;
            &lt;exclusion&gt;
                &lt;groupId&gt;org.apache.pulsar&lt;/groupId&gt;
                &lt;artifactId&gt;pulsar-client&lt;/artifactId&gt;
            &lt;/exclusion&gt;
            &lt;exclusion&gt;
                &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
                &lt;artifactId&gt;log4j-api&lt;/artifactId&gt;
            &lt;/exclusion&gt;
            &lt;exclusion&gt;
                &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
                &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
            &lt;/exclusion&gt;
        &lt;/exclusions&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;

And this is what my log4j2.xml looks like:

&lt;Configuration monitorInterval=&quot;60&quot;&gt;
    &lt;Appenders&gt;
        &lt;Console name=&quot;CONSOLE&quot; target=&quot;SYSTEM_OUT&quot;&gt;
            &lt;PatternLayout pattern=&quot;%d{hh:mm:ss,SSS} [%t] %-5p %c %x - %m%n&quot;/&gt;
            &lt;ThresholdFilter level=&quot;ERROR&quot; onMatch=&quot;DENY&quot; onMismatch=&quot;ACCEPT&quot;/&gt;
        &lt;/Console&gt;

        &lt;Console name=&quot;CONSOLE_ERR&quot; target=&quot;SYSTEM_ERR&quot;&gt;
            &lt;PatternLayout pattern=&quot;[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n&quot;/&gt;
        &lt;/Console&gt;

        &lt;Routing name=&quot;FILE&quot;&gt;
            &lt;Routes pattern=&quot;$${sys:nodeId}&quot;&gt;
                &lt;Route&gt;
                    &lt;RollingFile name=&quot;Rolling-${sys:nodeId}&quot; fileName=&quot;ignite/work/log/ignite-${sys:nodeId}.log&quot;
                                 filePattern=&quot;ignite/work/log/ignite-${sys:nodeId}-%i-%d{yyyy-MM-dd}.log.gz&quot;&gt;
                        &lt;PatternLayout pattern=&quot;[%d{ISO8601}][%-5p][%t][%c{1}]%notEmpty{[%markerSimpleName]} %m%n&quot;/&gt;
                        &lt;Policies&gt;
                            &lt;TimeBasedTriggeringPolicy interval=&quot;6&quot; modulate=&quot;true&quot; /&gt;
                            &lt;SizeBasedTriggeringPolicy size=&quot;10 MB&quot; /&gt;
                        &lt;/Policies&gt;
                    &lt;/RollingFile&gt;
                &lt;/Route&gt;
            &lt;/Routes&gt;
        &lt;/Routing&gt;
        &lt;Pulsar name=&quot;PULSAR&quot; serviceUrl=&quot;pulsar://172.21.11.82:6650&quot; topic=&quot;json_persistor&quot;  avoidRecursive=&quot;false&quot;&gt;
            &lt;PatternLayout pattern=&quot;%msg%n&quot;/&gt;
        &lt;/Pulsar&gt;
    &lt;/Appenders&gt;

    &lt;Loggers&gt;
     
        &lt;Logger name=&quot;org.apache.ignite&quot; level=&quot;ERROR&quot;/&gt;
        &lt;Logger name=&quot;org.springframework&quot; level=&quot;WARN&quot;/&gt;
        &lt;Logger name=&quot;org.eclipse.jetty&quot; level=&quot;WARN&quot;/&gt;
        &lt;Logger name=&quot;org.eclipse.jetty.util.log&quot; level=&quot;ERROR&quot;/&gt;
        &lt;Logger name=&quot;org.eclipse.jetty.util.component&quot; level=&quot;ERROR&quot;/&gt;
        &lt;Logger name=&quot;com.amazonaws&quot; level=&quot;WARN&quot;/&gt;

        &lt;Root level=&quot;INFO&quot;&gt;
            &lt;AppenderRef ref=&quot;CONSOLE&quot; level=&quot;INFO&quot;/&gt;
            &lt;AppenderRef ref=&quot;CONSOLE_ERR&quot; level=&quot;ERROR&quot;/&gt;
            &lt;AppenderRef ref=&quot;FILE&quot; level=&quot;DEBUG&quot;/&gt;
        &lt;/Root&gt;
    &lt;/Loggers&gt;
&lt;/Configuration&gt;

答案1

得分: 2

问题不在于log4j的依赖关系,而是与试图连接到Pulsar主题的生产者发生了名称冲突。堆栈跟踪显示“Producer with name 'pulsar-log4j2-appender-json_persistor4' is already connected to topic”,我假设这是您的应用程序用于一个生产者的名称。

因此,您只需要停止先前运行的应用程序实例,以终止现有的生产者,以便新的生产者可以连接。

一个长期的解决方案是避免显式命名您的生产者,让Pulsar为您处理。然后名称将保证是唯一的。有关更多详细信息,请参阅https://stackoverflow.com/questions/63258912/is-it-possible-to-have-multiple-producers-for-the-same-topic-on-pulsar。

英文:

The issue isn't with the log4j dependencies, but rather with a name conflict with the producer that is trying to connect to the Pulsar topic. The stack trace says "Producer with name 'pulsar-log4j2-appender-json_persistor4' is already connected to topic", which I assume is the name your application uses for one of the producers.

Therefore, you simply need to stop the previously running instance of the application in order to terminate the existing producer so that the new one can connect.

An long-term solution is to avoid explicitly naming your producers and allow Pulsar to handle that for you. Then the names are guaranteed to be unique. See https://stackoverflow.com/questions/63258912/is-it-possible-to-have-multiple-producers-for-the-same-topic-on-pulsar for more details

huangapple
  • 本文由 发表于 2020年7月28日 16:14:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/63129768.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定