The ProducerTemplate interface allows you to send message exchanges to endpoints in a variety of different ways to make it easy to work with Camel endpoint instances from Java code. See more about templates . ConsumerTemplate is for working with Camel and consuming message instances in an Exchange from an Endpoint. See more
Here is one Camel routing example which is using Producer and Consumer templates to send and receive messages. In this example Apache activemq is using for messaging services.
1. Start Activemq Message broker.
In order to send and receive messages we have to start Apache activemq message broker before running this main program.
2. Create a Maven Project.
Create a maven project and add below dependencies
2. Create Spring configuration file (camel-context.xml)
In this Spring configuration file we are defining camel templates inside context. Also adding bean definition for activemq component.
3. Create a Main class (TemplateTest.java)
In this main class we will load all the components which we defined in the configuration file and create templates to send and receive messages.
3. Run the program
Upon running this main program we can see below logs are in the console and Queue details in the ActiveMQ console (http://localhost:8161/admin/)
Reference: Apache Camel