I can't get a simple hello-world type Spring Boot app to utilize the Pulsar Log4j2 appender. At startup it reports the error:

2021-05-14T15:34:23.549-05:00 [pulsar-client-io-6-1] ERROR o.a.p.c.i.ProducerImpl [applog-json] [pulsar-log4j2-appender-applog-json] Failed to create producer: Producer with name 'pulsar-log4j2-appender-applog-json' is already connected to topic 2021-05-14 15:34:23,550 main ERROR Failed to start pulsar manager org.apache.pulsar.client.api.PulsarClientException$ProducerBusyException: Producer with name 'pulsar-log4j2-appender-applog-json' is already connected to topic at org.apache.pulsar.client.api.PulsarClientException.unwrap(PulsarClientException.java:884) 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) ...

I'm using Apache Pulsar 2.7.1 and pulsar-log4j2-appender:2.6.3 (I've tried other versions of appender with the same result). Its not a matter of having multiple instances running as the error might suggest. I can even verify through 'pulsar-admin topics stats' that there are no current publishers connected to the topic before starting the app. I start up a single instance of a spring boot app with the Pulsar Log4j2 appender and it logs that error and will not send data to Pulsar. Somehow internally the appender must be creating multiple connections if the error message is indeed valid. Has anyone else run into this and figured out a resolution? This seems like a fairly simple thing to try and do and should not be this complicated or finicky.

I posted the example project to GitHub to make it easier for someone to test this.

git clone https://github.com/kelbyloden/pulsarLog4jTest.git
cd pulsarLog4jTest/
./gradlew clean build
./gradlew bootRun -Dapp.name=pulsarLog4jTest -Dlog.level=INFO -Dpulsar.host=localhost

Edit the pulsar.host variable to reflect the hostname of your Pulsar instance. This assumes its at http://localhost:6650. This is referenced in the log4j2.xml file. When I execute this I get the error mentioned.
Note I created another sample Java project which doesn not use Spring Boot and it works fine. It seems to be something with the Spring dependencies.

1

There are 1 answers

3
David Kjerrumgaard On

The error Failed to create producer: Producer with name 'pulsar-log4j2-appender-applog-json' is already connected to topic indicates that the code may have been executed more than once, or that the shutdown logic of the code does not properly shutdown the producer.

Can you share the code? Perhaps a link to a simple Github repo, etc? How are you running the code?