The following code sends message to ActiveMQ
1: public class TestCodeForBlog {2: public static RouteBuilder createRoute() {3: return new RouteBuilder() {4: public void configure() throws Exception {5: from("direct:toActiveMQ")6: .marshal().jaxb("org.apache.camel.example.console").7: setHeader(Exchange.FILE_NAME, constant("test.ActiveMQ"))8: .to("file:target/TestmyFiles")9: .to("test-jms:queue:test.queue").10: to("stream:out");11: }12: };13: }14:15: public static void main(String[] args) {16:17:18: try {19: CamelContext context = new DefaultCamelContext();20:21: ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");22: // Explicit name the jms active mq component23: context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));24:25: context.addRoutes(createRoute());26: context.start();27:28: PersoneData thePersoneData = new PersoneData();29:30: thePersoneData.Name = "Zvika";31:32: thePersoneData.Age = 42;33:34: thePersoneData.Email = "Loveme42@hotmail.com";35:36: thePersoneData.Address ="Bilo 9b Ness-Ziona";37:38: Thread.sleep(1000);39:40: ProducerTemplate template = context.createProducerTemplate();41:42: template.sendBody("direct:toActiveMQ", thePersoneData);43:44: Thread.sleep(1000);45: System.out.print("I'm out");46:47: } catch (Exception e) {48: e.printStackTrace();49: }50: }51: }
The following dependencies should be inserted into the pom file :
1: <dependency>2: <groupId>org.apache.activemq</groupId>3: <artifactId>activemq-core</artifactId>4: </dependency>5: <dependency>6: <groupId>org.apache.activemq</groupId>7: <artifactId>activemq-camel</artifactId>8: <exclusions>9: <exclusion>10: <groupId>org.apache.camel</groupId>11: <artifactId>camel-web</artifactId>12: </exclusion>13: </exclusions>14: </dependency>15: <dependency>16: <groupId>org.apache.xbean</groupId>17: <artifactId>xbean-spring</artifactId>18: <exclusions>19: <exclusion>20: <groupId>org.springframework</groupId>21: <artifactId>spring</artifactId>22: </exclusion>23: </exclusions>24: </dependency>
אין תגובות:
הוסף רשומת תגובה