| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
package org.apache.camel.itest.jms; |
| 19 |
|
|
| 20 |
|
import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge; |
| 21 |
|
|
| 22 |
|
import javax.jms.ConnectionFactory; |
| 23 |
|
import javax.jms.Message; |
| 24 |
|
import javax.jms.MessageListener; |
| 25 |
|
|
| 26 |
|
import junit.framework.TestCase; |
| 27 |
|
|
| 28 |
|
import org.apache.activemq.ActiveMQConnectionFactory; |
| 29 |
|
import org.apache.camel.CamelContext; |
| 30 |
|
import org.apache.camel.Producer; |
| 31 |
|
import org.apache.camel.builder.RouteBuilder; |
| 32 |
|
import org.apache.camel.component.jms.JmsEndpoint; |
| 33 |
|
import org.apache.camel.component.jms.JmsExchange; |
| 34 |
|
import org.apache.camel.component.jms.JmsMessage; |
| 35 |
|
import org.apache.camel.component.pojo.PojoComponent; |
| 36 |
|
import org.apache.camel.impl.DefaultCamelContext; |
| 37 |
|
import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch; |
| 38 |
|
import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit; |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
0 |
public class JmsIntegrationTest extends TestCase { |
| 44 |
|
|
| 45 |
0 |
protected CamelContext container = new DefaultCamelContext(); |
| 46 |
|
|
| 47 |
|
public void testDummy() { |
| 48 |
0 |
} |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
public void xtestOneWayInJmsOutPojo() throws Exception { |
| 56 |
|
|
| 57 |
0 |
final CountDownLatch receivedCountDown = new CountDownLatch(1); |
| 58 |
|
|
| 59 |
|
|
| 60 |
0 |
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); |
| 61 |
0 |
container.addComponent("activemq", jmsComponentClientAcknowledge(connectionFactory)); |
| 62 |
0 |
PojoComponent component = new PojoComponent(); |
| 63 |
0 |
component.addService("listener", new MessageListener(){ |
| 64 |
0 |
public void onMessage(Message msg) { |
| 65 |
0 |
System.out.println("Received: "+msg); |
| 66 |
0 |
receivedCountDown.countDown(); |
| 67 |
0 |
} |
| 68 |
|
}); |
| 69 |
0 |
container.addComponent("default", component); |
| 70 |
|
|
| 71 |
|
|
| 72 |
0 |
container.addRoutes(new RouteBuilder() { |
| 73 |
0 |
public void configure() { |
| 74 |
0 |
from("jms:test").to("pojo:listener"); |
| 75 |
0 |
} |
| 76 |
|
}); |
| 77 |
|
|
| 78 |
0 |
container.start(); |
| 79 |
|
|
| 80 |
|
|
| 81 |
0 |
JmsEndpoint endpoint = (JmsEndpoint) container.getEndpoint("jms:test"); |
| 82 |
0 |
Producer<JmsExchange> producer = endpoint.createProducer(); |
| 83 |
0 |
JmsExchange exchange = producer.createExchange(); |
| 84 |
0 |
JmsMessage in = exchange.getIn(); |
| 85 |
0 |
in.setBody("Hello"); |
| 86 |
0 |
in.setHeader("cheese", 123); |
| 87 |
0 |
producer.process(exchange); |
| 88 |
|
|
| 89 |
|
|
| 90 |
0 |
assertTrue("The message ware received by the Pojo", receivedCountDown.await(5, TimeUnit.SECONDS)); |
| 91 |
|
|
| 92 |
|
|
| 93 |
0 |
} |
| 94 |
|
|
| 95 |
|
@Override |
| 96 |
|
protected void tearDown() throws Exception { |
| 97 |
0 |
container.stop(); |
| 98 |
|
|
| 99 |
0 |
super.tearDown(); |
| 100 |
0 |
} |
| 101 |
|
} |