/** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { CamelContext context = new DefaultCamelContext(); ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm:/localhost"); context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory)); context.addRoutes( new RouteBuilder() { public void configure() { from("ftp://127.0.0.1/orders?username=johnny&password=quest") .process( new Processor() { public void process(Exchange exchange) throws Exception { System.out.println( "\nWe just downloaded: " + exchange.getIn().getHeader("CamelFileName")); System.out.println("Body:"); System.out.println(exchange.getIn().getBody()); System.out.println("\n==================\n"); } }) .to("jms:incomingOrders"); } }); context.start(); Thread.sleep(60000); context.stop(); }
protected CamelContext createCamelContext() throws Exception { CamelContext camelContext = super.createCamelContext(); ConnectionFactory connectionFactory = CamelJmsTestHelper.createConnectionFactory(); camelContext.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory)); return camelContext; }
public static void main(String[] args) throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("integration.xml"); CamelContext context = (CamelContext) ctx.getBean("camelContext"); ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616"); context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(cf)); context.addRoutes( new RouteBuilder() { public void configure() { from("jms:queue:spring-tweets") .process( new Processor() { public void process(Exchange e) { System.out.println("Message: " + e.getIn().getBody()); Tweet tweet = (Tweet) e.getIn().getBody(); System.out.println("Sender: " + tweet.getFromUser()); System.out.println("Text: " + tweet.getText()); } }); } }); context.start(); while (true) {} }
@Override public void configure() throws Exception { /** * Create an instance of the Camel JmsComponent and configure it to support JMS transactions. */ JmsComponent jmsComponent = JmsComponent.jmsComponentTransacted(connectionFactory, transactionManager); getContext().addComponent("jms", jmsComponent); /** Create an instance of the Camel JpaComponent and configure it to support transactions. */ JpaComponent jpaComponent = new JpaComponent(); jpaComponent.setEntityManagerFactory(entityManager.getEntityManagerFactory()); jpaComponent.setTransactionManager(transactionManager); getContext().addComponent("jpa", jpaComponent); /** Configure JAXB so that it can discover model classes. */ JaxbDataFormat jaxbDataFormat = new JaxbDataFormat(); jaxbDataFormat.setContextPath(Order.class.getPackage().getName()); /** * Configure a simple dead letter strategy. Whenever an IllegalStateException is encountered * this takes care of rolling back the JMS and JPA transactions. The problem message is sent to * the WildFly dead letter JMS queue (DLQ). */ onException(IllegalStateException.class) .maximumRedeliveries(1) .handled(true) .to("jms:queue:DLQ") .markRollbackOnly(); /** * This route consumes XML files from JBOSS_HOME/standalone/data/orders and sends the file * content to JMS destination OrdersQueue. */ from("file:{{jboss.server.data.dir}}/orders").transacted().to("jms:queue:OrdersQueue"); /** * This route consumes messages from JMS destination OrdersQueue, unmarshalls the XML message * body using JAXB to an Order entity object. The order is then sent to the JPA endpoint for * persisting within an in-memory database. * * <p>Whenever an order quantity greater than 10 is encountered, the route throws an * IllegalStateException which forces the JMS / JPA transaction to be rolled back and the * message to be delivered to the dead letter queue. */ from("jms:queue:OrdersQueue") .unmarshal(jaxbDataFormat) .to("jpa:Order") .choice() .when(simple("${body.quantity} > 10")) .log("Order quantity is greater than 10 - rolling back transaction!") .throwException(new IllegalStateException()) .otherwise() .log("Order processed successfully"); }
public static void main(String args[]) throws Exception { // START SNIPPET: e1 CamelContext context = new DefaultCamelContext(); // END SNIPPET: e1 // Set up the ActiveMQ JMS Components // START SNIPPET: e2 ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); // Note we can explicit name the component context.addComponent("test-jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory)); // END SNIPPET: e2 // Add some configuration by hand ... // START SNIPPET: e3 context.addRoutes( new RouteBuilder() { public void configure() { // from("test-jms:queue:test.queue").to("file://tmp/camel"); from("test-jms:queue:test.queue").to("file:/tmp/camel"); } }); // END SNIPPET: e3 // Camel template - a handy class for kicking off exchanges // START SNIPPET: e4 ProducerTemplate template = context.createProducerTemplate(); // END SNIPPET: e4 // Now everything is set up - lets start the context context.start(); // Now send some test text to a component - for this case a JMS Queue // The text get converted to JMS messages - and sent to the Queue // test.queue // The file component is listening for messages from the Queue // test.queue, consumes // them and stores them to disk. The content of each file will be the // test we sent here. // The listener on the file component gets notified when new files are // found ... that's it! // START SNIPPET: e5 for (int i = 0; i < 10; i++) { template.sendBody("test-jms:queue:test.queue", "Test Message: " + i); } // END SNIPPET: e5 // wait a bit and then stop Thread.sleep(1000); context.stop(); }
protected QueueBrowseStrategy createQueueBrowseStrategy() { QueueBrowseStrategy answer = null; try { answer = JmsComponent.tryCreateDefaultQueueBrowseStrategy(getCamelContext()); } catch (Throwable e) { LOG.debug( "Caught exception trying to create default QueueBrowseStrategy. " + "This could be due to spring 2.0.x on classpath? Cause: " + e, e); } if (answer == null) { LOG.warn( "Cannot browse queues as no QueueBrowseStrategy specified. Are you using Spring 2.0.x by any chance? If you upgrade to 2.5.x or later then queue browsing is supported"); } return answer; }