NO-JIRA small improvement on CLI, retry with user input
This commit is contained in:
parent
119476ddcc
commit
aa0965c0ca
|
@ -58,7 +58,7 @@ public class CreateDestination extends DestinationAction {
|
|||
}
|
||||
|
||||
private void createJmsTopic(final ActionContext context) throws Exception {
|
||||
performJmsManagement(brokerURL, user, password, new ManagementCallback<Message>() {
|
||||
performJmsManagement(new ManagementCallback<Message>() {
|
||||
@Override
|
||||
public void setUpInvocation(Message message) throws Exception {
|
||||
JMSManagementHelper.putOperationInvocation(message, "jms.server", "createTopic", getName(), bindings);
|
||||
|
@ -90,7 +90,7 @@ public class CreateDestination extends DestinationAction {
|
|||
}
|
||||
|
||||
private void createCoreQueue(final ActionContext context) throws Exception {
|
||||
performCoreManagement(brokerURL, user, password, new ManagementCallback<ClientMessage>() {
|
||||
performCoreManagement(new ManagementCallback<ClientMessage>() {
|
||||
@Override
|
||||
public void setUpInvocation(ClientMessage message) throws Exception {
|
||||
String address = getAddress();
|
||||
|
@ -112,7 +112,7 @@ public class CreateDestination extends DestinationAction {
|
|||
|
||||
private void createJmsQueue(final ActionContext context) throws Exception {
|
||||
|
||||
performJmsManagement(brokerURL, user, password, new ManagementCallback<Message>() {
|
||||
performJmsManagement(new ManagementCallback<Message>() {
|
||||
|
||||
@Override
|
||||
public void setUpInvocation(Message message) throws Exception {
|
||||
|
|
|
@ -49,7 +49,7 @@ public class DeleteDestination extends DestinationAction {
|
|||
}
|
||||
|
||||
private void deleteJmsTopic(final ActionContext context) throws Exception {
|
||||
performJmsManagement(brokerURL, user, password, new ManagementCallback<Message>() {
|
||||
performJmsManagement(new ManagementCallback<Message>() {
|
||||
@Override
|
||||
public void setUpInvocation(Message message) throws Exception {
|
||||
JMSManagementHelper.putOperationInvocation(message, "jms.server", "destroyTopic", getName(), removeConsumers);
|
||||
|
@ -74,7 +74,7 @@ public class DeleteDestination extends DestinationAction {
|
|||
}
|
||||
|
||||
private void deleteJmsQueue(final ActionContext context) throws Exception {
|
||||
performJmsManagement(brokerURL, user, password, new ManagementCallback<Message>() {
|
||||
performJmsManagement(new ManagementCallback<Message>() {
|
||||
@Override
|
||||
public void setUpInvocation(Message message) throws Exception {
|
||||
JMSManagementHelper.putOperationInvocation(message, "jms.server", "destroyQueue", getName(), removeConsumers);
|
||||
|
@ -99,7 +99,7 @@ public class DeleteDestination extends DestinationAction {
|
|||
}
|
||||
|
||||
private void deleteCoreQueue(final ActionContext context) throws Exception {
|
||||
performCoreManagement(brokerURL, user, password, new ManagementCallback<ClientMessage>() {
|
||||
performCoreManagement(new ManagementCallback<ClientMessage>() {
|
||||
@Override
|
||||
public void setUpInvocation(ClientMessage message) throws Exception {
|
||||
ManagementHelper.putOperationInvocation(message, "core.server", "destroyQueue", getName());
|
||||
|
|
|
@ -31,13 +31,12 @@ 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.cli.commands.messages.ConnectionAbstract;
|
||||
import org.apache.activemq.artemis.jms.client.ActiveMQConnection;
|
||||
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.artemis.jms.client.ActiveMQSession;
|
||||
|
||||
public abstract class DestinationAction extends InputAbstract {
|
||||
public abstract class DestinationAction extends ConnectionAbstract {
|
||||
|
||||
public static final String JMS_QUEUE = "jms-queue";
|
||||
public static final String JMS_TOPIC = "topic";
|
||||
|
@ -46,24 +45,12 @@ public abstract class DestinationAction extends InputAbstract {
|
|||
@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<Message> cb) throws Exception {
|
||||
public void performJmsManagement(ManagementCallback<Message> cb) throws Exception {
|
||||
|
||||
try (ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password);
|
||||
try (ActiveMQConnectionFactory factory = createConnectionFactory();
|
||||
ActiveMQConnection connection = (ActiveMQConnection) factory.createConnection();
|
||||
ActiveMQSession session = (ActiveMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
|
||||
|
||||
|
@ -88,12 +75,10 @@ public abstract class DestinationAction extends InputAbstract {
|
|||
}
|
||||
}
|
||||
|
||||
public static void performCoreManagement(String brokerURL,
|
||||
String user,
|
||||
String password,
|
||||
ManagementCallback<ClientMessage> cb) throws Exception {
|
||||
public void performCoreManagement(ManagementCallback<ClientMessage> cb) throws Exception {
|
||||
|
||||
try (ServerLocator locator = ServerLocatorImpl.newLocator(brokerURL);
|
||||
try (ActiveMQConnectionFactory factory = createConnectionFactory();
|
||||
ServerLocator locator = factory.getServerLocator();
|
||||
ClientSessionFactory sessionFactory = locator.createSessionFactory();
|
||||
ClientSession session = sessionFactory.createSession(user, password, false, true, true, false, ActiveMQClient.DEFAULT_ACK_BATCH_SIZE)) {
|
||||
session.start();
|
||||
|
|
|
@ -40,7 +40,7 @@ public class Browse extends DestAbstract {
|
|||
|
||||
System.out.println("Consumer:: filter = " + filter);
|
||||
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password);
|
||||
ActiveMQConnectionFactory factory = createConnectionFactory();
|
||||
|
||||
Destination dest = ActiveMQDestination.createDestination(this.destination, ActiveMQDestination.QUEUE_TYPE);
|
||||
try (Connection connection = factory.createConnection()) {
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* 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.JMSException;
|
||||
import javax.jms.JMSSecurityException;
|
||||
|
||||
import io.airlift.airline.Option;
|
||||
import org.apache.activemq.artemis.cli.commands.InputAbstract;
|
||||
import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
|
||||
|
||||
public class ConnectionAbstract extends InputAbstract {
|
||||
@Option(name = "--url", description = "URL towards the broker. (default: tcp://localhost:61616)")
|
||||
protected String brokerURL = "tcp://localhost:61616";
|
||||
|
||||
@Option(name = "--user", description = "User used to connect")
|
||||
protected String user;
|
||||
|
||||
@Option(name = "--password", description = "Password used to connect")
|
||||
protected String password;
|
||||
|
||||
|
||||
protected ActiveMQConnectionFactory createConnectionFactory() throws Exception {
|
||||
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(brokerURL, user, password);
|
||||
try {
|
||||
Connection connection = cf.createConnection();
|
||||
connection.close();
|
||||
return cf;
|
||||
} catch (JMSSecurityException e) {
|
||||
// if a security exception will get the user and password through an input
|
||||
context.err.println("Connection failed::" + e.getMessage());
|
||||
userPassword();
|
||||
return new ActiveMQConnectionFactory(brokerURL, user, password);
|
||||
} catch (JMSException e) {
|
||||
// if a connection exception will ask for the URL, user and password
|
||||
context.err.println("Connection failed::" + e.getMessage());
|
||||
brokerURL = input("--url", "Type in the broker URL for a retry (e.g. tcp://localhost:61616)", brokerURL);
|
||||
userPassword();
|
||||
return new ActiveMQConnectionFactory(brokerURL, user, password);
|
||||
}
|
||||
}
|
||||
|
||||
private void userPassword() {
|
||||
if (user == null) {
|
||||
user = input("--user", "Type the username for a retry", null);
|
||||
}
|
||||
if (password == null) {
|
||||
password = inputPassword("--password", "Type the password for a retry", null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -49,7 +49,7 @@ public class Consumer extends DestAbstract {
|
|||
|
||||
System.out.println("Consumer:: filter = " + filter);
|
||||
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password);
|
||||
ActiveMQConnectionFactory factory = createConnectionFactory();
|
||||
|
||||
Destination dest = ActiveMQDestination.createDestination(this.destination, ActiveMQDestination.QUEUE_TYPE);
|
||||
try (Connection connection = factory.createConnection()) {
|
||||
|
|
|
@ -18,12 +18,8 @@
|
|||
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";
|
||||
public class DestAbstract extends ConnectionAbstract {
|
||||
|
||||
@Option(name = "--destination", description = "Destination to be used. it could be prefixed with queue:// or topic:: (Default: queue://TEST")
|
||||
String destination = "queue://TEST";
|
||||
|
@ -31,12 +27,6 @@ public class DestAbstract extends ActionAbstract {
|
|||
@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;
|
||||
|
||||
|
|
|
@ -50,7 +50,7 @@ public class Producer extends DestAbstract {
|
|||
public Object execute(ActionContext context) throws Exception {
|
||||
super.execute(context);
|
||||
|
||||
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerURL, user, password);
|
||||
ActiveMQConnectionFactory factory = createConnectionFactory();
|
||||
|
||||
Destination dest = ActiveMQDestination.createDestination(this.destination, ActiveMQDestination.QUEUE_TYPE);
|
||||
try (Connection connection = factory.createConnection()) {
|
||||
|
|
Loading…
Reference in New Issue