Java Code Examples for org.apache.camel.CamelContext#createConsumerTemplate()
The following examples show how to use
org.apache.camel.CamelContext#createConsumerTemplate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HazelcastMapProducerIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testGet() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.start(); try { ProducerTemplate template = camelctx.createProducerTemplate(); Mockito.when(map.get("4711")).thenReturn("my-foo"); template.sendBodyAndHeader("direct:get", null, HazelcastConstants.OBJECT_ID, "4711"); ConsumerTemplate consumer = camelctx.createConsumerTemplate(); String body = consumer.receiveBody("seda:out", 5000, String.class); Mockito.verify(map).get("4711"); Assert.assertEquals("my-foo", body); } finally { camelctx.close(); } }
Example 2
Source File: HazelcastMapProducerIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testGetAllEmptySet() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.start(); try { Set<Object> l = new HashSet<Object>(); Map t = new HashMap(); t.put("key1", "value1"); t.put("key2", "value2"); t.put("key3", "value3"); Mockito.when(map.getAll(Mockito.anySet())).thenReturn(t); ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBodyAndHeader("direct:getAll", null, HazelcastConstants.OBJECT_ID, l); ConsumerTemplate consumer = camelctx.createConsumerTemplate(); String body = consumer.receiveBody("seda:out", 5000, String.class); Mockito.verify(map).getAll(l); Assert.assertTrue(body.contains("key1=value1")); Assert.assertTrue(body.contains("key2=value2")); Assert.assertTrue(body.contains("key3=value3")); } finally { camelctx.close(); } }
Example 3
Source File: HazelcastMapProducerIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testGetAllOnlyOneKey() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.start(); try { Set<Object> l = new HashSet<Object>(); l.add("key1"); Map t = new HashMap(); t.put("key1", "value1"); Mockito.when(map.getAll(l)).thenReturn(t); ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBodyAndHeader("direct:getAll", null, HazelcastConstants.OBJECT_ID, l); ConsumerTemplate consumer = camelctx.createConsumerTemplate(); String body = consumer.receiveBody("seda:out", 5000, String.class); Mockito.verify(map).getAll(l); Assert.assertEquals("{key1=value1}", body); } finally { camelctx.close(); } }
Example 4
Source File: HazelcastMapProducerIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testQuery() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.start(); try { String sql = "bar > 1000"; Mockito.when(map.values(Mockito.any(SqlPredicate.class))).thenReturn(Arrays.<Object>asList(new Dummy("beta", 2000), new Dummy("gamma", 3000))); ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBodyAndHeader("direct:queue", null, HazelcastConstants.QUERY, sql); Mockito.verify(map).values(Mockito.any(SqlPredicate.class)); ConsumerTemplate consumer = camelctx.createConsumerTemplate(); Collection<?> b1 = consumer.receiveBody("seda:out", 5000, Collection.class); Assert.assertNotNull(b1); Assert.assertEquals(2, b1.size()); } finally { camelctx.close(); } }
Example 5
Source File: HazelcastMapProducerIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testEmptyQuery() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.start(); try { Mockito.when(map.values()).thenReturn(Arrays.<Object>asList(new Dummy("beta", 2000), new Dummy("gamma", 3000), new Dummy("delta", 4000))); ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBody("direct:queue", null); Mockito. verify(map).values(); ConsumerTemplate consumer = camelctx.createConsumerTemplate(); Collection<?> b1 = consumer.receiveBody("seda:out", 5000, Collection.class); Assert.assertNotNull(b1); Assert.assertEquals(3, b1.size()); } finally { camelctx.close(); } }
Example 6
Source File: HazelcastMapProducerIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testContainsKey() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.start(); try { Mockito.when(map.containsKey("testOk")).thenReturn(true); Mockito.when(map.containsKey("testKo")).thenReturn(false); ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBodyAndHeader("direct:containsKey", null, HazelcastConstants.OBJECT_ID, "testOk"); ConsumerTemplate consumer = camelctx.createConsumerTemplate(); Boolean body = consumer.receiveBody("seda:out", 5000, Boolean.class); Mockito.verify(map).containsKey("testOk"); Assert.assertEquals(true, body); template.sendBodyAndHeader("direct:containsKey", null, HazelcastConstants.OBJECT_ID, "testKo"); body = consumer.receiveBody("seda:out", 5000, Boolean.class); Mockito.verify(map).containsKey("testKo"); Assert.assertEquals(false, body); } finally { camelctx.close(); } }
Example 7
Source File: HazelcastMapProducerIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testContainsValue() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.start(); try { Mockito.when(map.containsValue("testOk")).thenReturn(true); Mockito.when(map.containsValue("testKo")).thenReturn(false); ProducerTemplate template = camelctx.createProducerTemplate(); template.sendBody("direct:containsValue", "testOk"); ConsumerTemplate consumer = camelctx.createConsumerTemplate(); Boolean body = consumer.receiveBody("seda:out", 5000, Boolean.class); Mockito.verify(map).containsValue("testOk"); Assert.assertEquals(true, body); template.sendBody("direct:containsValue", "testKo"); body = consumer.receiveBody("seda:out", 5000, Boolean.class); Mockito.verify(map).containsValue("testKo"); Assert.assertEquals(false, body); } finally { camelctx.close(); } }
Example 8
Source File: CassandraIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testConsumeAll() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("cql://localhost/camel_ks?cql=" + CQL).to("seda:end"); } }); camelctx.start(); try { ConsumerTemplate consumer = camelctx.createConsumerTemplate(); List<?> result = consumer.receiveBody("seda:end", 3000, List.class); Assert.assertNotNull("Result not null", result); Assert.assertEquals("Two records selected", 2, result.size()); } finally { camelctx.close(); } }
Example 9
Source File: JMXIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testMonitorMBeanAttribute() throws Exception { CamelContext context = contextRegistry.getCamelContext("jmx-context-1"); Assert.assertNotNull("jmx-context-1 not null", context); final String routeName = context.getRoutes().get(0).getId(); MBeanServer server = ManagementFactory.getPlatformMBeanServer(); ObjectName onameAll = ObjectNameFactory.create("org.apache.camel:*"); Set<ObjectInstance> mbeans = server.queryMBeans(onameAll, null); System.out.println(">>>>>>>>> MBeans: " + mbeans.size()); mbeans.forEach(mb -> System.out.println(mb.getObjectName())); CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("jmx:platform?format=raw&objectDomain=org.apache.camel&key.context=jmx-context-1&key.type=routes&key.name=\"" + routeName + "\"" + "&monitorType=counter&observedAttribute=ExchangesTotal&granularityPeriod=500"). to("direct:end"); } }); camelctx.start(); try { ConsumerTemplate consumer = camelctx.createConsumerTemplate(); MonitorNotification notifcation = consumer.receiveBody("direct:end", MonitorNotification.class); Assert.assertEquals("ExchangesTotal", notifcation.getObservedAttribute()); } finally { camelctx.close(); } }
Example 10
Source File: CamelConsumerTemplate.java From hazelcastmq with Apache License 2.0 | 4 votes |
@Override public void start() throws Exception { // Create a Hazelcast instance. Config config = new Config(); config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false); HazelcastInstance hazelcast = Hazelcast.newHazelcastInstance(config); try { // Create the HazelcaseMQ instance. HazelcastMQConfig mqConfig = new HazelcastMQConfig(); mqConfig.setHazelcastInstance(hazelcast); HazelcastMQInstance mqInstance = HazelcastMQ .newHazelcastMQInstance(mqConfig); // Create the camel component. HazelcastMQCamelConfig mqCamelConfig = new HazelcastMQCamelConfig(); mqCamelConfig.setHazelcastMQInstance(mqInstance); HazelcastMQCamelComponent mqCamelComponent = new HazelcastMQCamelComponent(); mqCamelComponent.setConfiguration(mqCamelConfig); // Create the Camel context. This could be done via a Spring XML file. CamelContext camelContext = new DefaultCamelContext(); camelContext.addComponent("hazelcastmq", mqCamelComponent); camelContext.start(); // Send a message to a queue. try (HazelcastMQContext mqContext = mqInstance.createContext()) { HazelcastMQProducer mqProducer = mqContext.createProducer(); mqProducer.send("/queue/primo.test", "Hello World!"); } // Create a Camel polling consumer. ConsumerTemplate consumerTemplate = camelContext.createConsumerTemplate(); String body = consumerTemplate. receiveBody("hazelcastmq:queue:primo.test", 2000, String.class); if (body == null) { log.warn("Did not get expected message!"); } else { log.info("Got message on queue: " + body); } consumerTemplate.stop(); camelContext.stop(); } finally { // Shutdown Hazelcast. hazelcast.getLifecycleService().shutdown(); } }