Can someone explain me the differences between the two properties?
@Override
public void setUp() throws Exception {
context = new DefaultCamelContext(new SimpleRegistry());
template = context.createProducerTemplate();
context.addRoutes(new RouteBuilder() {
public void configure() throws Exception {
PropertiesComponent prop = context.getComponent(
"properties", PropertiesComponent.class);
prop.setLocation("classpath:test.properties");
from("direct:start")
.log("Property: ${properties:a}")
.process(new Processor() {
@Override
public void process(Exchange ex) throws Exception {
String a = ex.getProperty("a", String.class);
LOG.info("Property: " + a);
}
})
;
}
});
context.getShutdownStrategy().setTimeout(1);
context.start();
}
@Test
public void testRoute() throws Exception {
template.sendBody("direct:start", null);
}
The properties-file (test.properties
):
a = a
Output:
2015-09-03 14:38:01,740 | INFO | route1 | Property: a
2015-09-03 14:38:01,743 | INFO | CamelTest2 | Property: null
The first line is from .log("${properties:a}")
, so it can be found. However, String a = ex.getProperty("a", String.class);
cannot. Both are properties and point to the same property, right?
What is the difference, and how can I find the property in the processor?
The Exchange
is only created upon the reception of the request in the client side. And this means that your Camel Processor will have access to the Message
only and not the property from external resource.
The Exchange's properties are the Message's meta-information. As per the doc,
The Exchange also holds meta-data during its entire lifetime stored as properties accessible using the various
getProperty(String)
methods. ThesetProperty(String, Object)
is used to store a property. For example you can use this to store security, SLA related data or any other information deemed useful throughout processing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With