Return-Path: X-Original-To: apmail-brooklyn-commits-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5027A18063 for ; Wed, 15 Jul 2015 23:11:07 +0000 (UTC) Received: (qmail 40484 invoked by uid 500); 15 Jul 2015 23:11:07 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 40461 invoked by uid 500); 15 Jul 2015 23:11:07 -0000 Mailing-List: contact commits-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list commits@brooklyn.incubator.apache.org Received: (qmail 40446 invoked by uid 99); 15 Jul 2015 23:11:07 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Jul 2015 23:11:07 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id C157DD4DDC for ; Wed, 15 Jul 2015 23:11:06 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.354 X-Spam-Level: X-Spam-Status: No, score=0.354 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id Q_0kol3Q31SR for ; Wed, 15 Jul 2015 23:11:04 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with SMTP id 292A3261E6 for ; Wed, 15 Jul 2015 23:11:01 +0000 (UTC) Received: (qmail 37968 invoked by uid 99); 15 Jul 2015 23:09:45 -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, 15 Jul 2015 23:09:45 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8F2FCE35E6; Wed, 15 Jul 2015 23:09:45 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: aledsage@apache.org To: commits@brooklyn.incubator.apache.org Date: Wed, 15 Jul 2015 23:09:55 -0000 Message-Id: In-Reply-To: <1ce75962fe5043b8a0e4e6e4f3f0a8b2@git.apache.org> References: <1ce75962fe5043b8a0e4e6e4f3f0a8b2@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [11/12] incubator-brooklyn git commit: brooklyn-example-simple-messaging-pubsub: add org.apache package prefix brooklyn-example-simple-messaging-pubsub: add org.apache package prefix Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/f2792fa1 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/f2792fa1 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/f2792fa1 Branch: refs/heads/master Commit: f2792fa18a7bfb58f42938cde6f6bbaed49dacec Parents: 44d2dc1 Author: Ciprian Ciubotariu Authored: Wed Jul 15 11:11:14 2015 +0300 Committer: Ciprian Ciubotariu Committed: Wed Jul 15 18:47:01 2015 +0300 ---------------------------------------------------------------------- .../java/brooklyn/demo/KafkaClusterExample.java | 58 --------------- .../src/main/java/brooklyn/demo/Publish.java | 71 ------------------ .../demo/StandaloneQpidBrokerExample.java | 73 ------------------- .../src/main/java/brooklyn/demo/Subscribe.java | 76 -------------------- .../brooklyn/demo/KafkaClusterExample.java | 58 +++++++++++++++ .../java/org/apache/brooklyn/demo/Publish.java | 71 ++++++++++++++++++ .../demo/StandaloneQpidBrokerExample.java | 73 +++++++++++++++++++ .../org/apache/brooklyn/demo/Subscribe.java | 76 ++++++++++++++++++++ 8 files changed, 278 insertions(+), 278 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f2792fa1/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/KafkaClusterExample.java ---------------------------------------------------------------------- diff --git a/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/KafkaClusterExample.java b/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/KafkaClusterExample.java deleted file mode 100644 index ec921c9..0000000 --- a/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/KafkaClusterExample.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 brooklyn.demo; - -import java.util.List; - -import brooklyn.entity.basic.ApplicationBuilder; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.messaging.kafka.KafkaCluster; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.util.CommandLineUtil; - -import com.google.common.collect.Lists; - -/** Kafka Cluster Application */ -public class KafkaClusterExample extends ApplicationBuilder { - - public static final String DEFAULT_LOCATION = "localhost"; - - /** Configure the application. */ - protected void doBuild() { - addChild(EntitySpec.create(KafkaCluster.class) - .configure("startTimeout", 300) // 5 minutes - .configure("initialSize", 2)); - // TODO set application display name? - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(new KafkaClusterExample().appDisplayName("Kafka cluster application")) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f2792fa1/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/Publish.java ---------------------------------------------------------------------- diff --git a/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/Publish.java b/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/Publish.java deleted file mode 100644 index 22c0a60..0000000 --- a/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/Publish.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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 brooklyn.demo; - -import javax.jms.Connection; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; - -import org.apache.qpid.client.AMQConnectionFactory; -import org.apache.qpid.configuration.ClientProperties; - -import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; - -/** Publishes messages to a queue on a Qpid broker at a given URL. */ -public class Publish { - public static final String QUEUE = "'amq.direct'/'testQueue'; { node: { type: queue } }"; - - public static void main(String...argv) throws Exception { - Preconditions.checkElementIndex(0, argv.length, "Must specify broker URL"); - String url = argv[0]; - - // Set Qpid client properties - System.setProperty(ClientProperties.AMQP_VERSION, "0-10"); - System.setProperty(ClientProperties.DEST_SYNTAX, "ADDR"); - - // Connect to the broker - AMQConnectionFactory factory = new AMQConnectionFactory(url); - Connection connection = factory.createConnection(); - connection.start(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - try { - // Create a producer for the queue - Queue destination = session.createQueue(QUEUE); - MessageProducer messageProducer = session.createProducer(destination); - - // Send 100 messages - for (int n = 0; n < 100; n++) { - String body = String.format("test message %03d", n+1); - TextMessage message = session.createTextMessage(body); - messageProducer.send(message); - System.out.printf("Sent message %s\n", body); - } - } catch (Exception e) { - System.err.printf("Error while sending - %s\n", e.getMessage()); - System.err.printf("Cause: %s\n", Throwables.getStackTraceAsString(e)); - } finally { - session.close(); - connection.close(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f2792fa1/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/StandaloneQpidBrokerExample.java ---------------------------------------------------------------------- diff --git a/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/StandaloneQpidBrokerExample.java b/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/StandaloneQpidBrokerExample.java deleted file mode 100644 index 89f7874..0000000 --- a/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/StandaloneQpidBrokerExample.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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 brooklyn.demo; - -import java.util.List; - -import brooklyn.entity.basic.AbstractApplication; -import brooklyn.entity.basic.Entities; -import brooklyn.entity.basic.StartableApplication; -import brooklyn.entity.messaging.amqp.AmqpServer; -import brooklyn.entity.messaging.qpid.QpidBroker; -import brooklyn.entity.proxying.EntitySpec; -import brooklyn.launcher.BrooklynLauncher; -import brooklyn.util.CommandLineUtil; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; - -/** Qpid Broker Application */ -public class StandaloneQpidBrokerExample extends AbstractApplication { - - public static final String CUSTOM_CONFIG_PATH = "classpath://custom-config.xml"; - public static final String PASSWD_PATH = "classpath://passwd"; - public static final String QPID_BDBSTORE_JAR_PATH = "classpath://qpid-bdbstore-0.20.jar"; - public static final String BDBSTORE_JAR_PATH = "classpath://je-5.0.34.jar"; - - public static final String DEFAULT_LOCATION = "localhost"; - - @Override - public void initApp() { - // Configure the Qpid broker entity - QpidBroker broker = addChild(EntitySpec.create(QpidBroker.class) - .configure("amqpPort", 5672) - .configure("amqpVersion", AmqpServer.AMQP_0_10) - .configure("runtimeFiles", ImmutableMap.builder() - .put(CUSTOM_CONFIG_PATH, QpidBroker.CONFIG_XML) - .put(PASSWD_PATH, QpidBroker.PASSWD) - .put(QPID_BDBSTORE_JAR_PATH, "lib/opt/qpid-bdbstore-0.20.jar") - .put(BDBSTORE_JAR_PATH, "lib/opt/je-5.0.34.jar") - .build()) - .configure("queue", "testQueue")); - } - - public static void main(String[] argv) { - List args = Lists.newArrayList(argv); - String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); - String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION); - - BrooklynLauncher launcher = BrooklynLauncher.newInstance() - .application(EntitySpec.create(StartableApplication.class, StandaloneQpidBrokerExample.class).displayName("Qpid app")) - .webconsolePort(port) - .location(location) - .start(); - - Entities.dumpInfo(launcher.getApplications()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f2792fa1/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/Subscribe.java ---------------------------------------------------------------------- diff --git a/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/Subscribe.java b/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/Subscribe.java deleted file mode 100644 index 7272887..0000000 --- a/examples/simple-messaging-pubsub/src/main/java/brooklyn/demo/Subscribe.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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 brooklyn.demo; - -import javax.jms.Connection; -import javax.jms.MessageConsumer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; - -import org.apache.qpid.client.AMQConnectionFactory; -import org.apache.qpid.configuration.ClientProperties; - -import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; - -/** Receives messages from a queue on a Qpid broker at a given URL. */ -public class Subscribe { - public static final String QUEUE = "'amq.direct'/'testQueue'; { node: { type: queue } }"; - private static final long MESSAGE_TIMEOUT_MILLIS = 15000L; - private static final int MESSAGE_COUNT = 100; - - public static void main(String...argv) throws Exception { - Preconditions.checkElementIndex(0, argv.length, "Must specify broker URL"); - String url = argv[0]; - - // Set Qpid client properties - System.setProperty(ClientProperties.AMQP_VERSION, "0-10"); - System.setProperty(ClientProperties.DEST_SYNTAX, "ADDR"); - - // Connect to the broker - AMQConnectionFactory factory = new AMQConnectionFactory(url); - Connection connection = factory.createConnection(); - connection.start(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - System.out.printf("Waiting up to %s milliseconds to receive %s messages\n", MESSAGE_TIMEOUT_MILLIS, MESSAGE_COUNT); - try { - // Create a producer for the queue - Queue destination = session.createQueue(QUEUE); - MessageConsumer messageConsumer = session.createConsumer(destination); - - // Try and receive 100 messages - for (int n = 0; n < MESSAGE_COUNT; n++) { - TextMessage msg = (TextMessage) messageConsumer.receive(MESSAGE_TIMEOUT_MILLIS); - if (msg == null) { - System.out.printf("No message received in %s milliseconds, exiting", MESSAGE_TIMEOUT_MILLIS); - break; - } - System.out.printf("Got message %d: '%s'\n", n+1, msg.getText()); - } - } catch (Exception e) { - System.err.printf("Error while receiving - %s\n", e.getMessage()); - System.err.printf("Cause: %s\n", Throwables.getStackTraceAsString(e)); - } finally { - session.close(); - connection.close(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f2792fa1/examples/simple-messaging-pubsub/src/main/java/org/apache/brooklyn/demo/KafkaClusterExample.java ---------------------------------------------------------------------- diff --git a/examples/simple-messaging-pubsub/src/main/java/org/apache/brooklyn/demo/KafkaClusterExample.java b/examples/simple-messaging-pubsub/src/main/java/org/apache/brooklyn/demo/KafkaClusterExample.java new file mode 100644 index 0000000..f0d361e --- /dev/null +++ b/examples/simple-messaging-pubsub/src/main/java/org/apache/brooklyn/demo/KafkaClusterExample.java @@ -0,0 +1,58 @@ +/* + * 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.brooklyn.demo; + +import java.util.List; + +import brooklyn.entity.basic.ApplicationBuilder; +import brooklyn.entity.basic.Entities; +import brooklyn.entity.messaging.kafka.KafkaCluster; +import brooklyn.entity.proxying.EntitySpec; +import brooklyn.launcher.BrooklynLauncher; +import brooklyn.util.CommandLineUtil; + +import com.google.common.collect.Lists; + +/** Kafka Cluster Application */ +public class KafkaClusterExample extends ApplicationBuilder { + + public static final String DEFAULT_LOCATION = "localhost"; + + /** Configure the application. */ + protected void doBuild() { + addChild(EntitySpec.create(KafkaCluster.class) + .configure("startTimeout", 300) // 5 minutes + .configure("initialSize", 2)); + // TODO set application display name? + } + + public static void main(String[] argv) { + List args = Lists.newArrayList(argv); + String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); + String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION); + + BrooklynLauncher launcher = BrooklynLauncher.newInstance() + .application(new KafkaClusterExample().appDisplayName("Kafka cluster application")) + .webconsolePort(port) + .location(location) + .start(); + + Entities.dumpInfo(launcher.getApplications()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f2792fa1/examples/simple-messaging-pubsub/src/main/java/org/apache/brooklyn/demo/Publish.java ---------------------------------------------------------------------- diff --git a/examples/simple-messaging-pubsub/src/main/java/org/apache/brooklyn/demo/Publish.java b/examples/simple-messaging-pubsub/src/main/java/org/apache/brooklyn/demo/Publish.java new file mode 100644 index 0000000..8a68061 --- /dev/null +++ b/examples/simple-messaging-pubsub/src/main/java/org/apache/brooklyn/demo/Publish.java @@ -0,0 +1,71 @@ +/* + * 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.brooklyn.demo; + +import javax.jms.Connection; +import javax.jms.MessageProducer; +import javax.jms.Queue; +import javax.jms.Session; +import javax.jms.TextMessage; + +import org.apache.qpid.client.AMQConnectionFactory; +import org.apache.qpid.configuration.ClientProperties; + +import com.google.common.base.Preconditions; +import com.google.common.base.Throwables; + +/** Publishes messages to a queue on a Qpid broker at a given URL. */ +public class Publish { + public static final String QUEUE = "'amq.direct'/'testQueue'; { node: { type: queue } }"; + + public static void main(String...argv) throws Exception { + Preconditions.checkElementIndex(0, argv.length, "Must specify broker URL"); + String url = argv[0]; + + // Set Qpid client properties + System.setProperty(ClientProperties.AMQP_VERSION, "0-10"); + System.setProperty(ClientProperties.DEST_SYNTAX, "ADDR"); + + // Connect to the broker + AMQConnectionFactory factory = new AMQConnectionFactory(url); + Connection connection = factory.createConnection(); + connection.start(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + try { + // Create a producer for the queue + Queue destination = session.createQueue(QUEUE); + MessageProducer messageProducer = session.createProducer(destination); + + // Send 100 messages + for (int n = 0; n < 100; n++) { + String body = String.format("test message %03d", n+1); + TextMessage message = session.createTextMessage(body); + messageProducer.send(message); + System.out.printf("Sent message %s\n", body); + } + } catch (Exception e) { + System.err.printf("Error while sending - %s\n", e.getMessage()); + System.err.printf("Cause: %s\n", Throwables.getStackTraceAsString(e)); + } finally { + session.close(); + connection.close(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f2792fa1/examples/simple-messaging-pubsub/src/main/java/org/apache/brooklyn/demo/StandaloneQpidBrokerExample.java ---------------------------------------------------------------------- diff --git a/examples/simple-messaging-pubsub/src/main/java/org/apache/brooklyn/demo/StandaloneQpidBrokerExample.java b/examples/simple-messaging-pubsub/src/main/java/org/apache/brooklyn/demo/StandaloneQpidBrokerExample.java new file mode 100644 index 0000000..9df7005 --- /dev/null +++ b/examples/simple-messaging-pubsub/src/main/java/org/apache/brooklyn/demo/StandaloneQpidBrokerExample.java @@ -0,0 +1,73 @@ +/* + * 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.brooklyn.demo; + +import java.util.List; + +import brooklyn.entity.basic.AbstractApplication; +import brooklyn.entity.basic.Entities; +import brooklyn.entity.basic.StartableApplication; +import brooklyn.entity.messaging.amqp.AmqpServer; +import brooklyn.entity.messaging.qpid.QpidBroker; +import brooklyn.entity.proxying.EntitySpec; +import brooklyn.launcher.BrooklynLauncher; +import brooklyn.util.CommandLineUtil; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; + +/** Qpid Broker Application */ +public class StandaloneQpidBrokerExample extends AbstractApplication { + + public static final String CUSTOM_CONFIG_PATH = "classpath://custom-config.xml"; + public static final String PASSWD_PATH = "classpath://passwd"; + public static final String QPID_BDBSTORE_JAR_PATH = "classpath://qpid-bdbstore-0.20.jar"; + public static final String BDBSTORE_JAR_PATH = "classpath://je-5.0.34.jar"; + + public static final String DEFAULT_LOCATION = "localhost"; + + @Override + public void initApp() { + // Configure the Qpid broker entity + QpidBroker broker = addChild(EntitySpec.create(QpidBroker.class) + .configure("amqpPort", 5672) + .configure("amqpVersion", AmqpServer.AMQP_0_10) + .configure("runtimeFiles", ImmutableMap.builder() + .put(CUSTOM_CONFIG_PATH, QpidBroker.CONFIG_XML) + .put(PASSWD_PATH, QpidBroker.PASSWD) + .put(QPID_BDBSTORE_JAR_PATH, "lib/opt/qpid-bdbstore-0.20.jar") + .put(BDBSTORE_JAR_PATH, "lib/opt/je-5.0.34.jar") + .build()) + .configure("queue", "testQueue")); + } + + public static void main(String[] argv) { + List args = Lists.newArrayList(argv); + String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); + String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION); + + BrooklynLauncher launcher = BrooklynLauncher.newInstance() + .application(EntitySpec.create(StartableApplication.class, StandaloneQpidBrokerExample.class).displayName("Qpid app")) + .webconsolePort(port) + .location(location) + .start(); + + Entities.dumpInfo(launcher.getApplications()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/f2792fa1/examples/simple-messaging-pubsub/src/main/java/org/apache/brooklyn/demo/Subscribe.java ---------------------------------------------------------------------- diff --git a/examples/simple-messaging-pubsub/src/main/java/org/apache/brooklyn/demo/Subscribe.java b/examples/simple-messaging-pubsub/src/main/java/org/apache/brooklyn/demo/Subscribe.java new file mode 100644 index 0000000..b7df104 --- /dev/null +++ b/examples/simple-messaging-pubsub/src/main/java/org/apache/brooklyn/demo/Subscribe.java @@ -0,0 +1,76 @@ +/* + * 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.brooklyn.demo; + +import javax.jms.Connection; +import javax.jms.MessageConsumer; +import javax.jms.Queue; +import javax.jms.Session; +import javax.jms.TextMessage; + +import org.apache.qpid.client.AMQConnectionFactory; +import org.apache.qpid.configuration.ClientProperties; + +import com.google.common.base.Preconditions; +import com.google.common.base.Throwables; + +/** Receives messages from a queue on a Qpid broker at a given URL. */ +public class Subscribe { + public static final String QUEUE = "'amq.direct'/'testQueue'; { node: { type: queue } }"; + private static final long MESSAGE_TIMEOUT_MILLIS = 15000L; + private static final int MESSAGE_COUNT = 100; + + public static void main(String...argv) throws Exception { + Preconditions.checkElementIndex(0, argv.length, "Must specify broker URL"); + String url = argv[0]; + + // Set Qpid client properties + System.setProperty(ClientProperties.AMQP_VERSION, "0-10"); + System.setProperty(ClientProperties.DEST_SYNTAX, "ADDR"); + + // Connect to the broker + AMQConnectionFactory factory = new AMQConnectionFactory(url); + Connection connection = factory.createConnection(); + connection.start(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + System.out.printf("Waiting up to %s milliseconds to receive %s messages\n", MESSAGE_TIMEOUT_MILLIS, MESSAGE_COUNT); + try { + // Create a producer for the queue + Queue destination = session.createQueue(QUEUE); + MessageConsumer messageConsumer = session.createConsumer(destination); + + // Try and receive 100 messages + for (int n = 0; n < MESSAGE_COUNT; n++) { + TextMessage msg = (TextMessage) messageConsumer.receive(MESSAGE_TIMEOUT_MILLIS); + if (msg == null) { + System.out.printf("No message received in %s milliseconds, exiting", MESSAGE_TIMEOUT_MILLIS); + break; + } + System.out.printf("Got message %d: '%s'\n", n+1, msg.getText()); + } + } catch (Exception e) { + System.err.printf("Error while receiving - %s\n", e.getMessage()); + System.err.printf("Cause: %s\n", Throwables.getStackTraceAsString(e)); + } finally { + session.close(); + connection.close(); + } + } +}