org.apache.camel.ConsumerTemplate Java Examples
The following examples show how to use
org.apache.camel.ConsumerTemplate.
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: CamelSinkTaskTest.java From camel-kafka-connector with Apache License 2.0 | 6 votes |
@Test public void testOnlyBody() { Map<String, String> props = new HashMap<>(); props.put(CamelSinkConnectorConfig.TOPIC_CONF, TOPIC_NAME); props.put(CamelSinkConnectorConfig.CAMEL_SINK_URL_CONF, SEDA_URI); CamelSinkTask sinkTask = new CamelSinkTask(); sinkTask.start(props); List<SinkRecord> records = new ArrayList<SinkRecord>(); SinkRecord record = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel", 42); records.add(record); sinkTask.put(records); ConsumerTemplate consumer = sinkTask.getCms().createConsumerTemplate(); Exchange exchange = consumer.receive(SEDA_URI, RECEIVE_TIMEOUT); assertEquals("camel", exchange.getMessage().getBody()); assertEquals("test", exchange.getMessage().getHeaders().get(CamelSinkTask.KAFKA_RECORD_KEY_HEADER)); assertEquals(LoggingLevel.OFF.toString(), sinkTask.getCamelSinkConnectorConfig(props) .getString(CamelSinkConnectorConfig.CAMEL_SINK_CONTENT_LOG_LEVEL_CONF)); sinkTask.stop(); }
Example #2
Source File: CamelBridge.java From incubator-batchee with Apache License 2.0 | 6 votes |
public static Object receive(final String locator, final String endpoint, final long timeout, final Class<?> expected) { final BeanLocator.LocatorInstance<CamelTemplateLocator> locatorInstance = locator(locator); try { final ConsumerTemplate consumerTemplate = locatorInstance.getValue().findConsumerTemplate(); if (timeout > 0) { if (expected != null) { return consumerTemplate.receiveBody(endpoint, expected); } return consumerTemplate.receiveBody(endpoint); } if (expected != null) { return consumerTemplate.receiveBody(endpoint, timeout, expected); } return consumerTemplate.receiveBody(endpoint, timeout); } finally { locatorInstance.release(); } }
Example #3
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 #4
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 #5
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 #6
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 #7
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 #8
Source File: CamelSinkTaskTest.java From camel-kafka-connector with Apache License 2.0 | 6 votes |
@Test public void testUrlPrecedenceOnComponentProperty() { Map<String, String> props = new HashMap<>(); props.put(CamelSinkConnectorConfig.TOPIC_CONF, TOPIC_NAME); props.put(CamelSinkConnectorConfig.CAMEL_SINK_URL_CONF, SEDA_URI); props.put(CamelSinkConnectorConfig.CAMEL_SINK_COMPONENT_CONF, "shouldNotBeUsed"); props.put(CamelSinkTask.getCamelSinkEndpointConfigPrefix() + "endpointProperty", "shouldNotBeUsed"); props.put(CamelSinkTask.getCamelSinkPathConfigPrefix() + "pathChunk", "shouldNotBeUsed"); CamelSinkTask sinkTask = new CamelSinkTask(); sinkTask.start(props); List<SinkRecord> records = new ArrayList<SinkRecord>(); SinkRecord record = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel", 42); records.add(record); sinkTask.put(records); ConsumerTemplate consumer = sinkTask.getCms().createConsumerTemplate(); Exchange exchange = consumer.receive(SEDA_URI, RECEIVE_TIMEOUT); assertEquals("camel", exchange.getMessage().getBody()); assertEquals("test", exchange.getMessage().getHeaders().get(CamelSinkTask.KAFKA_RECORD_KEY_HEADER)); sinkTask.stop(); }
Example #9
Source File: CamelSinkTaskTest.java From camel-kafka-connector with Apache License 2.0 | 6 votes |
@Test public void testOnlyBodyUsingComponentProperty() { Map<String, String> props = new HashMap<>(); props.put(CamelSinkConnectorConfig.TOPIC_CONF, TOPIC_NAME); props.put(CamelSinkConnectorConfig.CAMEL_SINK_COMPONENT_CONF, "seda"); props.put(CamelSinkTask.getCamelSinkEndpointConfigPrefix() + "bridgeErrorHandler", "true"); props.put(CamelSinkTask.getCamelSinkPathConfigPrefix() + "name", "test"); CamelSinkTask sinkTask = new CamelSinkTask(); sinkTask.start(props); List<SinkRecord> records = new ArrayList<SinkRecord>(); SinkRecord record = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel", 42); records.add(record); sinkTask.put(records); ConsumerTemplate consumer = sinkTask.getCms().createConsumerTemplate(); Exchange exchange = consumer.receive(SEDA_URI, RECEIVE_TIMEOUT); assertEquals("camel", exchange.getMessage().getBody()); assertEquals("test", exchange.getMessage().getHeaders().get(CamelSinkTask.KAFKA_RECORD_KEY_HEADER)); assertEquals(1, sinkTask.getCms().getEndpoints() .stream().filter(e -> e.getEndpointUri().equals("seda://test?bridgeErrorHandler=true")).count()); sinkTask.stop(); }
Example #10
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 #11
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 #12
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 #13
Source File: WildFlySwarmCamelTest.java From camelinaction2 with Apache License 2.0 | 5 votes |
@Test public void testSeda() throws Exception { // send to the seda inbox queue producer.sendBody("Hello Swarm"); ConsumerTemplate consumer = camelContext.createConsumerTemplate(); // use 5 second timeout to receive the message from outbox Object body = consumer.receiveBody("seda:outbox", 5000); // expect it was the message we sent assertEquals("Hello Swarm", body); }
Example #14
Source File: CamelWriterTest.java From incubator-batchee with Apache License 2.0 | 5 votes |
@Test public void write() throws Exception { final ConsumerTemplate tpl = CamelBridge.CONTEXT.createConsumerTemplate(); final Collection<Object> received = new ArrayList<Object>(2); final ExecutorService thread = Executors.newSingleThreadExecutor(); thread.submit(new Runnable() { @Override public void run() { do { received.add(tpl.receiveBody("direct:writer")); } while (received.size() < 2); } }); thread.shutdown(); do { // starting the listener in another thread w can get timing issues so ensuring we are in the right state Thread.sleep(20); } while (DirectEndpoint.class.cast(CamelBridge.CONTEXT.getEndpoint("direct:writer")).getConsumer() == null); final JobOperator jobOperator = BatchRuntime.getJobOperator(); Batches.waitForEnd(jobOperator, jobOperator.start("camel-writer", new Properties())); thread.awaitTermination(5, TimeUnit.MINUTES); // wait end of the thread before checking received assertTrue(received.contains("1"), received.toString()); assertTrue(received.contains("2"), received.toString()); }
Example #15
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 #16
Source File: CamelStubMessages.java From spring-cloud-contract with Apache License 2.0 | 5 votes |
@Override public Message receive(String destination, long timeout, TimeUnit timeUnit) { try { ConsumerTemplate consumerTemplate = this.context.createConsumerTemplate(); Exchange exchange = consumerTemplate.receive(destination, timeUnit.toMillis(timeout)); return exchange != null ? exchange.getIn() : null; } catch (Exception e) { log.error("Exception occurred while trying to read a message from " + " a channel with name [" + destination + "]", e); throw new IllegalStateException(e); } }
Example #17
Source File: CamelSinkTaskTest.java From camel-kafka-connector with Apache License 2.0 | 5 votes |
@Test public void testAggregationBodyAndTimeout() throws InterruptedException { Map<String, String> props = new HashMap<>(); props.put(CamelSinkConnectorConfig.TOPIC_CONF, TOPIC_NAME); props.put(CamelSinkConnectorConfig.CAMEL_SINK_URL_CONF, SEDA_URI); props.put(CamelSinkConnectorConfig.CAMEL_SINK_AGGREGATE_CONF, "#class:org.apache.camel.kafkaconnector.utils.SampleAggregator"); props.put(CamelSinkConnectorConfig.CAMEL_SINK_AGGREGATE_SIZE_CONF, "5"); props.put(CamelSinkConnectorConfig.CAMEL_SINK_AGGREGATE_TIMEOUT_CONF, "100"); CamelSinkTask sinkTask = new CamelSinkTask(); sinkTask.start(props); List<SinkRecord> records = new ArrayList<SinkRecord>(); SinkRecord record = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel", 42); SinkRecord record1 = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel1", 42); SinkRecord record2 = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel2", 42); SinkRecord record3 = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel3", 42); SinkRecord record4 = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel4", 42); SinkRecord record5 = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel5", 42); records.add(record); records.add(record1); records.add(record2); records.add(record3); records.add(record4); records.add(record5); sinkTask.put(records); ConsumerTemplate consumer = sinkTask.getCms().createConsumerTemplate(); Exchange exchange = consumer.receive(SEDA_URI, RECEIVE_TIMEOUT); assertEquals("camel camel1 camel2 camel3 camel4", exchange.getMessage().getBody()); assertEquals("test", exchange.getMessage().getHeaders().get(CamelSinkTask.KAFKA_RECORD_KEY_HEADER)); assertEquals(LoggingLevel.OFF.toString(), sinkTask.getCamelSinkConnectorConfig(props) .getString(CamelSinkConnectorConfig.CAMEL_SINK_CONTENT_LOG_LEVEL_CONF)); sinkTask.stop(); }
Example #18
Source File: CamelSinkTaskTest.java From camel-kafka-connector with Apache License 2.0 | 5 votes |
@Test public void testAggregationBody() { Map<String, String> props = new HashMap<>(); props.put(CamelSinkConnectorConfig.TOPIC_CONF, TOPIC_NAME); props.put(CamelSinkConnectorConfig.CAMEL_SINK_URL_CONF, SEDA_URI); props.put(CamelSinkConnectorConfig.CAMEL_SINK_AGGREGATE_CONF, "#class:org.apache.camel.kafkaconnector.utils.SampleAggregator"); props.put(CamelSinkConnectorConfig.CAMEL_SINK_AGGREGATE_SIZE_CONF, "5"); CamelSinkTask sinkTask = new CamelSinkTask(); sinkTask.start(props); List<SinkRecord> records = new ArrayList<SinkRecord>(); SinkRecord record = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel", 42); SinkRecord record1 = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel1", 42); SinkRecord record2 = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel2", 42); SinkRecord record3 = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel3", 42); SinkRecord record4 = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel4", 42); SinkRecord record5 = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel5", 42); records.add(record); records.add(record1); records.add(record2); records.add(record3); records.add(record4); records.add(record5); sinkTask.put(records); ConsumerTemplate consumer = sinkTask.getCms().createConsumerTemplate(); Exchange exchange = consumer.receive(SEDA_URI, RECEIVE_TIMEOUT); assertEquals("camel camel1 camel2 camel3 camel4", exchange.getMessage().getBody()); assertEquals("test", exchange.getMessage().getHeaders().get(CamelSinkTask.KAFKA_RECORD_KEY_HEADER)); assertEquals(LoggingLevel.OFF.toString(), sinkTask.getCamelSinkConnectorConfig(props) .getString(CamelSinkConnectorConfig.CAMEL_SINK_CONTENT_LOG_LEVEL_CONF)); sinkTask.stop(); }
Example #19
Source File: CamelSinkTaskTest.java From camel-kafka-connector with Apache License 2.0 | 5 votes |
@Test public void testOnlyBodyUsingMultipleComponentProperties() { Map<String, String> props = new HashMap<>(); props.put(CamelSinkConnectorConfig.TOPIC_CONF, TOPIC_NAME); props.put(CamelSinkConnectorConfig.CAMEL_SINK_COMPONENT_CONF, "seda"); props.put(CamelSinkTask.getCamelSinkEndpointConfigPrefix() + "bridgeErrorHandler", "true"); props.put(CamelSinkTask.getCamelSinkEndpointConfigPrefix() + "size", "50"); props.put(CamelSinkTask.getCamelSinkPathConfigPrefix() + "name", "test"); CamelSinkTask sinkTask = new CamelSinkTask(); sinkTask.start(props); List<SinkRecord> records = new ArrayList<SinkRecord>(); SinkRecord record = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel", 42); records.add(record); sinkTask.put(records); ConsumerTemplate consumer = sinkTask.getCms().createConsumerTemplate(); Exchange exchange = consumer.receive(SEDA_URI, RECEIVE_TIMEOUT); assertEquals("camel", exchange.getMessage().getBody()); assertEquals("test", exchange.getMessage().getHeaders().get(CamelSinkTask.KAFKA_RECORD_KEY_HEADER)); assertEquals(1, sinkTask.getCms().getEndpoints() .stream().filter(e -> e.getEndpointUri().equals("seda://test?bridgeErrorHandler=true&size=50")).count()); sinkTask.stop(); }
Example #20
Source File: CamelSpringBootTemplateShutdownTest.java From camel-spring-boot with Apache License 2.0 | 5 votes |
@Before public void setupApplicationContext() { applicationContext = new AnnotationConfigApplicationContext(CamelAutoConfiguration.class); camelContext = applicationContext.getBean(CamelContext.class); consumerTemplate = applicationContext.getBean(ConsumerTemplate.class); producerTemplate = applicationContext.getBean(ProducerTemplate.class); fluentProducerTemplate = applicationContext.getBean(FluentProducerTemplate.class); }
Example #21
Source File: CamelSinkTaskTest.java From camel-kafka-connector with Apache License 2.0 | 4 votes |
@Test public void testBodyAndPropertiesHeadersListMixed() { Map<String, String> props = new HashMap<>(); props.put(CamelSinkConnectorConfig.TOPIC_CONF, TOPIC_NAME); props.put(CamelSinkConnectorConfig.CAMEL_SINK_URL_CONF, SEDA_URI); CamelSinkTask sinkTask = new CamelSinkTask(); sinkTask.start(props); Byte myByte = new Byte("100"); Float myFloat = new Float("100"); Short myShort = new Short("100"); Double myDouble = new Double("100"); int myInteger = 100; Long myLong = new Long("100"); List<String> list = new ArrayList<String>(); list.add("a"); List<Integer> list1 = new ArrayList<Integer>(); list1.add(1); List<SinkRecord> records = new ArrayList<SinkRecord>(); SinkRecord record = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel", 42); record.headers().addBoolean("CamelPropertyMyBoolean", true); record.headers().addByte("CamelPropertyMyByte", myByte); record.headers().addFloat("CamelPropertyMyFloat", myFloat); record.headers().addShort("CamelPropertyMyShort", myShort); record.headers().addDouble("CamelPropertyMyDouble", myDouble); record.headers().addInt("CamelPropertyMyInteger", myInteger); record.headers().addLong("CamelPropertyMyLong", myLong); record.headers().addBoolean("CamelHeaderMyBoolean", true); record.headers().addByte("CamelHeaderMyByte", myByte); record.headers().addFloat("CamelHeaderMyFloat", myFloat); record.headers().addShort("CamelHeaderMyShort", myShort); record.headers().addDouble("CamelHeaderMyDouble", myDouble); record.headers().addInt("CamelHeaderMyInteger", myInteger); record.headers().addLong("CamelHeaderMyLong", myLong); record.headers().addList("CamelHeaderMyList", list, SchemaBuilder.array(Schema.STRING_SCHEMA)); record.headers().addList("CamelHeaderMyList1", list1, SchemaBuilder.array(Schema.INT64_SCHEMA)); record.headers().addList("CamelPropertyMyList", list, SchemaBuilder.array(Schema.STRING_SCHEMA)); record.headers().addList("CamelPropertyMyList1", list1, SchemaBuilder.array(Schema.INT64_SCHEMA)); records.add(record); sinkTask.put(records); ConsumerTemplate consumer = sinkTask.getCms().createConsumerTemplate(); Exchange exchange = consumer.receive(SEDA_URI, RECEIVE_TIMEOUT); assertEquals("camel", exchange.getMessage().getBody()); assertEquals("test", exchange.getMessage().getHeaders().get(CamelSinkTask.KAFKA_RECORD_KEY_HEADER)); assertTrue((boolean) exchange.getProperties().get("MyBoolean")); assertEquals(myByte, (Byte) exchange.getProperties().get("MyByte")); assertEquals(myFloat, (Float) exchange.getProperties().get("MyFloat")); assertEquals(myShort, (Short) exchange.getProperties().get("MyShort")); assertEquals(myDouble, (Double) exchange.getProperties().get("MyDouble")); assertEquals(myInteger, exchange.getProperties().get("MyInteger")); assertEquals(myLong, (Long) exchange.getProperties().get("MyLong")); assertEquals(list, exchange.getProperties().get("MyList")); assertEquals(list1, exchange.getProperties().get("MyList1")); assertTrue(exchange.getIn().getHeader("MyBoolean", Boolean.class)); assertEquals(myByte, exchange.getIn().getHeader("MyByte", Byte.class)); assertEquals(myFloat, exchange.getIn().getHeader("MyFloat", Float.class)); assertEquals(myShort, exchange.getIn().getHeader("MyShort", Short.class)); assertEquals(myDouble, exchange.getIn().getHeader("MyDouble", Double.class)); assertEquals(myInteger, exchange.getIn().getHeader("MyInteger")); assertEquals(myLong, exchange.getIn().getHeader("MyLong", Long.class)); assertEquals(list, exchange.getIn().getHeader("MyList", List.class)); assertEquals(list1, exchange.getIn().getHeader("MyList1", List.class)); sinkTask.stop(); }
Example #22
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(); } }
Example #23
Source File: CamelSinkTaskTest.java From camel-kafka-connector with Apache License 2.0 | 4 votes |
@Test public void testBodyAndHeaders() { Map<String, String> props = new HashMap<>(); props.put(CamelSinkConnectorConfig.TOPIC_CONF, TOPIC_NAME); props.put(CamelSinkConnectorConfig.CAMEL_SINK_URL_CONF, SEDA_URI); CamelSinkTask sinkTask = new CamelSinkTask(); sinkTask.start(props); Byte myByte = new Byte("100"); Float myFloat = new Float("100"); Short myShort = new Short("100"); Double myDouble = new Double("100"); int myInteger = 100; Long myLong = new Long("100"); List<SinkRecord> records = new ArrayList<SinkRecord>(); SinkRecord record = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel", 42); record.headers().addBoolean("CamelHeaderMyBoolean", true); record.headers().addByte("CamelHeaderMyByte", myByte); record.headers().addFloat("CamelHeaderMyFloat", myFloat); record.headers().addShort("CamelHeaderMyShort", myShort); record.headers().addDouble("CamelHeaderMyDouble", myDouble); record.headers().addInt("CamelHeaderMyInteger", myInteger); record.headers().addLong("CamelHeaderMyLong", myLong); records.add(record); sinkTask.put(records); ConsumerTemplate consumer = sinkTask.getCms().createConsumerTemplate(); Exchange exchange = consumer.receive(SEDA_URI, RECEIVE_TIMEOUT); assertEquals("camel", exchange.getMessage().getBody()); assertEquals("test", exchange.getMessage().getHeaders().get(CamelSinkTask.KAFKA_RECORD_KEY_HEADER)); assertTrue(exchange.getIn().getHeader("MyBoolean", Boolean.class)); assertEquals(myByte, exchange.getIn().getHeader("MyByte", Byte.class)); assertEquals(myFloat, exchange.getIn().getHeader("MyFloat", Float.class)); assertEquals(myShort, exchange.getIn().getHeader("MyShort", Short.class)); assertEquals(myDouble, exchange.getIn().getHeader("MyDouble", Double.class)); assertEquals(myInteger, exchange.getIn().getHeader("MyInteger")); assertEquals(myLong, exchange.getIn().getHeader("MyLong", Long.class)); sinkTask.stop(); }
Example #24
Source File: CamelBridge.java From incubator-batchee with Apache License 2.0 | 4 votes |
@Override public ConsumerTemplate findConsumerTemplate() { return CONSUMER_TEMPLATE; }
Example #25
Source File: CamelSinkTaskTest.java From camel-kafka-connector with Apache License 2.0 | 4 votes |
@Test public void testBodyAndProperties() { Map<String, String> props = new HashMap<>(); props.put(CamelSinkConnectorConfig.TOPIC_CONF, TOPIC_NAME); props.put(CamelSinkConnectorConfig.CAMEL_SINK_URL_CONF, SEDA_URI); CamelSinkTask sinkTask = new CamelSinkTask(); sinkTask.start(props); Byte myByte = new Byte("100"); Float myFloat = new Float("100"); Short myShort = new Short("100"); Double myDouble = new Double("100"); int myInteger = 100; Long myLong = new Long("100"); List<SinkRecord> records = new ArrayList<SinkRecord>(); SinkRecord record = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel", 42); record.headers().addBoolean("CamelPropertyMyBoolean", true); record.headers().addByte("CamelPropertyMyByte", myByte); record.headers().addFloat("CamelPropertyMyFloat", myFloat); record.headers().addShort("CamelPropertyMyShort", myShort); record.headers().addDouble("CamelPropertyMyDouble", myDouble); record.headers().addInt("CamelPropertyMyInteger", myInteger); record.headers().addLong("CamelPropertyMyLong", myLong); records.add(record); sinkTask.put(records); ConsumerTemplate consumer = sinkTask.getCms().createConsumerTemplate(); Exchange exchange = consumer.receive(SEDA_URI, RECEIVE_TIMEOUT); assertEquals("camel", exchange.getMessage().getBody()); assertEquals("test", exchange.getMessage().getHeaders().get(CamelSinkTask.KAFKA_RECORD_KEY_HEADER)); assertTrue((boolean) exchange.getProperties().get("MyBoolean")); assertEquals(myByte, (Byte) exchange.getProperties().get("MyByte")); assertEquals(myFloat, (Float) exchange.getProperties().get("MyFloat")); assertEquals(myShort, (Short) exchange.getProperties().get("MyShort")); assertEquals(myDouble, (Double) exchange.getProperties().get("MyDouble")); assertEquals(myInteger, exchange.getProperties().get("MyInteger")); assertEquals(myLong, (Long) exchange.getProperties().get("MyLong")); sinkTask.stop(); }
Example #26
Source File: CamelSinkTaskTest.java From camel-kafka-connector with Apache License 2.0 | 4 votes |
@Test public void testBodyAndPropertiesHeadersMixed() { Map<String, String> props = new HashMap<>(); props.put(CamelSinkConnectorConfig.TOPIC_CONF, TOPIC_NAME); props.put(CamelSinkConnectorConfig.CAMEL_SINK_URL_CONF, SEDA_URI); CamelSinkTask sinkTask = new CamelSinkTask(); sinkTask.start(props); Byte myByte = new Byte("100"); Float myFloat = new Float("100"); Short myShort = new Short("100"); Double myDouble = new Double("100"); int myInteger = 100; Long myLong = new Long("100"); List<SinkRecord> records = new ArrayList<SinkRecord>(); SinkRecord record = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel", 42); record.headers().addBoolean("CamelPropertyMyBoolean", true); record.headers().addByte("CamelPropertyMyByte", myByte); record.headers().addFloat("CamelPropertyMyFloat", myFloat); record.headers().addShort("CamelPropertyMyShort", myShort); record.headers().addDouble("CamelPropertyMyDouble", myDouble); record.headers().addInt("CamelPropertyMyInteger", myInteger); record.headers().addLong("CamelPropertyMyLong", myLong); record.headers().addBoolean("CamelHeaderMyBoolean", true); record.headers().addByte("CamelHeaderMyByte", myByte); record.headers().addFloat("CamelHeaderMyFloat", myFloat); record.headers().addShort("CamelHeaderMyShort", myShort); record.headers().addDouble("CamelHeaderMyDouble", myDouble); record.headers().addInt("CamelHeaderMyInteger", myInteger); record.headers().addLong("CamelHeaderMyLong", myLong); records.add(record); sinkTask.put(records); ConsumerTemplate consumer = sinkTask.getCms().createConsumerTemplate(); Exchange exchange = consumer.receive(SEDA_URI, RECEIVE_TIMEOUT); assertEquals("camel", exchange.getMessage().getBody()); assertEquals("test", exchange.getMessage().getHeaders().get(CamelSinkTask.KAFKA_RECORD_KEY_HEADER)); assertTrue((boolean) exchange.getProperties().get("MyBoolean")); assertEquals(myByte, (Byte) exchange.getProperties().get("MyByte")); assertEquals(myFloat, (Float) exchange.getProperties().get("MyFloat")); assertEquals(myShort, (Short) exchange.getProperties().get("MyShort")); assertEquals(myDouble, (Double) exchange.getProperties().get("MyDouble")); assertEquals(myInteger, exchange.getProperties().get("MyInteger")); assertEquals(myLong, (Long) exchange.getProperties().get("MyLong")); assertTrue(exchange.getIn().getHeader("MyBoolean", Boolean.class)); assertEquals(myByte, exchange.getIn().getHeader("MyByte", Byte.class)); assertEquals(myFloat, exchange.getIn().getHeader("MyFloat", Float.class)); assertEquals(myShort, exchange.getIn().getHeader("MyShort", Short.class)); assertEquals(myDouble, exchange.getIn().getHeader("MyDouble", Double.class)); assertEquals(myInteger, exchange.getIn().getHeader("MyInteger")); assertEquals(myLong, exchange.getIn().getHeader("MyLong", Long.class)); sinkTask.stop(); }
Example #27
Source File: CamelSinkTaskTest.java From camel-kafka-connector with Apache License 2.0 | 4 votes |
@Test public void testBodyAndHeadersMap() { Map<String, String> props = new HashMap<>(); props.put(CamelSinkConnectorConfig.TOPIC_CONF, TOPIC_NAME); props.put(CamelSinkConnectorConfig.CAMEL_SINK_URL_CONF, SEDA_URI); CamelSinkTask sinkTask = new CamelSinkTask(); sinkTask.start(props); Byte myByte = new Byte("100"); Float myFloat = new Float("100"); Short myShort = new Short("100"); Double myDouble = new Double("100"); int myInteger = 100; Long myLong = new Long("100"); HashMap<String, String> map = new HashMap<String, String>(); map.put("a", "a"); HashMap<Integer, String> map1 = new HashMap<Integer, String>(); map1.put(1, "a"); HashMap<Integer, Integer> map2 = new HashMap<Integer, Integer>(); map2.put(1, 1); List<SinkRecord> records = new ArrayList<SinkRecord>(); SinkRecord record = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel", 42); record.headers().addBoolean("CamelHeaderMyBoolean", true); record.headers().addByte("CamelHeaderMyByte", myByte); record.headers().addFloat("CamelHeaderMyFloat", myFloat); record.headers().addShort("CamelHeaderMyShort", myShort); record.headers().addDouble("CamelHeaderMyDouble", myDouble); record.headers().addInt("CamelHeaderMyInteger", myInteger); record.headers().addLong("CamelHeaderMyLong", myLong); record.headers().addMap("CamelHeaderMyMap", map, SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.STRING_SCHEMA)); record.headers().addMap("CamelHeaderMyMap1", map1, SchemaBuilder.map(Schema.INT64_SCHEMA, Schema.STRING_SCHEMA)); record.headers().addMap("CamelHeaderMyMap2", map2, SchemaBuilder.map(Schema.INT64_SCHEMA, Schema.INT64_SCHEMA)); records.add(record); sinkTask.put(records); ConsumerTemplate consumer = sinkTask.getCms().createConsumerTemplate(); Exchange exchange = consumer.receive(SEDA_URI, RECEIVE_TIMEOUT); assertEquals("camel", exchange.getMessage().getBody()); assertEquals("test", exchange.getMessage().getHeaders().get(CamelSinkTask.KAFKA_RECORD_KEY_HEADER)); assertTrue(exchange.getIn().getHeader("MyBoolean", Boolean.class)); assertEquals(myByte, exchange.getIn().getHeader("MyByte", Byte.class)); assertEquals(myFloat, exchange.getIn().getHeader("MyFloat", Float.class)); assertEquals(myShort, exchange.getIn().getHeader("MyShort", Short.class)); assertEquals(myDouble, exchange.getIn().getHeader("MyDouble", Double.class)); assertEquals(myInteger, exchange.getIn().getHeader("MyInteger")); assertEquals(myLong, exchange.getIn().getHeader("MyLong", Long.class)); assertEquals(map, exchange.getIn().getHeader("MyMap", Map.class)); assertEquals(map1, exchange.getIn().getHeader("MyMap1", Map.class)); assertEquals(map2, exchange.getIn().getHeader("MyMap2", Map.class)); sinkTask.stop(); }
Example #28
Source File: CamelSinkTaskTest.java From camel-kafka-connector with Apache License 2.0 | 4 votes |
@Test public void testBodyAndPropertiesHeadersMapMixed() { Map<String, String> props = new HashMap<>(); props.put(CamelSinkConnectorConfig.TOPIC_CONF, TOPIC_NAME); props.put(CamelSinkConnectorConfig.CAMEL_SINK_URL_CONF, SEDA_URI); CamelSinkTask sinkTask = new CamelSinkTask(); sinkTask.start(props); Byte myByte = new Byte("100"); Float myFloat = new Float("100"); Short myShort = new Short("100"); Double myDouble = new Double("100"); int myInteger = 100; Long myLong = new Long("100"); HashMap<String, String> map = new HashMap<String, String>(); map.put("a", "a"); HashMap<Integer, String> map1 = new HashMap<Integer, String>(); map1.put(1, "a"); HashMap<Integer, Integer> map2 = new HashMap<Integer, Integer>(); map2.put(1, 1); List<SinkRecord> records = new ArrayList<SinkRecord>(); SinkRecord record = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel", 42); record.headers().addBoolean("CamelPropertyMyBoolean", true); record.headers().addByte("CamelPropertyMyByte", myByte); record.headers().addFloat("CamelPropertyMyFloat", myFloat); record.headers().addShort("CamelPropertyMyShort", myShort); record.headers().addDouble("CamelPropertyMyDouble", myDouble); record.headers().addInt("CamelPropertyMyInteger", myInteger); record.headers().addLong("CamelPropertyMyLong", myLong); record.headers().addMap("CamelPropertyMyMap", map, SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.STRING_SCHEMA)); record.headers().addMap("CamelPropertyMyMap1", map1, SchemaBuilder.map(Schema.INT64_SCHEMA, Schema.STRING_SCHEMA)); record.headers().addMap("CamelPropertyMyMap2", map2, SchemaBuilder.map(Schema.INT64_SCHEMA, Schema.INT64_SCHEMA)); record.headers().addBoolean("CamelHeaderMyBoolean", true); record.headers().addByte("CamelHeaderMyByte", myByte); record.headers().addFloat("CamelHeaderMyFloat", myFloat); record.headers().addShort("CamelHeaderMyShort", myShort); record.headers().addDouble("CamelHeaderMyDouble", myDouble); record.headers().addInt("CamelHeaderMyInteger", myInteger); record.headers().addLong("CamelHeaderMyLong", myLong); record.headers().addMap("CamelHeaderMyMap", map, SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.STRING_SCHEMA)); record.headers().addMap("CamelHeaderMyMap1", map1, SchemaBuilder.map(Schema.INT64_SCHEMA, Schema.STRING_SCHEMA)); record.headers().addMap("CamelHeaderMyMap2", map2, SchemaBuilder.map(Schema.INT64_SCHEMA, Schema.INT64_SCHEMA)); records.add(record); sinkTask.put(records); ConsumerTemplate consumer = sinkTask.getCms().createConsumerTemplate(); Exchange exchange = consumer.receive(SEDA_URI, RECEIVE_TIMEOUT); assertEquals("camel", exchange.getMessage().getBody()); assertEquals("test", exchange.getMessage().getHeaders().get(CamelSinkTask.KAFKA_RECORD_KEY_HEADER)); assertTrue((boolean) exchange.getProperties().get("MyBoolean")); assertEquals(myByte, (Byte) exchange.getProperties().get("MyByte")); assertEquals(myFloat, (Float) exchange.getProperties().get("MyFloat")); assertEquals(myShort, (Short) exchange.getProperties().get("MyShort")); assertEquals(myDouble, (Double) exchange.getProperties().get("MyDouble")); assertEquals(myInteger, exchange.getProperties().get("MyInteger")); assertEquals(myLong, (Long) exchange.getProperties().get("MyLong")); assertEquals(map, exchange.getProperties().get("MyMap")); assertEquals(map1, exchange.getProperties().get("MyMap1")); assertEquals(map2, exchange.getProperties().get("MyMap2")); assertTrue(exchange.getIn().getHeader("MyBoolean", Boolean.class)); assertEquals(myByte, exchange.getIn().getHeader("MyByte", Byte.class)); assertEquals(myFloat, exchange.getIn().getHeader("MyFloat", Float.class)); assertEquals(myShort, exchange.getIn().getHeader("MyShort", Short.class)); assertEquals(myDouble, exchange.getIn().getHeader("MyDouble", Double.class)); assertEquals(myInteger, exchange.getIn().getHeader("MyInteger")); assertEquals(myLong, exchange.getIn().getHeader("MyLong", Long.class)); assertEquals(map, exchange.getIn().getHeader("MyMap", Map.class)); assertEquals(map1, exchange.getIn().getHeader("MyMap1", Map.class)); assertEquals(map2, exchange.getIn().getHeader("MyMap2", Map.class)); sinkTask.stop(); }
Example #29
Source File: CamelSinkTaskTest.java From camel-kafka-connector with Apache License 2.0 | 4 votes |
@Test public void testBodyAndHeadersList() { Map<String, String> props = new HashMap<>(); props.put(CamelSinkConnectorConfig.TOPIC_CONF, TOPIC_NAME); props.put(CamelSinkConnectorConfig.CAMEL_SINK_URL_CONF, SEDA_URI); CamelSinkTask sinkTask = new CamelSinkTask(); sinkTask.start(props); Byte myByte = new Byte("100"); Float myFloat = new Float("100"); Short myShort = new Short("100"); Double myDouble = new Double("100"); int myInteger = 100; Long myLong = new Long("100"); List<String> list = new ArrayList<String>(); list.add("a"); List<Integer> list1 = new ArrayList<Integer>(); list1.add(1); List<SinkRecord> records = new ArrayList<SinkRecord>(); SinkRecord record = new SinkRecord(TOPIC_NAME, 1, null, "test", null, "camel", 42); record.headers().addBoolean("CamelHeaderMyBoolean", true); record.headers().addByte("CamelHeaderMyByte", myByte); record.headers().addFloat("CamelHeaderMyFloat", myFloat); record.headers().addShort("CamelHeaderMyShort", myShort); record.headers().addDouble("CamelHeaderMyDouble", myDouble); record.headers().addInt("CamelHeaderMyInteger", myInteger); record.headers().addLong("CamelHeaderMyLong", myLong); record.headers().addList("CamelHeaderMyList", list, SchemaBuilder.array(Schema.STRING_SCHEMA)); record.headers().addList("CamelHeaderMyList1", list1, SchemaBuilder.array(Schema.INT64_SCHEMA)); records.add(record); sinkTask.put(records); ConsumerTemplate consumer = sinkTask.getCms().createConsumerTemplate(); Exchange exchange = consumer.receive(SEDA_URI, RECEIVE_TIMEOUT); assertEquals("camel", exchange.getMessage().getBody()); assertEquals("test", exchange.getMessage().getHeaders().get(CamelSinkTask.KAFKA_RECORD_KEY_HEADER)); assertTrue(exchange.getIn().getHeader("MyBoolean", Boolean.class)); assertEquals(myByte, exchange.getIn().getHeader("MyByte", Byte.class)); assertEquals(myFloat, exchange.getIn().getHeader("MyFloat", Float.class)); assertEquals(myShort, exchange.getIn().getHeader("MyShort", Short.class)); assertEquals(myDouble, exchange.getIn().getHeader("MyDouble", Double.class)); assertEquals(myInteger, exchange.getIn().getHeader("MyInteger")); assertEquals(myLong, exchange.getIn().getHeader("MyLong", Long.class)); assertEquals(list, exchange.getIn().getHeader("MyList", List.class)); assertEquals(list1, exchange.getIn().getHeader("MyList1", List.class)); sinkTask.stop(); }
Example #30
Source File: CamelProducers.java From camel-quarkus with Apache License 2.0 | 4 votes |
@Produces ConsumerTemplate camelConsumerTemplate() { return this.context.createConsumerTemplate(); }