Java Code Examples for org.apache.camel.PollingConsumer#start()
The following examples show how to use
org.apache.camel.PollingConsumer#start() .
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: AbstractCamelProvisioningManager.java From syncope with Apache License 2.0 | 6 votes |
protected PollingConsumer getConsumer(final String uri) { if (!knownURIs.contains(uri)) { knownURIs.add(uri); Endpoint endpoint = contextFactory.getCamelContext().getEndpoint(uri); PollingConsumer pollingConsumer = null; try { pollingConsumer = endpoint.createPollingConsumer(); consumerMap.put(uri, pollingConsumer); pollingConsumer.start(); } catch (Exception ex) { LOG.error("Unexpected error in Consumer creation ", ex); } return pollingConsumer; } else { return consumerMap.get(uri); } }
Example 2
Source File: AhcWSSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testAsyncWssRoute() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("ahc-wss:" + WEBSOCKET_ENDPOINT); from("ahc-wss:" + WEBSOCKET_ENDPOINT).to("seda:end"); } }); WsComponent wsComponent = (WsComponent) camelctx.getComponent("ahc-wss"); wsComponent.setSslContextParameters(defineSSLContextClientParameters()); PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); consumer.start(); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); producer.sendBody("direct:start", "Kermit"); Exchange exchange = consumer.receive(1000); Assert.assertEquals("Hello Kermit", exchange.getIn().getBody(String.class)); } finally { camelctx.close(); } }
Example 3
Source File: SJMSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testMessageConsumerRoute() throws Exception { CamelContext camelctx = createCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("sjms:queue:" + QUEUE_NAME + "?connectionFactory=#cfactory"). transform(body().prepend("Hello ")).to("seda:end"); } }); camelctx.start(); PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); consumer.start(); try { // Send a message to the queue ConnectionFactory cfactory = lookupConnectionFactory(); Connection connection = cfactory.createConnection(); try { sendMessage(connection, QUEUE_JNDI_NAME, "Kermit"); String result = consumer.receive(3000).getIn().getBody(String.class); Assert.assertEquals("Hello Kermit", result); } finally { connection.close(); } } finally { camelctx.close(); } }
Example 4
Source File: NettyIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testNettyTcpSocket() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("netty:tcp://" + SOCKET_HOST + ":" + SOCKET_PORT + "?textline=true") .transform(simple("Hello ${body}")) .inOnly("seda:end"); } }); camelctx.start(); try { PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); Socket socket = new Socket(SOCKET_HOST, SOCKET_PORT); socket.setKeepAlive(true); PrintWriter out = new PrintWriter(socket.getOutputStream(), true); try { out.write("Kermit\n"); } finally { out.close(); socket.close(); } String result = pollingConsumer.receive(3000).getIn().getBody(String.class); Assert.assertEquals("Hello Kermit", result); } finally { camelctx.close(); } }
Example 5
Source File: NettyIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testDeployedContext() throws Exception { ServiceName sname = CamelConstants.CAMEL_CONTEXT_REGISTRY_SERVICE_NAME; CamelContextRegistry registry = ServiceLocator.getRequiredService(sname, CamelContextRegistry.class); CamelContext camelctx = registry.getCamelContext("netty-context"); Assert.assertNotNull("CamelContext not null", camelctx); Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus()); PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); Socket socket = new Socket(SOCKET_HOST, 7999); socket.setKeepAlive(true); PrintWriter out = new PrintWriter(socket.getOutputStream(), true); try { out.write("Kermit\n"); } finally { out.close(); socket.close(); } String result = pollingConsumer.receive().getIn().getBody(String.class); Assert.assertEquals("Hello Kermit", result); }
Example 6
Source File: AtomIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testConsumeAtomFeed() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("atom://http://localhost:8080/atom-test/atom/feed?splitEntries=true") .to("seda:end"); } }); PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); camelctx.start(); try { Entry result = pollingConsumer.receive(5000).getIn().getBody(Entry.class); Assert.assertEquals(FeedConstants.ENTRY_TITLE, result.getTitle()); Assert.assertEquals(FeedConstants.ENTRY_CONTENT, result.getContent()); } finally { camelctx.close(); } }
Example 7
Source File: TransactedJMSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testJMSTransactionToDLQ() throws Exception { CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addComponent("jms", jmsComponent); camelctx.addRoutes(configureJmsRoutes()); camelctx.start(); PollingConsumer consumer = camelctx.getEndpoint("seda:dlq").createPollingConsumer(); consumer.start(); // Send a message to queue camel-jms-queue-one Connection connection = connectionFactory.createConnection(); sendMessage(connection, JmsQueue.QUEUE_ONE.getJndiName(), "Hello Bob"); // The JMS transaction should have been rolled back and the message sent to the DLQ String result = consumer.receive().getIn().getBody(String.class); Assert.assertNotNull(result); Assert.assertEquals("Hello Bob", result); connection.close(); camelctx.close(); }
Example 8
Source File: TransactedJMSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testJMSTransaction() throws Exception { CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addComponent("jms", jmsComponent); camelctx.addRoutes(configureJmsRoutes()); camelctx.start(); PollingConsumer consumer = camelctx.getEndpoint("seda:success").createPollingConsumer(); consumer.start(); // Send a message to queue camel-jms-queue-one Connection connection = connectionFactory.createConnection(); sendMessage(connection, JmsQueue.QUEUE_ONE.getJndiName(), "Hello Kermit"); // The JMS transaction should have been committed and the message payload sent to the direct:success endpoint String result = consumer.receive(3000).getIn().getBody(String.class); Assert.assertNotNull(result); Assert.assertEquals("Hello Kermit", result); connection.close(); camelctx.close(); }
Example 9
Source File: JMSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testMessageConsumerRoute() throws Exception { CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { fromF("jms:queue:%s?connectionFactory=ConnectionFactory", QUEUE_NAME) .transform(simple("Hello ${body}")) .to("seda:end"); } }); camelctx.start(); PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); consumer.start(); try { // Send a message to the queue ConnectionFactory cfactory = (ConnectionFactory) initialctx.lookup("java:/ConnectionFactory"); Connection connection = cfactory.createConnection(); try { sendMessage(connection, QUEUE_JNDI_NAME, "Kermit"); String result = consumer.receive(3000).getIn().getBody(String.class); Assert.assertEquals("Hello Kermit", result); } finally { connection.close(); } } finally { camelctx.close(); } }
Example 10
Source File: SQLIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testSQLEndpointWithCDIContext() throws Exception { try { deployer.deploy(CAMEL_SQL_CDI_ROUTES_JAR); CamelContext camelctx = contextRegistry.getCamelContext("camel-sql-cdi-context"); Assert.assertNotNull("Camel context not null", camelctx); PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); String result = (String) pollingConsumer.receive(3000).getIn().getBody(Map.class).get("NAME"); Assert.assertEquals("SA", result); } finally { deployer.undeploy(CAMEL_SQL_CDI_ROUTES_JAR); } }
Example 11
Source File: SQLIntegrationTest.java From wildfly-camel with Apache License 2.0 | 6 votes |
@Test public void testSQLEndpoint() throws Exception { Assert.assertNotNull("DataSource not null", dataSource); CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("sql:select name from information_schema.users?dataSource=java:jboss/datasources/ExampleDS") .to("seda:end"); } }); PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); camelctx.start(); try { String result = (String) pollingConsumer.receive(3000).getIn().getBody(Map.class).get("NAME"); Assert.assertEquals("SA", result); } finally { camelctx.close(); } }
Example 12
Source File: ZipFileIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testZipSplitterUnmarshal() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("file://" + datadir + File.separator + "zip-unmarshal?initialDelay=500&antInclude=*.zip&noop=true") .split(new ZipSplitter()) .streaming() .convertBodyTo(String.class) .to("seda:end"); } }); createZipFile("Hello Kermit"); PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); camelctx.start(); try { String result = pollingConsumer.receive(3000).getIn().getBody(String.class); Assert.assertEquals("Hello Kermit", result); } finally { camelctx.close(); } }
Example 13
Source File: ZipFileIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testZipFileUnmarshal() throws Exception { final ZipFileDataFormat zipFileDataFormat = new ZipFileDataFormat(); zipFileDataFormat.setUsingIterator("true"); CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("file://" + datadir + File.separator + "zip-unmarshal?initialDelay=500&antInclude=*.zip&noop=true") .unmarshal(zipFileDataFormat) .split(bodyAs(Iterator.class)) .streaming() .convertBodyTo(String.class) .to("seda:end"); } }); createZipFile("Hello Kermit"); PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); camelctx.start(); try { String result = pollingConsumer.receive(3000).getIn().getBody(String.class); Assert.assertEquals("Hello Kermit", result); } finally { camelctx.close(); } }
Example 14
Source File: ActiveMQIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testSendMessage() throws Exception { CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { fromF("activemq:queue:%s?connectionFactory=java:/ActiveMQConnectionFactory", QUEUE_NAME). transform(simple("Hello ${body}")). to("seda:end"); } }); PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); camelctx.start(); try { ConnectionFactory connectionFactory = lookupConnectionFactory(); Connection con = connectionFactory.createConnection(); try { sendMessage(con, "Kermit"); String result = pollingConsumer.receive(3000).getIn().getBody(String.class); Assert.assertEquals("Hello Kermit", result); } finally { con.close(); } } finally { camelctx.close(); } }
Example 15
Source File: CXFWSSecureProducerIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testEndpointRouteWithInvalidCredentials() throws Exception { deployer.deploy(SIMPLE_WAR); try { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start") .doTry() .to("cxf://" + getEndpointAddress("/simple", "baduser", "badpassword")) .doCatch(Exception.class) .setBody(exceptionMessage()) .to("direct:error") .end(); } }); PollingConsumer pollingConsumer = camelctx.getEndpoint("direct:error").createPollingConsumer(); pollingConsumer.start(); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); producer.requestBody("direct:start", "Kermit", String.class); String result = pollingConsumer.receive(3000).getIn().getBody(String.class); Assert.assertTrue(result.contains("401: Unauthorized")); } finally { camelctx.close(); } } finally { deployer.undeploy(SIMPLE_WAR); } }
Example 16
Source File: AhcWSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Test public void testAsyncWsRoute() throws Exception { CamelContext camelctx = new DefaultCamelContext(); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("ahc-ws:" + WEBSOCKET_ENDPOINT); from("ahc-ws:" + WEBSOCKET_ENDPOINT).to("seda:end"); } }); PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); consumer.start(); camelctx.start(); try { ProducerTemplate producer = camelctx.createProducerTemplate(); producer.sendBody("direct:start", "Kermit"); Exchange exchange = consumer.receive(1000); Assert.assertEquals("Hello Kermit", exchange.getIn().getBody(String.class)); } finally { camelctx.close(); } }
Example 17
Source File: ActiveMQIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void testCustomMessageConverter() throws Exception { MessageConverter converter = new MessageConverter() { @Override public Message toMessage(Object o, Session session) throws JMSException, MessageConversionException { return null; } @Override public Object fromMessage(Message message) throws JMSException, MessageConversionException { TextMessage originalMessage = (TextMessage) message; TextMessage modifiedMessage = new ActiveMQTextMessage(); modifiedMessage.setText(originalMessage.getText() + " Modified"); return modifiedMessage; } }; context.bind("messageConverter", converter); CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { fromF("activemq:queue:%s?connectionFactory=java:/ActiveMQConnectionFactory&messageConverter=#messageConverter", QUEUE_NAME). transform(simple("Hello ${body.getText()}")). to("seda:end"); } }); PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); camelctx.start(); try { ConnectionFactory connectionFactory = lookupConnectionFactory(); Connection con = connectionFactory.createConnection(); try { sendMessage(con, "Kermit"); String result = pollingConsumer.receive(3000).getIn().getBody(String.class); Assert.assertEquals("Hello Kermit Modified", result); } finally { con.close(); } } finally { camelctx.close(); context.unbind("messageConverter"); } }
Example 18
Source File: JMSIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void testCustomMessageConverter() throws Exception { MessageConverter converter = new MessageConverter() { @Override public Message toMessage(Object o, Session session) throws JMSException, MessageConversionException { return null; } @Override public Object fromMessage(Message message) throws JMSException, MessageConversionException { TextMessage originalMessage = (TextMessage) message; TextMessage modifiedMessage = new ActiveMQTextMessage(); modifiedMessage.setText(originalMessage.getText() + " Modified"); return modifiedMessage; } }; initialctx.bind("messageConverter", converter); CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { fromF("jms:queue:%s?connectionFactory=ConnectionFactory&messageConverter=#messageConverter", QUEUE_NAME) .transform(simple("Hello ${body.getText()}")) .to("seda:end"); } }); camelctx.start(); PollingConsumer consumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); consumer.start(); try { // Send a message to the queue ConnectionFactory cfactory = (ConnectionFactory) initialctx.lookup("java:/ConnectionFactory"); Connection connection = cfactory.createConnection(); try { sendMessage(connection, QUEUE_JNDI_NAME, "Kermit"); String result = consumer.receive(3000).getIn().getBody(String.class); Assert.assertEquals("Hello Kermit Modified", result); } finally { connection.close(); } } finally { camelctx.close(); initialctx.unbind("messageConverter"); } }
Example 19
Source File: DynamoDBStreamsIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Test public void testKeyValueOperations() throws Exception { AmazonDynamoDBClient ddbClient = ddbProvider.getClient(); Assume.assumeNotNull("AWS client not null", ddbClient); DynamoDBUtils.assertNoStaleTables(ddbClient, "before"); try { try { TableDescription description = DynamoDBUtils.createTable(ddbClient, tableName); Assert.assertEquals("ACTIVE", description.getTableStatus()); WildFlyCamelContext camelctx = new WildFlyCamelContext(); camelctx.getNamingContext().bind("ddbClientB", ddbClient); camelctx.getNamingContext().bind("dbsClientB", dbsProvider.getClient()); camelctx.addRoutes(new RouteBuilder() { @Override public void configure() throws Exception { from("direct:start").to("aws-ddb://" + tableName + "?amazonDDBClient=#ddbClientB"); from("aws-ddbstream://" + tableName + "?amazonDynamoDbStreamsClient=#dbsClientB") .to("seda:end"); } }); PollingConsumer pollingConsumer = camelctx.getEndpoint("seda:end").createPollingConsumer(); pollingConsumer.start(); camelctx.start(); try { DynamoDBUtils.putItem(camelctx, "Book 103 Title"); String result = ((AttributeValue) DynamoDBUtils.getItem(camelctx).get("Title")).getS(); Assert.assertEquals("Book 103 Title", result); Exchange exchange = pollingConsumer.receive(3000); Assert.assertNull(exchange); DynamoDBUtils.updItem(camelctx, "Book 103 Update"); result = ((AttributeValue) DynamoDBUtils.getItem(camelctx).get("Title")).getS(); Assert.assertEquals("Book 103 Update", result); exchange = pollingConsumer.receive(3000); StreamRecord record = exchange.getIn().getBody(Record.class).getDynamodb(); Map<String, AttributeValue> oldImage = record.getOldImage(); Map<String, AttributeValue> newImage = record.getNewImage(); Assert.assertEquals("Book 103 Title", oldImage.get("Title").getS()); Assert.assertEquals("Book 103 Update", newImage.get("Title").getS()); } finally { camelctx.close(); } } finally { DynamoDBUtils.deleteTable(ddbClient, tableName); } } finally { DynamoDBUtils.assertNoStaleTables(ddbClient, "after"); } }