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 E2920200B6B for ; Thu, 11 Aug 2016 01:56:16 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id E1350160AA4; Wed, 10 Aug 2016 23:56:16 +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 90ABD160AB8 for ; Thu, 11 Aug 2016 01:56:14 +0200 (CEST) Received: (qmail 11825 invoked by uid 500); 10 Aug 2016 23:56:13 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 11605 invoked by uid 99); 10 Aug 2016 23:56:13 -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, 10 Aug 2016 23:56:13 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 70BBDE3A9C; Wed, 10 Aug 2016 23:56:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: johndament@apache.org To: commits@activemq.apache.org Date: Wed, 10 Aug 2016 23:56:16 -0000 Message-Id: <0046e3da6ebd4373bbede84b8159b23b@git.apache.org> In-Reply-To: <659146922a284650906ef7891881395d@git.apache.org> References: <659146922a284650906ef7891881395d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [4/5] activemq-artemis git commit: ARTEMIS-670 Adjusting package names on CLI and adding input for destination create name archived-at: Wed, 10 Aug 2016 23:56:17 -0000 ARTEMIS-670 Adjusting package names on CLI and adding input for destination create name Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/7d684956 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/7d684956 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/7d684956 Branch: refs/heads/master Commit: 7d684956e2028bc73137d1d6fb507dbd490c2deb Parents: 1f9ca74 Author: Clebert Suconic Authored: Wed Aug 10 19:08:45 2016 -0400 Committer: Clebert Suconic Committed: Wed Aug 10 19:12:58 2016 -0400 ---------------------------------------------------------------------- .../apache/activemq/artemis/cli/Artemis.java | 13 +- .../artemis/cli/commands/ActionAbstract.java | 2 +- .../activemq/artemis/cli/commands/Browse.java | 77 ---------- .../activemq/artemis/cli/commands/Consumer.java | 86 ----------- .../artemis/cli/commands/CreateDestination.java | 151 ------------------ .../artemis/cli/commands/DeleteDestination.java | 125 --------------- .../artemis/cli/commands/DestAbstract.java | 48 ------ .../artemis/cli/commands/DestinationAction.java | 142 ----------------- .../artemis/cli/commands/HelpDestination.java | 54 ------- .../activemq/artemis/cli/commands/Producer.java | 87 ----------- .../commands/destination/CreateDestination.java | 152 +++++++++++++++++++ .../commands/destination/DeleteDestination.java | 126 +++++++++++++++ .../commands/destination/DestinationAction.java | 139 +++++++++++++++++ .../commands/destination/HelpDestination.java | 56 +++++++ .../artemis/cli/commands/messages/Browse.java | 78 ++++++++++ .../artemis/cli/commands/messages/Consumer.java | 87 +++++++++++ .../cli/commands/messages/DestAbstract.java | 49 ++++++ .../artemis/cli/commands/messages/Producer.java | 88 +++++++++++ .../integration/cli/DestinationCommandTest.java | 6 +- 19 files changed, 786 insertions(+), 780 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java index 72f0eba..40b52bf 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java @@ -24,15 +24,15 @@ import java.util.List; import io.airlift.airline.Cli; import org.apache.activemq.artemis.cli.commands.Action; import org.apache.activemq.artemis.cli.commands.ActionContext; -import org.apache.activemq.artemis.cli.commands.Browse; -import org.apache.activemq.artemis.cli.commands.Consumer; +import org.apache.activemq.artemis.cli.commands.messages.Browse; +import org.apache.activemq.artemis.cli.commands.messages.Consumer; import org.apache.activemq.artemis.cli.commands.Create; -import org.apache.activemq.artemis.cli.commands.CreateDestination; -import org.apache.activemq.artemis.cli.commands.DeleteDestination; +import org.apache.activemq.artemis.cli.commands.destination.CreateDestination; +import org.apache.activemq.artemis.cli.commands.destination.DeleteDestination; import org.apache.activemq.artemis.cli.commands.HelpAction; -import org.apache.activemq.artemis.cli.commands.HelpDestination; +import org.apache.activemq.artemis.cli.commands.destination.HelpDestination; import org.apache.activemq.artemis.cli.commands.Kill; -import org.apache.activemq.artemis.cli.commands.Producer; +import org.apache.activemq.artemis.cli.commands.messages.Producer; import org.apache.activemq.artemis.cli.commands.Run; import org.apache.activemq.artemis.cli.commands.Stop; import org.apache.activemq.artemis.cli.commands.tools.CompactJournal; @@ -124,6 +124,7 @@ public class Artemis { builder.withGroup("destination").withDescription("Destination tools group (create|delete) (example ./artemis destination create)"). withDefaultCommand(HelpDestination.class).withCommands(CreateDestination.class, DeleteDestination.class); + if (instance != null) { builder.withGroup("data").withDescription("data tools group (print|exp|imp|exp|encode|decode|compact) (example ./artemis data print)"). withDefaultCommand(HelpData.class).withCommands(PrintData.class, XmlDataExporter.class, XmlDataImporter.class, DecodeJournal.class, EncodeJournal.class, CompactJournal.class); http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/ActionAbstract.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/ActionAbstract.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/ActionAbstract.java index 43b1b3e..431f2ab 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/ActionAbstract.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/ActionAbstract.java @@ -23,7 +23,7 @@ import io.airlift.airline.Option; public abstract class ActionAbstract implements Action { @Option(name = "--verbose", description = "Adds more information on the execution") - boolean verbose; + public boolean verbose; private String brokerInstance; http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Browse.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Browse.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Browse.java deleted file mode 100644 index 65eac0d..0000000 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Browse.java +++ /dev/null @@ -1,77 +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 org.apache.activemq.artemis.cli.commands; - -import io.airlift.airline.Command; -import io.airlift.airline.Option; -import org.apache.activemq.artemis.cli.commands.util.ConsumerThread; -import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; -import org.apache.activemq.artemis.jms.client.ActiveMQDestination; - -import javax.jms.Connection; -import javax.jms.Destination; -import javax.jms.Session; - -@Command(name = "browser", description = "It will send consume messages from an instance") -public class Browse extends DestAbstract { - - @Option(name = "--filter", description = "filter to be used with the consumer") - String filter; - - @Override - public Object execute(ActionContext context) throws Exception { - super.execute(context); - - System.out.println("Consumer:: filter = " + filter); - - ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password); - - Destination dest = ActiveMQDestination.createDestination(this.destination, ActiveMQDestination.QUEUE_TYPE); - try (Connection connection = factory.createConnection()) { - ConsumerThread[] threadsArray = new ConsumerThread[threads]; - for (int i = 0; i < threads; i++) { - Session session; - if (txBatchSize > 0) { - session = connection.createSession(true, Session.SESSION_TRANSACTED); - } - else { - session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - } - threadsArray[i] = new ConsumerThread(session, dest, i); - - threadsArray[i].setVerbose(verbose).setSleep(sleep).setMessageCount(messageCount).setFilter(filter).setBrowse(true); - } - - for (ConsumerThread thread : threadsArray) { - thread.start(); - } - - connection.start(); - - int received = 0; - - for (ConsumerThread thread : threadsArray) { - thread.join(); - received += thread.getReceived(); - } - - return received; - } - } - -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Consumer.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Consumer.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Consumer.java deleted file mode 100644 index 7ef438b..0000000 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Consumer.java +++ /dev/null @@ -1,86 +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 org.apache.activemq.artemis.cli.commands; - -import javax.jms.Connection; -import javax.jms.Destination; -import javax.jms.Session; - -import io.airlift.airline.Command; -import io.airlift.airline.Option; -import org.apache.activemq.artemis.cli.commands.util.ConsumerThread; -import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; -import org.apache.activemq.artemis.jms.client.ActiveMQDestination; - -@Command(name = "consumer", description = "It will send consume messages from an instance") -public class Consumer extends DestAbstract { - - @Option(name = "--durable", description = "It will use durable subscription in case of client") - boolean durable = false; - - @Option(name = "--break-on-null", description = "It will break on null messages") - boolean breakOnNull = false; - - @Option(name = "--receive-timeout", description = "Time used on receive(timeout)") - int receiveTimeout = 3000; - - @Option(name = "--filter", description = "filter to be used with the consumer") - String filter; - - @Override - public Object execute(ActionContext context) throws Exception { - super.execute(context); - - System.out.println("Consumer:: filter = " + filter); - - ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password); - - Destination dest = ActiveMQDestination.createDestination(this.destination, ActiveMQDestination.QUEUE_TYPE); - try (Connection connection = factory.createConnection()) { - ConsumerThread[] threadsArray = new ConsumerThread[threads]; - for (int i = 0; i < threads; i++) { - Session session; - if (txBatchSize > 0) { - session = connection.createSession(true, Session.SESSION_TRANSACTED); - } - else { - session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - } - threadsArray[i] = new ConsumerThread(session, dest, i); - - threadsArray[i].setVerbose(verbose).setSleep(sleep).setDurable(durable).setBatchSize(txBatchSize).setBreakOnNull(breakOnNull).setMessageCount(messageCount).setReceiveTimeOut(receiveTimeout).setFilter(filter).setBrowse(false); - } - - for (ConsumerThread thread : threadsArray) { - thread.start(); - } - - connection.start(); - - int received = 0; - - for (ConsumerThread thread : threadsArray) { - thread.join(); - received += thread.getReceived(); - } - - return received; - } - } - -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/CreateDestination.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/CreateDestination.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/CreateDestination.java deleted file mode 100644 index b873a80..0000000 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/CreateDestination.java +++ /dev/null @@ -1,151 +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 org.apache.activemq.artemis.cli.commands; - -import io.airlift.airline.Command; -import io.airlift.airline.Option; -import org.apache.activemq.artemis.api.core.client.ClientMessage; -import org.apache.activemq.artemis.api.core.management.ManagementHelper; -import org.apache.activemq.artemis.api.jms.management.JMSManagementHelper; - -import javax.jms.Message; - -@Command(name = "create", description = "create a queue or topic") -public class CreateDestination extends DestinationAction { - - @Option(name = "--filter", description = "queue's filter string (default null)") - String filter = null; - - @Option(name = "--address", description = "address of the core queue (default queue's name)") - String address; - - @Option(name = "--durable", description = "whether the queue is durable or not (default false)") - boolean durable = false; - - @Option(name = "--bindings", description = "comma separated jndi binding names (default null)") - String bindings = null; - - @Override - public Object execute(ActionContext context) throws Exception { - super.execute(context); - - if (JMS_QUEUE.equals(destType)) { - createJmsQueue(context); - } - else if (CORE_QUEUE.equals(destType)) { - createCoreQueue(context); - } - else if (JMS_TOPIC.equals(destType)) { - createJmsTopic(context); - } - else { - throw new IllegalArgumentException("--type can only be one of " + JMS_QUEUE + ", " + JMS_TOPIC + " and " + CORE_QUEUE); - } - return null; - } - - private void createJmsTopic(final ActionContext context) throws Exception { - performJmsManagement(brokerURL, user, password, new ManagementCallback() { - @Override - public void setUpInvocation(Message message) throws Exception { - JMSManagementHelper.putOperationInvocation(message, "jms.server", "createTopic", name, bindings); - } - - @Override - public void requestSuccessful(Message reply) throws Exception { - boolean result = (boolean) JMSManagementHelper.getResult(reply, Boolean.class); - if (result) { - context.out.println("Topic " + name + " created successfully."); - } - else { - context.err.println("Failed to create topic " + name + "."); - } - } - - @Override - public void requestFailed(Message reply) throws Exception { - String errorMsg = (String) JMSManagementHelper.getResult(reply, String.class); - context.err.println("Failed to create topic " + name + ". Reason: " + errorMsg); - } - }); - } - - public String getAddress() { - if (address == null || "".equals(address.trim())) { - address = name; - } - return address.trim(); - } - - private void createCoreQueue(final ActionContext context) throws Exception { - performCoreManagement(brokerURL, user, password, new ManagementCallback() { - @Override - public void setUpInvocation(ClientMessage message) throws Exception { - String address = getAddress(); - ManagementHelper.putOperationInvocation(message, "core.server", "createQueue", address, name, filter, durable); - } - - @Override - public void requestSuccessful(ClientMessage reply) throws Exception { - context.out.println("Core queue " + name + " created successfully."); - } - - @Override - public void requestFailed(ClientMessage reply) throws Exception { - String errMsg = (String) ManagementHelper.getResult(reply, String.class); - context.err.println("Failed to create queue " + name + ". Reason: " + errMsg); - } - }); - } - - private void createJmsQueue(final ActionContext context) throws Exception { - - performJmsManagement(brokerURL, user, password, new ManagementCallback() { - - @Override - public void setUpInvocation(Message message) throws Exception { - JMSManagementHelper.putOperationInvocation(message, "jms.server", "createQueue", name, bindings, filter, durable); - } - - @Override - public void requestSuccessful(Message reply) throws Exception { - boolean result = (boolean) JMSManagementHelper.getResult(reply, Boolean.class); - if (result) { - context.out.println("Jms queue " + name + " created successfully."); - } - else { - context.err.println("Failed to create jms queue " + name + "."); - } - } - - @Override - public void requestFailed(Message reply) throws Exception { - String errorMsg = (String) JMSManagementHelper.getResult(reply, String.class); - context.err.println("Failed to create jms queue " + name + ". Reason: " + errorMsg); - } - }); - } - - public void setFilter(String filter) { - this.filter = filter; - } - - public void setBindings(String bindings) { - this.bindings = bindings; - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DeleteDestination.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DeleteDestination.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DeleteDestination.java deleted file mode 100644 index 8653d45..0000000 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DeleteDestination.java +++ /dev/null @@ -1,125 +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 org.apache.activemq.artemis.cli.commands; - -import io.airlift.airline.Command; -import io.airlift.airline.Option; -import org.apache.activemq.artemis.api.core.client.ClientMessage; -import org.apache.activemq.artemis.api.core.management.ManagementHelper; -import org.apache.activemq.artemis.api.jms.management.JMSManagementHelper; - -import javax.jms.Message; - -@Command(name = "delete", description = "delete a queue or topic") -public class DeleteDestination extends DestinationAction { - - @Option(name = "--removeConsumers", description = "whether deleting destination with consumers or not (default false)") - boolean removeConsumers = false; - - @Override - public Object execute(ActionContext context) throws Exception { - super.execute(context); - - if (JMS_QUEUE.equals(destType)) { - deleteJmsQueue(context); - } - else if (CORE_QUEUE.equals(destType)) { - deleteCoreQueue(context); - } - else if (JMS_TOPIC.equals(destType)) { - deleteJmsTopic(context); - } - else { - throw new IllegalArgumentException("--type can only be one of " + JMS_QUEUE + ", " + JMS_TOPIC + " and " + CORE_QUEUE); - } - return null; - } - - private void deleteJmsTopic(final ActionContext context) throws Exception { - performJmsManagement(brokerURL, user, password, new ManagementCallback() { - @Override - public void setUpInvocation(Message message) throws Exception { - JMSManagementHelper.putOperationInvocation(message, "jms.server", "destroyTopic", name, removeConsumers); - } - - @Override - public void requestSuccessful(Message reply) throws Exception { - boolean result = (boolean) JMSManagementHelper.getResult(reply, Boolean.class); - if (result) { - context.out.println("Topic " + name + " deleted successfully."); - } - else { - context.err.println("Failed to delete topic " + name); - } - } - - @Override - public void requestFailed(Message reply) throws Exception { - String errorMsg = (String) JMSManagementHelper.getResult(reply, String.class); - context.err.println("Failed to delete topic " + name + ". Reason: " + errorMsg); - } - }); - } - - private void deleteJmsQueue(final ActionContext context) throws Exception { - performJmsManagement(brokerURL, user, password, new ManagementCallback() { - @Override - public void setUpInvocation(Message message) throws Exception { - JMSManagementHelper.putOperationInvocation(message, "jms.server", "destroyQueue", name, removeConsumers); - } - - @Override - public void requestSuccessful(Message reply) throws Exception { - boolean result = (boolean) JMSManagementHelper.getResult(reply, Boolean.class); - if (result) { - context.out.println("Jms queue " + name + " deleted successfully."); - } - else { - context.err.println("Failed to delete queue " + name); - } - } - - @Override - public void requestFailed(Message reply) throws Exception { - String errorMsg = (String) JMSManagementHelper.getResult(reply, String.class); - context.err.println("Failed to create " + name + " with reason: " + errorMsg); - } - }); - } - - private void deleteCoreQueue(final ActionContext context) throws Exception { - performCoreManagement(brokerURL, user, password, new ManagementCallback() { - @Override - public void setUpInvocation(ClientMessage message) throws Exception { - ManagementHelper.putOperationInvocation(message, "core.server", "destroyQueue", name); - } - - @Override - public void requestSuccessful(ClientMessage reply) throws Exception { - context.out.println("Queue " + name + " deleted successfully."); - } - - @Override - public void requestFailed(ClientMessage reply) throws Exception { - String errMsg = (String) ManagementHelper.getResult(reply, String.class); - context.err.println("Failed to delete queue " + name + ". Reason: " + errMsg); - } - }); - } - -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DestAbstract.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DestAbstract.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DestAbstract.java deleted file mode 100644 index 0733966..0000000 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DestAbstract.java +++ /dev/null @@ -1,48 +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 org.apache.activemq.artemis.cli.commands; - -import io.airlift.airline.Option; - -public class DestAbstract extends ActionAbstract { - - @Option(name = "--url", description = "URL towards the broker. (default: tcp://localhost:61616)") - String brokerURL = "tcp://localhost:61616"; - - @Option(name = "--destination", description = "Destination to be used. it could be prefixed with queue:// or topic:: (Default: queue://TEST") - String destination = "queue://TEST"; - - @Option(name = "--message-count", description = "Number of messages to act on (Default: 1000)") - int messageCount = 1000; - - @Option(name = "--user", description = "User used to connect") - String user; - - @Option(name = "--password", description = "Password used to connect") - String password; - - @Option(name = "--sleep", description = "Time wait between each message") - int sleep = 0; - - @Option(name = "--txt-size", description = "TX Batch Size") - int txBatchSize; - - @Option(name = "--threads", description = "Number of Threads to be used (Default: 1)") - int threads = 1; - -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DestinationAction.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DestinationAction.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DestinationAction.java deleted file mode 100644 index 435d325..0000000 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/DestinationAction.java +++ /dev/null @@ -1,142 +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 org.apache.activemq.artemis.cli.commands; - -import io.airlift.airline.Option; -import org.apache.activemq.artemis.api.core.client.ActiveMQClient; -import org.apache.activemq.artemis.api.core.client.ClientMessage; -import org.apache.activemq.artemis.api.core.client.ClientRequestor; -import org.apache.activemq.artemis.api.core.client.ClientSession; -import org.apache.activemq.artemis.api.core.client.ClientSessionFactory; -import org.apache.activemq.artemis.api.core.client.ServerLocator; -import org.apache.activemq.artemis.api.core.management.ManagementHelper; -import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; -import org.apache.activemq.artemis.api.jms.management.JMSManagementHelper; -import org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl; -import org.apache.activemq.artemis.jms.client.ActiveMQConnection; -import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; -import org.apache.activemq.artemis.jms.client.ActiveMQSession; - -import javax.jms.Message; -import javax.jms.Queue; -import javax.jms.QueueRequestor; -import javax.jms.Session; - -public abstract class DestinationAction extends ActionAbstract { - - public static final String JMS_QUEUE = "jms-queue"; - public static final String JMS_TOPIC = "topic"; - public static final String CORE_QUEUE = "core-queue"; - - @Option(name = "--type", description = "type of destination to be created (one of jms-queue, topic and core-queue, default jms-queue") - String destType = JMS_QUEUE; - - @Option(name = "--url", description = "URL towards the broker. (default: tcp://localhost:61616)") - String brokerURL = "tcp://localhost:61616"; - - @Option(name = "--user", description = "User used to connect") - String user; - - @Option(name = "--password", description = "Password used to connect") - String password; - - @Option(name = "--name", description = "destination name", required = true) - String name; - - public static void performJmsManagement(String brokerURL, String user, String password, ManagementCallback cb) throws Exception { - - ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password); - ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection(); - ActiveMQSession session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - Queue managementQueue = ActiveMQJMSClient.createQueue("activemq.management"); - QueueRequestor requestor = new QueueRequestor(session, managementQueue); - - try { - connection.start(); - - Message message = session.createMessage(); - - cb.setUpInvocation(message); - - Message reply = requestor.request(message); - - boolean result = JMSManagementHelper.hasOperationSucceeded(reply); - - if (result) { - cb.requestSuccessful(reply); - } - else { - cb.requestFailed(reply); - } - } - finally { - connection.close(); - } - } - - public static void performCoreManagement(String brokerURL, String user, String password, ManagementCallback cb) throws Exception { - - ServerLocator locator = ServerLocatorImpl.newLocator(brokerURL); - ClientSessionFactory sessionFactory = locator.createSessionFactory(); - ClientSession session = sessionFactory.createSession(user, password, false, true, true, false, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE); - - try { - session.start(); - ClientRequestor requestor = new ClientRequestor(session, "jms.queue.activemq.management"); - ClientMessage message = session.createMessage(false); - - cb.setUpInvocation(message); - - ClientMessage reply = requestor.request(message); - - if (ManagementHelper.hasOperationSucceeded(reply)) { - cb.requestSuccessful(reply); - } - else { - cb.requestFailed(reply); - } - } - finally { - session.close(); - sessionFactory.close(); - } - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public String getDestType() { - return destType; - } - - public void setDestType(String destType) { - this.destType = destType; - } - - public interface ManagementCallback { - void setUpInvocation(T message) throws Exception; - - void requestSuccessful(T reply) throws Exception; - - void requestFailed(T reply) throws Exception; - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/HelpDestination.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/HelpDestination.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/HelpDestination.java deleted file mode 100644 index 4554803..0000000 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/HelpDestination.java +++ /dev/null @@ -1,54 +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 org.apache.activemq.artemis.cli.commands; - -import io.airlift.airline.Help; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -public class HelpDestination extends Help implements Action { - - @Override - public boolean isVerbose() { - return false; - } - - @Override - public void setHomeValues(File brokerHome, File brokerInstance) { - } - - @Override - public String getBrokerInstance() { - return null; - } - - @Override - public String getBrokerHome() { - return null; - } - - @Override - public Object execute(ActionContext context) throws Exception { - List commands = new ArrayList<>(1); - commands.add("destination"); - help(global, commands); - return null; - } -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Producer.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Producer.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Producer.java deleted file mode 100644 index f1b5889..0000000 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Producer.java +++ /dev/null @@ -1,87 +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 org.apache.activemq.artemis.cli.commands; - -import javax.jms.Connection; -import javax.jms.Destination; -import javax.jms.Session; - -import io.airlift.airline.Command; -import io.airlift.airline.Option; -import org.apache.activemq.artemis.cli.commands.util.ProducerThread; -import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; -import org.apache.activemq.artemis.jms.client.ActiveMQDestination; - -@Command(name = "producer", description = "It will send messages to an instance") -public class Producer extends DestAbstract { - - @Option(name = "--non-persistent", description = "It will send messages non persistently") - boolean nonpersistent = false; - - @Option(name = "--message-size", description = "Size of each byteMessage (The producer will use byte message on this case)") - int messageSize = 0; - - @Option(name = "--text-size", description = "Size of each textNessage (The producer will use text message on this case)") - int textMessageSize; - - @Option(name = "--msgttl", description = "TTL for each message") - long msgTTL = 0L; - - @Option(name = "--group", description = "Message Group to be used") - String msgGroupID = null; - - @Override - public Object execute(ActionContext context) throws Exception { - super.execute(context); - - ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password); - - Destination dest = ActiveMQDestination.createDestination(this.destination, ActiveMQDestination.QUEUE_TYPE); - try (Connection connection = factory.createConnection()) { - ProducerThread[] threadsArray = new ProducerThread[threads]; - for (int i = 0; i < threads; i++) { - Session session; - if (txBatchSize > 0) { - session = connection.createSession(true, Session.SESSION_TRANSACTED); - } - else { - session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - } - threadsArray[i] = new ProducerThread(session, dest, i); - - threadsArray[i].setVerbose(verbose).setSleep(sleep).setPersistent(!nonpersistent). - setMessageSize(messageSize).setTextMessageSize(textMessageSize). - setMsgTTL(msgTTL).setMsgGroupID(msgGroupID).setTransactionBatchSize(txBatchSize). - setMessageCount(messageCount); - } - - for (ProducerThread thread : threadsArray) { - thread.start(); - } - - int messagesProduced = 0; - for (ProducerThread thread : threadsArray) { - thread.join(); - messagesProduced += thread.getSentCount(); - } - - return messagesProduced; - } - } - -} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/CreateDestination.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/CreateDestination.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/CreateDestination.java new file mode 100644 index 0000000..985ef14 --- /dev/null +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/CreateDestination.java @@ -0,0 +1,152 @@ +/* + * 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.activemq.artemis.cli.commands.destination; + +import io.airlift.airline.Command; +import io.airlift.airline.Option; +import org.apache.activemq.artemis.api.core.client.ClientMessage; +import org.apache.activemq.artemis.api.core.management.ManagementHelper; +import org.apache.activemq.artemis.api.jms.management.JMSManagementHelper; +import org.apache.activemq.artemis.cli.commands.ActionContext; + +import javax.jms.Message; + +@Command(name = "create", description = "create a queue or topic") +public class CreateDestination extends DestinationAction { + + @Option(name = "--filter", description = "queue's filter string (default null)") + String filter = null; + + @Option(name = "--address", description = "address of the core queue (default queue's name)") + String address; + + @Option(name = "--durable", description = "whether the queue is durable or not (default false)") + boolean durable = false; + + @Option(name = "--bindings", description = "comma separated jndi binding names (default null)") + String bindings = null; + + @Override + public Object execute(ActionContext context) throws Exception { + super.execute(context); + + if (JMS_QUEUE.equals(destType)) { + createJmsQueue(context); + } + else if (CORE_QUEUE.equals(destType)) { + createCoreQueue(context); + } + else if (JMS_TOPIC.equals(destType)) { + createJmsTopic(context); + } + else { + throw new IllegalArgumentException("--type can only be one of " + JMS_QUEUE + ", " + JMS_TOPIC + " and " + CORE_QUEUE); + } + return null; + } + + private void createJmsTopic(final ActionContext context) throws Exception { + performJmsManagement(brokerURL, user, password, new ManagementCallback() { + @Override + public void setUpInvocation(Message message) throws Exception { + JMSManagementHelper.putOperationInvocation(message, "jms.server", "createTopic", getName(), bindings); + } + + @Override + public void requestSuccessful(Message reply) throws Exception { + boolean result = (boolean) JMSManagementHelper.getResult(reply, Boolean.class); + if (result) { + context.out.println("Topic " + getName() + " created successfully."); + } + else { + context.err.println("Failed to create topic " + getName() + "."); + } + } + + @Override + public void requestFailed(Message reply) throws Exception { + String errorMsg = (String) JMSManagementHelper.getResult(reply, String.class); + context.err.println("Failed to create topic " + getName() + ". Reason: " + errorMsg); + } + }); + } + + public String getAddress() { + if (address == null || "".equals(address.trim())) { + address = getName(); + } + return address.trim(); + } + + private void createCoreQueue(final ActionContext context) throws Exception { + performCoreManagement(brokerURL, user, password, new ManagementCallback() { + @Override + public void setUpInvocation(ClientMessage message) throws Exception { + String address = getAddress(); + ManagementHelper.putOperationInvocation(message, "core.server", "createQueue", address, getName(), filter, durable); + } + + @Override + public void requestSuccessful(ClientMessage reply) throws Exception { + context.out.println("Core queue " + getName() + " created successfully."); + } + + @Override + public void requestFailed(ClientMessage reply) throws Exception { + String errMsg = (String) ManagementHelper.getResult(reply, String.class); + context.err.println("Failed to create queue " + getName() + ". Reason: " + errMsg); + } + }); + } + + private void createJmsQueue(final ActionContext context) throws Exception { + + performJmsManagement(brokerURL, user, password, new ManagementCallback() { + + @Override + public void setUpInvocation(Message message) throws Exception { + JMSManagementHelper.putOperationInvocation(message, "jms.server", "createQueue", getName(), bindings, filter, durable); + } + + @Override + public void requestSuccessful(Message reply) throws Exception { + boolean result = (boolean) JMSManagementHelper.getResult(reply, Boolean.class); + if (result) { + context.out.println("Jms queue " + getName() + " created successfully."); + } + else { + context.err.println("Failed to create jms queue " + getName() + "."); + } + } + + @Override + public void requestFailed(Message reply) throws Exception { + String errorMsg = (String) JMSManagementHelper.getResult(reply, String.class); + context.err.println("Failed to create jms queue " + getName() + ". Reason: " + errorMsg); + } + }); + } + + public void setFilter(String filter) { + this.filter = filter; + } + + public void setBindings(String bindings) { + this.bindings = bindings; + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DeleteDestination.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DeleteDestination.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DeleteDestination.java new file mode 100644 index 0000000..9b2bc49 --- /dev/null +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DeleteDestination.java @@ -0,0 +1,126 @@ +/* + * 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.activemq.artemis.cli.commands.destination; + +import io.airlift.airline.Command; +import io.airlift.airline.Option; +import org.apache.activemq.artemis.api.core.client.ClientMessage; +import org.apache.activemq.artemis.api.core.management.ManagementHelper; +import org.apache.activemq.artemis.api.jms.management.JMSManagementHelper; +import org.apache.activemq.artemis.cli.commands.ActionContext; + +import javax.jms.Message; + +@Command(name = "delete", description = "delete a queue or topic") +public class DeleteDestination extends DestinationAction { + + @Option(name = "--removeConsumers", description = "whether deleting destination with consumers or not (default false)") + boolean removeConsumers = false; + + @Override + public Object execute(ActionContext context) throws Exception { + super.execute(context); + + if (JMS_QUEUE.equals(destType)) { + deleteJmsQueue(context); + } + else if (CORE_QUEUE.equals(destType)) { + deleteCoreQueue(context); + } + else if (JMS_TOPIC.equals(destType)) { + deleteJmsTopic(context); + } + else { + throw new IllegalArgumentException("--type can only be one of " + JMS_QUEUE + ", " + JMS_TOPIC + " and " + CORE_QUEUE); + } + return null; + } + + private void deleteJmsTopic(final ActionContext context) throws Exception { + performJmsManagement(brokerURL, user, password, new ManagementCallback() { + @Override + public void setUpInvocation(Message message) throws Exception { + JMSManagementHelper.putOperationInvocation(message, "jms.server", "destroyTopic", getName(), removeConsumers); + } + + @Override + public void requestSuccessful(Message reply) throws Exception { + boolean result = (boolean) JMSManagementHelper.getResult(reply, Boolean.class); + if (result) { + context.out.println("Topic " + getName() + " deleted successfully."); + } + else { + context.err.println("Failed to delete topic " + getName()); + } + } + + @Override + public void requestFailed(Message reply) throws Exception { + String errorMsg = (String) JMSManagementHelper.getResult(reply, String.class); + context.err.println("Failed to delete topic " + getName() + ". Reason: " + errorMsg); + } + }); + } + + private void deleteJmsQueue(final ActionContext context) throws Exception { + performJmsManagement(brokerURL, user, password, new ManagementCallback() { + @Override + public void setUpInvocation(Message message) throws Exception { + JMSManagementHelper.putOperationInvocation(message, "jms.server", "destroyQueue", getName(), removeConsumers); + } + + @Override + public void requestSuccessful(Message reply) throws Exception { + boolean result = (boolean) JMSManagementHelper.getResult(reply, Boolean.class); + if (result) { + context.out.println("Jms queue " + getName() + " deleted successfully."); + } + else { + context.err.println("Failed to delete queue " + getName()); + } + } + + @Override + public void requestFailed(Message reply) throws Exception { + String errorMsg = (String) JMSManagementHelper.getResult(reply, String.class); + context.err.println("Failed to create " + getName() + " with reason: " + errorMsg); + } + }); + } + + private void deleteCoreQueue(final ActionContext context) throws Exception { + performCoreManagement(brokerURL, user, password, new ManagementCallback() { + @Override + public void setUpInvocation(ClientMessage message) throws Exception { + ManagementHelper.putOperationInvocation(message, "core.server", "destroyQueue", getName()); + } + + @Override + public void requestSuccessful(ClientMessage reply) throws Exception { + context.out.println("Queue " + getName() + " deleted successfully."); + } + + @Override + public void requestFailed(ClientMessage reply) throws Exception { + String errMsg = (String) ManagementHelper.getResult(reply, String.class); + context.err.println("Failed to delete queue " + getName() + ". Reason: " + errMsg); + } + }); + } + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DestinationAction.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DestinationAction.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DestinationAction.java new file mode 100644 index 0000000..ffce4d4 --- /dev/null +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/DestinationAction.java @@ -0,0 +1,139 @@ +/* + * 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.activemq.artemis.cli.commands.destination; + +import io.airlift.airline.Option; +import org.apache.activemq.artemis.api.core.client.ActiveMQClient; +import org.apache.activemq.artemis.api.core.client.ClientMessage; +import org.apache.activemq.artemis.api.core.client.ClientRequestor; +import org.apache.activemq.artemis.api.core.client.ClientSession; +import org.apache.activemq.artemis.api.core.client.ClientSessionFactory; +import org.apache.activemq.artemis.api.core.client.ServerLocator; +import org.apache.activemq.artemis.api.core.management.ManagementHelper; +import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient; +import org.apache.activemq.artemis.api.jms.management.JMSManagementHelper; +import org.apache.activemq.artemis.cli.commands.InputAbstract; +import org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl; +import org.apache.activemq.artemis.jms.client.ActiveMQConnection; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.jms.client.ActiveMQSession; + +import javax.jms.Message; +import javax.jms.Queue; +import javax.jms.QueueRequestor; +import javax.jms.Session; + +public abstract class DestinationAction extends InputAbstract { + + public static final String JMS_QUEUE = "jms-queue"; + public static final String JMS_TOPIC = "topic"; + public static final String CORE_QUEUE = "core-queue"; + + @Option(name = "--type", description = "type of destination to be created (one of jms-queue, topic and core-queue, default jms-queue") + String destType = JMS_QUEUE; + + @Option(name = "--url", description = "URL towards the broker. (default: tcp://localhost:61616)") + String brokerURL = "tcp://localhost:61616"; + + @Option(name = "--user", description = "User used to connect") + String user; + + @Option(name = "--password", description = "Password used to connect") + String password; + + @Option(name = "--name", description = "destination name") + String name; + + public static void performJmsManagement(String brokerURL, String user, String password, ManagementCallback cb) throws Exception { + + try (ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password); + ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection(); + ActiveMQSession session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) { + + Queue managementQueue = ActiveMQJMSClient.createQueue("activemq.management"); + QueueRequestor requestor = new QueueRequestor(session, managementQueue); + + connection.start(); + + Message message = session.createMessage(); + + cb.setUpInvocation(message); + + Message reply = requestor.request(message); + + boolean result = JMSManagementHelper.hasOperationSucceeded(reply); + + if (result) { + cb.requestSuccessful(reply); + } + else { + cb.requestFailed(reply); + } + } + } + + public static void performCoreManagement(String brokerURL, String user, String password, ManagementCallback cb) throws Exception { + + + try (ServerLocator locator = ServerLocatorImpl.newLocator(brokerURL); + ClientSessionFactory sessionFactory = locator.createSessionFactory(); + ClientSession session = sessionFactory.createSession(user, password, false, true, true, false, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE)) { + session.start(); + ClientRequestor requestor = new ClientRequestor(session, "jms.queue.activemq.management"); + ClientMessage message = session.createMessage(false); + + cb.setUpInvocation(message); + + ClientMessage reply = requestor.request(message); + + if (ManagementHelper.hasOperationSucceeded(reply)) { + cb.requestSuccessful(reply); + } + else { + cb.requestFailed(reply); + } + } + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + if (name == null) { + name = input("--name", "Please provide the destination name:", ""); + } + + return name; + } + + public String getDestType() { + return destType; + } + + public void setDestType(String destType) { + this.destType = destType; + } + + public interface ManagementCallback { + void setUpInvocation(T message) throws Exception; + + void requestSuccessful(T reply) throws Exception; + + void requestFailed(T reply) throws Exception; + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/HelpDestination.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/HelpDestination.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/HelpDestination.java new file mode 100644 index 0000000..b9d9d73 --- /dev/null +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/destination/HelpDestination.java @@ -0,0 +1,56 @@ +/* + * 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.activemq.artemis.cli.commands.destination; + +import io.airlift.airline.Help; +import org.apache.activemq.artemis.cli.commands.Action; +import org.apache.activemq.artemis.cli.commands.ActionContext; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +public class HelpDestination extends Help implements Action { + + @Override + public boolean isVerbose() { + return false; + } + + @Override + public void setHomeValues(File brokerHome, File brokerInstance) { + } + + @Override + public String getBrokerInstance() { + return null; + } + + @Override + public String getBrokerHome() { + return null; + } + + @Override + public Object execute(ActionContext context) throws Exception { + List commands = new ArrayList<>(1); + commands.add("destination"); + help(global, commands); + return null; + } +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Browse.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Browse.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Browse.java new file mode 100644 index 0000000..dbd0913 --- /dev/null +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Browse.java @@ -0,0 +1,78 @@ +/* + * 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.activemq.artemis.cli.commands.messages; + +import io.airlift.airline.Command; +import io.airlift.airline.Option; +import org.apache.activemq.artemis.cli.commands.ActionContext; +import org.apache.activemq.artemis.cli.commands.util.ConsumerThread; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.jms.client.ActiveMQDestination; + +import javax.jms.Connection; +import javax.jms.Destination; +import javax.jms.Session; + +@Command(name = "browser", description = "It will send consume messages from an instance") +public class Browse extends DestAbstract { + + @Option(name = "--filter", description = "filter to be used with the consumer") + String filter; + + @Override + public Object execute(ActionContext context) throws Exception { + super.execute(context); + + System.out.println("Consumer:: filter = " + filter); + + ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password); + + Destination dest = ActiveMQDestination.createDestination(this.destination, ActiveMQDestination.QUEUE_TYPE); + try (Connection connection = factory.createConnection()) { + ConsumerThread[] threadsArray = new ConsumerThread[threads]; + for (int i = 0; i < threads; i++) { + Session session; + if (txBatchSize > 0) { + session = connection.createSession(true, Session.SESSION_TRANSACTED); + } + else { + session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + } + threadsArray[i] = new ConsumerThread(session, dest, i); + + threadsArray[i].setVerbose(verbose).setSleep(sleep).setMessageCount(messageCount).setFilter(filter).setBrowse(true); + } + + for (ConsumerThread thread : threadsArray) { + thread.start(); + } + + connection.start(); + + int received = 0; + + for (ConsumerThread thread : threadsArray) { + thread.join(); + received += thread.getReceived(); + } + + return received; + } + } + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Consumer.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Consumer.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Consumer.java new file mode 100644 index 0000000..dee8475 --- /dev/null +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Consumer.java @@ -0,0 +1,87 @@ +/* + * 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.activemq.artemis.cli.commands.messages; + +import javax.jms.Connection; +import javax.jms.Destination; +import javax.jms.Session; + +import io.airlift.airline.Command; +import io.airlift.airline.Option; +import org.apache.activemq.artemis.cli.commands.ActionContext; +import org.apache.activemq.artemis.cli.commands.util.ConsumerThread; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.jms.client.ActiveMQDestination; + +@Command(name = "consumer", description = "It will send consume messages from an instance") +public class Consumer extends DestAbstract { + + @Option(name = "--durable", description = "It will use durable subscription in case of client") + boolean durable = false; + + @Option(name = "--break-on-null", description = "It will break on null messages") + boolean breakOnNull = false; + + @Option(name = "--receive-timeout", description = "Time used on receive(timeout)") + int receiveTimeout = 3000; + + @Option(name = "--filter", description = "filter to be used with the consumer") + String filter; + + @Override + public Object execute(ActionContext context) throws Exception { + super.execute(context); + + System.out.println("Consumer:: filter = " + filter); + + ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password); + + Destination dest = ActiveMQDestination.createDestination(this.destination, ActiveMQDestination.QUEUE_TYPE); + try (Connection connection = factory.createConnection()) { + ConsumerThread[] threadsArray = new ConsumerThread[threads]; + for (int i = 0; i < threads; i++) { + Session session; + if (txBatchSize > 0) { + session = connection.createSession(true, Session.SESSION_TRANSACTED); + } + else { + session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + } + threadsArray[i] = new ConsumerThread(session, dest, i); + + threadsArray[i].setVerbose(verbose).setSleep(sleep).setDurable(durable).setBatchSize(txBatchSize).setBreakOnNull(breakOnNull).setMessageCount(messageCount).setReceiveTimeOut(receiveTimeout).setFilter(filter).setBrowse(false); + } + + for (ConsumerThread thread : threadsArray) { + thread.start(); + } + + connection.start(); + + int received = 0; + + for (ConsumerThread thread : threadsArray) { + thread.join(); + received += thread.getReceived(); + } + + return received; + } + } + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/DestAbstract.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/DestAbstract.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/DestAbstract.java new file mode 100644 index 0000000..1e3ac11 --- /dev/null +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/DestAbstract.java @@ -0,0 +1,49 @@ +/* + * 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.activemq.artemis.cli.commands.messages; + +import io.airlift.airline.Option; +import org.apache.activemq.artemis.cli.commands.ActionAbstract; + +public class DestAbstract extends ActionAbstract { + + @Option(name = "--url", description = "URL towards the broker. (default: tcp://localhost:61616)") + String brokerURL = "tcp://localhost:61616"; + + @Option(name = "--destination", description = "Destination to be used. it could be prefixed with queue:// or topic:: (Default: queue://TEST") + String destination = "queue://TEST"; + + @Option(name = "--message-count", description = "Number of messages to act on (Default: 1000)") + int messageCount = 1000; + + @Option(name = "--user", description = "User used to connect") + String user; + + @Option(name = "--password", description = "Password used to connect") + String password; + + @Option(name = "--sleep", description = "Time wait between each message") + int sleep = 0; + + @Option(name = "--txt-size", description = "TX Batch Size") + int txBatchSize; + + @Option(name = "--threads", description = "Number of Threads to be used (Default: 1)") + int threads = 1; + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Producer.java ---------------------------------------------------------------------- diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Producer.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Producer.java new file mode 100644 index 0000000..ea3b088 --- /dev/null +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/messages/Producer.java @@ -0,0 +1,88 @@ +/* + * 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.activemq.artemis.cli.commands.messages; + +import javax.jms.Connection; +import javax.jms.Destination; +import javax.jms.Session; + +import io.airlift.airline.Command; +import io.airlift.airline.Option; +import org.apache.activemq.artemis.cli.commands.ActionContext; +import org.apache.activemq.artemis.cli.commands.util.ProducerThread; +import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.jms.client.ActiveMQDestination; + +@Command(name = "producer", description = "It will send messages to an instance") +public class Producer extends DestAbstract { + + @Option(name = "--non-persistent", description = "It will send messages non persistently") + boolean nonpersistent = false; + + @Option(name = "--message-size", description = "Size of each byteMessage (The producer will use byte message on this case)") + int messageSize = 0; + + @Option(name = "--text-size", description = "Size of each textNessage (The producer will use text message on this case)") + int textMessageSize; + + @Option(name = "--msgttl", description = "TTL for each message") + long msgTTL = 0L; + + @Option(name = "--group", description = "Message Group to be used") + String msgGroupID = null; + + @Override + public Object execute(ActionContext context) throws Exception { + super.execute(context); + + ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password); + + Destination dest = ActiveMQDestination.createDestination(this.destination, ActiveMQDestination.QUEUE_TYPE); + try (Connection connection = factory.createConnection()) { + ProducerThread[] threadsArray = new ProducerThread[threads]; + for (int i = 0; i < threads; i++) { + Session session; + if (txBatchSize > 0) { + session = connection.createSession(true, Session.SESSION_TRANSACTED); + } + else { + session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + } + threadsArray[i] = new ProducerThread(session, dest, i); + + threadsArray[i].setVerbose(verbose).setSleep(sleep).setPersistent(!nonpersistent). + setMessageSize(messageSize).setTextMessageSize(textMessageSize). + setMsgTTL(msgTTL).setMsgGroupID(msgGroupID).setTransactionBatchSize(txBatchSize). + setMessageCount(messageCount); + } + + for (ProducerThread thread : threadsArray) { + thread.start(); + } + + int messagesProduced = 0; + for (ProducerThread thread : threadsArray) { + thread.join(); + messagesProduced += thread.getSentCount(); + } + + return messagesProduced; + } + } + +} http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/7d684956/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cli/DestinationCommandTest.java ---------------------------------------------------------------------- diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cli/DestinationCommandTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cli/DestinationCommandTest.java index 6b9d5ac..e499f38 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cli/DestinationCommandTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cli/DestinationCommandTest.java @@ -18,9 +18,9 @@ package org.apache.activemq.artemis.tests.integration.cli; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.cli.commands.ActionContext; -import org.apache.activemq.artemis.cli.commands.CreateDestination; -import org.apache.activemq.artemis.cli.commands.DeleteDestination; -import org.apache.activemq.artemis.cli.commands.DestinationAction; +import org.apache.activemq.artemis.cli.commands.destination.CreateDestination; +import org.apache.activemq.artemis.cli.commands.destination.DeleteDestination; +import org.apache.activemq.artemis.cli.commands.destination.DestinationAction; import org.apache.activemq.artemis.core.filter.Filter; import org.apache.activemq.artemis.core.postoffice.Binding; import org.apache.activemq.artemis.tests.util.JMSTestBase;