Hi, I get sporadic cases of no body when having a client sending small
JSON messages over http, and a jetty endpoint receiving them, and a
short route with a vm endpoint and a bean. Stream-caching is enabled.
The issue only appears when MEP is InOnly. A simple test case to
reproduce the issue is attached, you might have to adjust (increase) the
message count if test executes without failure.
Enabling trace logging on org.apache.camel, there is only one log
statement I noticed to differ when message came through vs. was lost:
2016-06-14 12:50:49.441 [TRACE] [MethodInfo] []: Parameter #0 evaluated
as:
{"key1":"value1","key2":"value2","key3":"value3","key4":"value4","key5":"value5"}
type:
vs.:
2016-06-14 12:50:49.547 [TRACE] [MethodInfo] []: Parameter #0 evaluated
as: type:
The number of lost messages - or empty bodied messages - when running
this test case is in the range 5-50 (out of 800). I have avoided the
issue for now by converting the body from stream to string, but I would
really like to know if I'm using the API wrong or if there is a bug
hidden somewhere. Any help appreciated.
Versions etc:
Camel: 2.17.1
JDK: 1.8.0_77
Jetty: 9.2.15 (also tried 9.1.6)
OS: Fedora + RHEL
Same result if using other client than camel-http
Regards,
Bjørn E.
package tmp;
import static org.junit.Assert.assertEquals;
import org.apache.camel.CamelContext;
import org.apache.camel.ExchangePattern;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.junit.BeforeClass;
import org.junit.Test;
public class CamelStreamConverterTest {
private static final String MSG = "{\"key1\":\"value1\",\"key2\":\"value2\",\"key3\":\"value3\",\"key4\":\"value4\",\"key5\":\"value5\"}";
private static final String URI = "http://127.0.0.1:49999/test";
private static final int MSG_COUNT = 800;
private static CamelContext ctx;
private static ProducerTemplate producerTemplate;
@BeforeClass
public static final void setup() throws Exception {
ctx = new DefaultCamelContext();
ctx.setStreamCaching(true);
ctx.addRoutes(new TestRouteBuilder());
ctx.start();
ctx.startAllRoutes();
producerTemplate = ctx.createProducerTemplate();
}
@Test
public void testConversionFailure() {
for (int i = 0; i < MSG_COUNT; i++) {
producerTemplate.sendBodyAndHeader(URI, MSG, "Content-Type", "application/json");
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
assertEquals(MSG_COUNT, Foo.count);
}
private static final class TestRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("jetty:" + URI).to(ExchangePattern.InOnly, "vm:test");
from("vm:test").bean(Foo.class, "process");
}
}
public static final class Foo {
private static int count = 0;
public String process(String json) {
assertEquals(MSG, json);
count++;
return "OK";
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="info">
<Properties>
<Property name="ptrn">%d{yyyy-MM-dd HH:mm:ss.SSS} [%p] [%c{1}] %x: %m%n</Property>
</Properties>
<Appenders>
<Console name="CON" target="SYSTEM_OUT">
<PatternLayout pattern="${ptrn}"/>
</Console>
</Appenders>
<Loggers>
<Logger name="org.apache.camel" level="info"/>
<Root level="info">
<AppenderRef ref="CON"/>
</Root>
</Loggers>
</Configuration>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>tmp</groupId>
<artifactId>tmp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<camel.version>2.17.1</camel.version>
<log4j2.version>2.6.1</log4j2.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jetty</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${log4j2.version}</version>
</dependency>
</dependencies>
</project>