apache / camel-quarkus

Apache Camel Quarkus
https://camel.apache.org
Apache License 2.0
255 stars 189 forks source link

Log with KafkaProducer does not work #1862

Closed tstuber closed 3 years ago

tstuber commented 3 years ago

Hi

I am facing an issue with Quarkus Camel and Kafka. I use the following route:

    @Override
    public void configure() throws Exception {

        getContext().setStreamCaching(true);
        getContext().setTracing(true);

        from("platform-http:/entries?httpMethodRestrict=POST")
                .to("kafka:{{kafka.topic}}"
                   + "?brokers={{kafka.bootstrap.servers}}")
                .log("whatever")
            ;
    }

I want to write a log entry after the message has been sent to Kafka. Having this .log() component set, I get the following error when calling the endpoint:

$ curl -H "Content-Type: application/json" -X POST --data '{"id":"1","message":"whatever"}' localhost:8080/entries
java.lang.NullPointerException
        at org.apache.camel.processor.CamelInternalProcessor$TracingAdvice.before(CamelInternalProcessor.java:874)
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:237)
        at org.apache.camel.processor.Pipeline$PipelineTask.run(Pipeline.java:90)
        at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:148)
        at org.apache.camel.impl.engine.DefaultReactiveExecutor.schedule(DefaultReactiveExecutor.java:55)
        at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.lambda$run$0(RedeliveryErrorHandler.java:398)
        at org.apache.camel.processor.SendProcessor.lambda$process$0(SendProcessor.java:162)
        at org.apache.camel.component.kafka.KafkaProducer$KafkaProducerCallBack$1.run(KafkaProducer.java:492)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

From the apps logs, the route seems to stop just after calling kafka. The log component is not listed in the trace. There is also no exception or something like that. Same when checking debug logs. The route just seems to end.

2020-10-01 12:26:40,774 INFO  [org.apa.cam.Tracing] (vert.x-eventloop-thread-7) *--> [post-transfo] [from[platform-http:/entries?httpM] Exchange[Id: 8C0A747DF97BA1C-0000000000000001, BodyType: byte[], Body: {"id":"1","message":"whatever"}]
2020-10-01 12:26:40,774 INFO  [org.apa.cam.Tracing] (vert.x-eventloop-thread-7)      [post-transfo] [kafka:{{kafka.topic}}?brokers={{k] Exchange[Id: 8C0A747DF97BA1C-0000000000000001, BodyType: byte[], Body: {"id":"1","message":"whatever"}]

When I remove the .log() component, the requests written and returned properly:

curl -H "Content-Type: application/json" -X POST --data '{"id":"1","message":"whatever"}' localhost:8080/entries
{"id":"1","message":"whatever"}

The message is written to the topic in both cases, so that is not the problem. But I do not understand, why using a log component results in that error... Any ideas?

Thanks for your help

ppalaga commented 3 years ago

Which version of Camel Quarkus and Quarkus are you using? Could you please share your pom.xml?

tstuber commented 3 years ago

Camel Quarkus: 1.0.0 Quarkus: 1.7.0.Final

pom.xml:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.company.example</groupId>
    <artifactId>myproject</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <compiler-plugin.version>3.8.1</compiler-plugin.version>
        <maven.compiler.parameters>true</maven.compiler.parameters>
        <version.sonar-maven-plugin>3.7.0.1746</version.sonar-maven-plugin>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <quarkus-plugin.version>1.7.0.Final</quarkus-plugin.version>
        <quarkus.platform.artifact-id>quarkus-universe-bom</quarkus.platform.artifact-id>
        <quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
        <quarkus.platform.version>1.7.0.Final</quarkus.platform.version>
        <surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>${quarkus.platform.group-id}</groupId>
                <artifactId>${quarkus.platform.artifact-id}</artifactId>
                <version>${quarkus.platform.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy</artifactId>
        </dependency>

        <!-- Camel dependencies -->
        <dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-main</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-timer</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-jackson</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-file</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-direct</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-platform-http</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-kafka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-seda</artifactId>
        </dependency>

        <!-- Monitoring / Tracing -->
        <dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-microprofile-health</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-microprofile-metrics</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-opentracing</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-log</artifactId>
        </dependency>

        <!-- test dependencies -->
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit5</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>commons-logging-jboss-logging</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-maven-plugin</artifactId>
                <version>${quarkus-plugin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare</goal>
                            <goal>prepare-tests</goal>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${compiler-plugin.version}</version>
            </plugin>
            <plugin>
                <groupId>org.sonarsource.scanner.maven</groupId>
                <artifactId>sonar-maven-plugin</artifactId>
                <version>${version.sonar-maven-plugin}</version>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${surefire-plugin.version}</version>
                <configuration>
                    <systemPropertyVariables>
                        <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                        <maven.home>${maven.home}</maven.home>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.5</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <!-- attached to Maven test phase -->
                    <execution>
                        <id>report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                        <configuration>
                            <xml.enabled>true</xml.enabled>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>native</id>
            <activation>
                <property>
                    <name>native</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <version>${surefire-plugin.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                                <configuration>
                                    <systemPropertyVariables>
                                        <native.image.path>
                                            ${project.build.directory}/${project.build.finalName}-runner
                                        </native.image.path>
                                        <java.util.logging.manager>org.jboss.logmanager.LogManager
                                        </java.util.logging.manager>
                                        <maven.home>${maven.home}</maven.home>
                                    </systemPropertyVariables>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
            <properties>
                <quarkus.package.type>native</quarkus.package.type>
            </properties>
        </profile>
    </profiles>
</project>
tstuber commented 3 years ago

I also face the same issue when using: Camel Quarkus: 1.1.0 Quarkus: 1.7.5.Final

jamesnetherton commented 3 years ago

I can replicate this issue with Camel Quarkus 1.1.0 but not with the latest 1.2.0-SNAPSHOT.

tstuber commented 3 years ago

Indeed, poblem is solved with camel-quarkus 1.2.0.