Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 42B43200C5B for ; Wed, 12 Apr 2017 21:56:22 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 400DF160BA8; Wed, 12 Apr 2017 19:56:22 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6FCE7160B95 for ; Wed, 12 Apr 2017 21:56:21 +0200 (CEST) Received: (qmail 58429 invoked by uid 500); 12 Apr 2017 19:56:20 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 58370 invoked by uid 99); 12 Apr 2017 19:56:20 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Apr 2017 19:56:20 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5AE16E96A4; Wed, 12 Apr 2017 19:56:20 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Wed, 12 Apr 2017 19:56:23 -0000 Message-Id: <1fbca552b72743f4a11e9a3d4bb35ab4@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [04/11] camel git commit: initial commit of camel-pubnub component archived-at: Wed, 12 Apr 2017 19:56:22 -0000 http://git-wip-us.apache.org/repos/asf/camel/blob/289a6728/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.java ---------------------------------------------------------------------- diff --git a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.java b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.java new file mode 100644 index 0000000..01d51fa --- /dev/null +++ b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensor2Example.java @@ -0,0 +1,122 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.pubnub.example; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.camel.EndpointInject; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.pubnub.PubNubConstants; +import org.apache.camel.main.Main; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +public final class PubNubSensor2Example { + + private PubNubSensor2Example() { + } + + public static void main(String[] args) throws Exception { + Main main = new Main(); + main.addRouteBuilder(new PubsubRoute()); + main.addRouteBuilder(new SimulatedDeviceEventGeneratorRoute()); + main.run(); + } + + static class SimulatedDeviceEventGeneratorRoute extends RouteBuilder { + private final String deviceEP = "pubnub://pubsub:iot?uuid=device2&publisherKey=" + PubNubExampleConstants.PUBNUB_PUBLISHER_KEY + "&subscriberKey=" + + PubNubExampleConstants.PUBNUB_SUBSCRIBER_KEY; + private final String devicePrivateEP = "pubnub://pubsub:device2private?uuid=device2&publisherKey=" + PubNubExampleConstants.PUBNUB_PUBLISHER_KEY + "&subscriberKey=" + + PubNubExampleConstants.PUBNUB_SUBSCRIBER_KEY; + + @Override + public void configure() throws Exception { + //@formatter:off + from("timer:device2").routeId("device-event-route") + .bean(PubNubSensor2Example.EventGeneratorBean.class, "getRandomEvent('device2')") + .convertBodyTo(JSONObject.class) + .to(deviceEP); + + from(devicePrivateEP) + .routeId("device-unicast-route") + .log("Message from master to device2 : ${body}"); + //@formatter:on + } + } + + static class PubsubRoute extends RouteBuilder { + private static String masterEP = "pubnub://pubsub:iot?uuid=master&subscriberKey=" + PubNubExampleConstants.PUBNUB_SUBSCRIBER_KEY + "&publisherKey=" + + PubNubExampleConstants.PUBNUB_PUBLISHER_KEY; + private static Map devices = new ConcurrentHashMap(); + + @Override + public void configure() throws Exception { + //@formatter:off + from(masterEP) + .routeId("master-route") + .convertBodyTo(JSONObject.class) + .bean(PubNubSensor2Example.PubsubRoute.DataProcessorBean.class, "doSomethingInteresting(${body})") + .log("${body} headers : ${headers}").to("mock:result"); + + //TODO Could remote control device to turn on/off sensor measurement + from("timer:master?delay=15s&period=5s").routeId("unicast2device-route") + .setHeader(PubNubConstants.CHANNEL, method(PubNubSensor2Example.PubsubRoute.DataProcessorBean.class, "getUnicastChannelOfDevice()")) + .setBody(constant("Hello device")) + .to(masterEP); + //@formatter:on + } + + static class DataProcessorBean { + @EndpointInject(uri = "pubnub://pubsub:iot?uuid=master&subscriberKey=" + PubNubExampleConstants.PUBNUB_SUBSCRIBER_KEY) + private static ProducerTemplate template; + + public static String getUnicastChannelOfDevice() { + // just get the first channel + return devices.values().iterator().next(); + } + + public static void doSomethingInteresting(JSONObject message) { + String deviceUUID; + try { + deviceUUID = message.getString("uuid"); + if (devices.get(deviceUUID) == null) { + Map headers = new HashMap(); + headers.put(PubNubConstants.OPERATION, "WHERE_NOW"); + headers.put(PubNubConstants.UUID, deviceUUID); + JSONObject response = (JSONObject)template.requestBodyAndHeaders(null, headers); + JSONArray listofDeviceChannels = response.getJSONArray("channels"); + devices.put(deviceUUID, listofDeviceChannels.getString(0)); + } + } catch (JSONException e) { + } + } + } + } + + public static class EventGeneratorBean { + public static String getRandomEvent(String device) throws JSONException { + Random rand = new Random(); + String s = "{uuid:" + device + ", humidity:" + rand.nextInt(100) + ", temperature:" + rand.nextInt(40) + "}"; + return s; + } + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/289a6728/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensorExample.java ---------------------------------------------------------------------- diff --git a/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensorExample.java b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensorExample.java new file mode 100644 index 0000000..0625453 --- /dev/null +++ b/components/camel-pubnub/src/test/java/org/apache/camel/component/pubnub/example/PubNubSensorExample.java @@ -0,0 +1,40 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.pubnub.example; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.main.Main; + +public final class PubNubSensorExample { + + private PubNubSensorExample() { + } + + public static void main(String[] args) throws Exception { + Main main = new Main(); + main.addRouteBuilder(new SensorRoute()); + main.run(); + } + + static class SensorRoute extends RouteBuilder { + @Override + public void configure() throws Exception { + from("pubnub://pubsub:pubnub-sensor-network?subscriberKey=sub-c-5f1b7c8e-fbee-11e3-aa40-02ee2ddab7fe").log("${body}").to("mock:result"); + } + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/289a6728/components/camel-pubnub/src/test/resources/log4j2.properties ---------------------------------------------------------------------- diff --git a/components/camel-pubnub/src/test/resources/log4j2.properties b/components/camel-pubnub/src/test/resources/log4j2.properties new file mode 100644 index 0000000..25b59c8 --- /dev/null +++ b/components/camel-pubnub/src/test/resources/log4j2.properties @@ -0,0 +1,28 @@ +## --------------------------------------------------------------------------- +## Licensed to the Apache Software Foundation (ASF) under one or more +## contributor license agreements. See the NOTICE file distributed with +## this work for additional information regarding copyright ownership. +## The ASF licenses this file to You under the Apache License, Version 2.0 +## (the "License"); you may not use this file except in compliance with +## the License. You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## --------------------------------------------------------------------------- + +appender.file.type = File +appender.file.name = file +appender.file.fileName = target/camel-pubnub-test.log +appender.file.layout.type = PatternLayout +appender.file.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n +appender.out.type = Console +appender.out.name = out +appender.out.layout.type = PatternLayout +appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n +rootLogger.level = INFO +rootLogger.appenderRef.file.ref = file http://git-wip-us.apache.org/repos/asf/camel/blob/289a6728/components/pom.xml ---------------------------------------------------------------------- diff --git a/components/pom.xml b/components/pom.xml index 429ee4e..49a423c 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -220,6 +220,7 @@ camel-pgevent camel-printer camel-protobuf + camel-pubnub camel-quartz camel-quartz2 camel-quickfix http://git-wip-us.apache.org/repos/asf/camel/blob/289a6728/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index 65387c8..546f7ce 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -517,6 +517,7 @@ 0.7.1 1.6.6 3.1.0 + 3.7.4 0.28_1 0.16.0 0.14.0