...
Next up is to be able to send a message to this endpoint. ThisTODO: Add an endpoint
TODO: Inject the endpoint in our service and use itThe easiest way is to use a CamelProducer. A CamelProducer is inspired by Spring template pattern with for instance JmsTemplate or JdbcTemplate in mind. The template that all the grunt work and exposes a simple interface to the end-user where he/she can set the payload to send. Then the template will do proper resource handling and all related issues in that regard. But how do we get hold of such a template? Well the CamelContext is able to provide one. This is done by configuring the template on the camel context in the spring XML as:
Code Block |
---|
|
<camel:camelContext id="camelContext">
<!-- producer template exposed with this id -->
<camel:template id="camelTemplate"/>
<!-- endpoint named backup that is configued as a file component -->
<camel:endpoint id="backup" uri="file://target?append=false"/>
</camel:camelContext>
|
Then we can expose a ProducerTemplate property on our service with a setter in the Java code as:
Code Block |
---|
|
public class ReportIncidentService {
private ProducerTemplate template;
public void setTemplate(ProducerTemplate template) {
this.template = template;
}
|
And then let Spring handle the dependency inject as below:
Code Block |
---|
|
<bean id="incidentservice" class="org.apache.camel.example.axis.ReportIncidentService">
<!-- set the producer template to use from the camel context below -->
<property name="template" ref="camelTemplate"/>
</bean>
|
TODO: Add a route and use it