mirror of https://github.com/apache/activemq.git
https://issues.apache.org/jira/browse/AMQ-4034 - osgi, remove create-broker and destory-broker commands
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1441470 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3527a4cfa0
commit
081b823c2d
|
@ -1,161 +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.karaf.commands;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
import org.apache.felix.gogo.commands.Argument;
|
|
||||||
import org.apache.felix.gogo.commands.Command;
|
|
||||||
import org.apache.felix.gogo.commands.Option;
|
|
||||||
import org.apache.karaf.shell.console.OsgiCommandSupport;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @version $Rev: 960482 $ $Date: 2010-07-05 10:28:33 +0200 (Mon, 05 Jul 2010) $
|
|
||||||
*/
|
|
||||||
@Command(scope="activemq", name="create-broker", description="Creates a broker instance.")
|
|
||||||
public class CreateBrokerCommand extends OsgiCommandSupport {
|
|
||||||
|
|
||||||
@Argument(name = "name", description = "The name of the broker (defaults to localhost).")
|
|
||||||
private String name = "localhost";
|
|
||||||
@Option(name = "-t", aliases = {"--type"}, description = "type of configuration to be used: spring or blueprint (defaults to spring)")
|
|
||||||
private String type = "spring";
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see
|
|
||||||
* org.apache.karaf.shell.console.OsgiCommandSupport#doExecute()
|
|
||||||
*/
|
|
||||||
protected Object doExecute() throws Exception {
|
|
||||||
|
|
||||||
try {
|
|
||||||
String name = getName();
|
|
||||||
File base = new File(System.getProperty("karaf.base"));
|
|
||||||
File deploy = new File(base, "deploy");
|
|
||||||
|
|
||||||
HashMap<String, String> props = new HashMap<String, String>();
|
|
||||||
props.put("${name}", name);
|
|
||||||
|
|
||||||
mkdir(deploy);
|
|
||||||
File configFile = new File(deploy, name + "-broker.xml");
|
|
||||||
|
|
||||||
if (!type.equalsIgnoreCase("spring") && !type.equalsIgnoreCase("blueprint")) {
|
|
||||||
System.out.println("@|green Unknown type '" + type + "' Using spring by default");
|
|
||||||
type = "spring";
|
|
||||||
}
|
|
||||||
|
|
||||||
copyFilteredResourceTo(configFile, type.toLowerCase() + ".xml", props);
|
|
||||||
|
|
||||||
System.out.println("");
|
|
||||||
System.out.println("Default ActiveMQ Broker (" + name + ") configuration file created at: "
|
|
||||||
+ configFile.getPath());
|
|
||||||
System.out.println("Please review the configuration and modify to suite your needs. ");
|
|
||||||
System.out.println("");
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void copyFilteredResourceTo(File outFile, String resource, HashMap<String, String> props)
|
|
||||||
throws Exception {
|
|
||||||
if (!outFile.exists()) {
|
|
||||||
System.out.println("Creating file: @|green " + outFile.getPath() + "|");
|
|
||||||
InputStream is = CreateBrokerCommand.class.getResourceAsStream(resource);
|
|
||||||
try {
|
|
||||||
// Read it line at a time so that we can use the platform line
|
|
||||||
// ending when we write it out.
|
|
||||||
PrintStream out = new PrintStream(new FileOutputStream(outFile));
|
|
||||||
try {
|
|
||||||
Scanner scanner = new Scanner(is);
|
|
||||||
while (scanner.hasNextLine()) {
|
|
||||||
String line = scanner.nextLine();
|
|
||||||
line = filter(line, props);
|
|
||||||
out.println(line);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
safeClose(out);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
safeClose(is);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
System.out.println("@|red File already exists|. Move it out of the way if you want it re-created: "
|
|
||||||
+ outFile.getPath() + "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void safeClose(InputStream is) throws IOException {
|
|
||||||
if (is == null)
|
|
||||||
return;
|
|
||||||
try {
|
|
||||||
is.close();
|
|
||||||
} catch (Throwable ignore) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void safeClose(OutputStream is) throws IOException {
|
|
||||||
if (is == null)
|
|
||||||
return;
|
|
||||||
try {
|
|
||||||
is.close();
|
|
||||||
} catch (Throwable ignore) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String filter(String line, HashMap<String, String> props) {
|
|
||||||
for (Map.Entry<String, String> i : props.entrySet()) {
|
|
||||||
int p1;
|
|
||||||
while ((p1 = line.indexOf(i.getKey())) >= 0) {
|
|
||||||
String l1 = line.substring(0, p1);
|
|
||||||
String l2 = line.substring(p1 + i.getKey().length());
|
|
||||||
line = l1 + i.getValue() + l2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void mkdir(File file) {
|
|
||||||
if (!file.exists()) {
|
|
||||||
System.out.println("Creating missing directory: @|green " + file.getPath() + "|");
|
|
||||||
file.mkdirs();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
if (name == null) {
|
|
||||||
File base = new File(System.getProperty("karaf.base"));
|
|
||||||
name = base.getName();
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,68 +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.karaf.commands;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import org.apache.felix.gogo.commands.Option;
|
|
||||||
import org.apache.felix.gogo.commands.Command;
|
|
||||||
import org.apache.karaf.shell.console.OsgiCommandSupport;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @version $Rev: 960482 $ $Date: 2010-07-05 10:28:33 +0200 (Mon, 05 Jul 2010) $
|
|
||||||
*/
|
|
||||||
@Command(scope="activemq", name="destroy-broker", description="Destory a broker instance.")
|
|
||||||
public class DestroyBrokerCommand extends OsgiCommandSupport {
|
|
||||||
|
|
||||||
@Option(name = "-n", aliases = {"--name"}, description = "The name of the broker (defaults to localhost).")
|
|
||||||
private String name = "localhost";
|
|
||||||
|
|
||||||
protected Object doExecute() throws Exception {
|
|
||||||
|
|
||||||
try {
|
|
||||||
String name = getName();
|
|
||||||
File base = new File(System.getProperty("karaf.base"));
|
|
||||||
File deploy = new File(base, "deploy");
|
|
||||||
File configFile = new File(deploy, name + "-broker.xml");
|
|
||||||
|
|
||||||
configFile.delete();
|
|
||||||
|
|
||||||
System.out.println("");
|
|
||||||
System.out.println("Default ActiveMQ Broker (" + name + ") configuration file created at: "
|
|
||||||
+ configFile.getPath() + " removed.");
|
|
||||||
System.out.println("");
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
if (name == null) {
|
|
||||||
File base = new File(System.getProperty("karaf.base"));
|
|
||||||
name = base.getName();
|
|
||||||
}
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -20,18 +20,6 @@
|
||||||
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
|
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
|
||||||
xmlns:shell="http://karaf.apache.org/xmlns/shell/v1.0.0">
|
xmlns:shell="http://karaf.apache.org/xmlns/shell/v1.0.0">
|
||||||
|
|
||||||
<shell:command-bundle>
|
|
||||||
|
|
||||||
<shell:command name="activemq/create-broker">
|
|
||||||
<shell:action class="org.apache.activemq.karaf.commands.CreateBrokerCommand"/>
|
|
||||||
</shell:command>
|
|
||||||
|
|
||||||
<shell:command name="activemq/destroy-broker">
|
|
||||||
<shell:action class="org.apache.activemq.karaf.commands.DestroyBrokerCommand"/>
|
|
||||||
</shell:command>
|
|
||||||
|
|
||||||
</shell:command-bundle>
|
|
||||||
|
|
||||||
<!-- ActiveMQ List Command -->
|
<!-- ActiveMQ List Command -->
|
||||||
<bean id="listcommand" class="org.apache.activemq.karaf.commands.ActiveMQCommand">
|
<bean id="listcommand" class="org.apache.activemq.karaf.commands.ActiveMQCommand">
|
||||||
<property name="blueprintContainer" ref="blueprintContainer"/>
|
<property name="blueprintContainer" ref="blueprintContainer"/>
|
||||||
|
|
|
@ -1,27 +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.
|
|
||||||
##
|
|
||||||
|
|
||||||
##
|
|
||||||
## $Rev: 703511 $ $Date: 2008-10-10 18:07:36 +0200 (Fri, 10 Oct 2008) $
|
|
||||||
##
|
|
||||||
|
|
||||||
command.description=Creates a broker instance.
|
|
||||||
|
|
||||||
command.manual=\
|
|
||||||
TODO: date manual
|
|
|
@ -1,27 +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.
|
|
||||||
##
|
|
||||||
|
|
||||||
##
|
|
||||||
## $Rev: 703511 $ $Date: 2008-10-10 18:07:36 +0200 (Fri, 10 Oct 2008) $
|
|
||||||
##
|
|
||||||
|
|
||||||
command.description=Remove a broker instance.
|
|
||||||
|
|
||||||
command.manual=\
|
|
||||||
TODO: date manual
|
|
|
@ -1,130 +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.
|
|
||||||
-->
|
|
||||||
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
|
|
||||||
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
|
|
||||||
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
|
|
||||||
xmlns:amq="http://activemq.apache.org/schema/core">
|
|
||||||
|
|
||||||
<!-- Allows us to use system properties as variables in this configuration file -->
|
|
||||||
<ext:property-placeholder />
|
|
||||||
|
|
||||||
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="${name}" dataDirectory="${karaf.data}/activemq/${name}" useShutdownHook="false" startAsync="true">
|
|
||||||
|
|
||||||
<!--
|
|
||||||
For better performances use VM cursor and small memory limit.
|
|
||||||
For more information, see:
|
|
||||||
|
|
||||||
http://activemq.apache.org/message-cursors.html
|
|
||||||
|
|
||||||
Also, if your producer is "hanging", it's probably due to producer flow control.
|
|
||||||
For more information, see:
|
|
||||||
http://activemq.apache.org/producer-flow-control.html
|
|
||||||
-->
|
|
||||||
|
|
||||||
<destinationPolicy>
|
|
||||||
<policyMap>
|
|
||||||
<policyEntries>
|
|
||||||
<policyEntry topic=">" producerFlowControl="true" memoryLimit="1mb">
|
|
||||||
<pendingSubscriberPolicy>
|
|
||||||
<vmCursor />
|
|
||||||
</pendingSubscriberPolicy>
|
|
||||||
</policyEntry>
|
|
||||||
<policyEntry queue=">" producerFlowControl="true" memoryLimit="1mb">
|
|
||||||
<!-- Use VM cursor for better latency
|
|
||||||
For more information, see:
|
|
||||||
|
|
||||||
http://activemq.apache.org/message-cursors.html
|
|
||||||
|
|
||||||
<pendingQueuePolicy>
|
|
||||||
<vmQueueCursor/>
|
|
||||||
</pendingQueuePolicy>
|
|
||||||
-->
|
|
||||||
</policyEntry>
|
|
||||||
</policyEntries>
|
|
||||||
</policyMap>
|
|
||||||
</destinationPolicy>
|
|
||||||
|
|
||||||
<!-- Use the following to configure how ActiveMQ is exposed in JMX -->
|
|
||||||
<managementContext>
|
|
||||||
<managementContext createConnector="false"/>
|
|
||||||
</managementContext>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
Configure message persistence for the broker. The default persistence
|
|
||||||
mechanism is the KahaDB store (identified by the kahaDB tag).
|
|
||||||
For more information, see:
|
|
||||||
|
|
||||||
http://activemq.apache.org/persistence.html
|
|
||||||
-->
|
|
||||||
<persistenceAdapter>
|
|
||||||
<kahaDB directory="${karaf.data}/activemq/${name}/kahadb"/>
|
|
||||||
</persistenceAdapter>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
The systemUsage controls the maximum amount of space the broker will
|
|
||||||
use before slowing down producers. For more information, see:
|
|
||||||
|
|
||||||
http://activemq.apache.org/producer-flow-control.html
|
|
||||||
|
|
||||||
<systemUsage>
|
|
||||||
<systemUsage>
|
|
||||||
<memoryUsage>
|
|
||||||
<memoryUsage limit="20 mb"/>
|
|
||||||
</memoryUsage>
|
|
||||||
<storeUsage>
|
|
||||||
<storeUsage limit="1 gb" name="foo"/>
|
|
||||||
</storeUsage>
|
|
||||||
<tempUsage>
|
|
||||||
<tempUsage limit="100 mb"/>
|
|
||||||
</tempUsage>
|
|
||||||
</systemUsage>
|
|
||||||
</systemUsage>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- The transport connectors ActiveMQ will listen to -->
|
|
||||||
<transportConnectors>
|
|
||||||
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
|
|
||||||
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613"/>
|
|
||||||
</transportConnectors>
|
|
||||||
|
|
||||||
</broker>
|
|
||||||
|
|
||||||
<bean id="activemqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
|
|
||||||
<property name="brokerURL" value="tcp://0.0.0.0:61616" />
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
|
|
||||||
<property name="maxConnections" value="8" />
|
|
||||||
<property name="connectionFactory" ref="activemqConnectionFactory" />
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<bean id="resourceManager" class="org.apache.activemq.pool.ActiveMQResourceManager" init-method="recoverResource">
|
|
||||||
<property name="transactionManager" ref="transactionManager" />
|
|
||||||
<property name="connectionFactory" ref="activemqConnectionFactory" />
|
|
||||||
<property name="resourceName" value="activemq.${name}" />
|
|
||||||
</bean>
|
|
||||||
|
|
||||||
<reference id="transactionManager" interface="javax.transaction.TransactionManager" />
|
|
||||||
|
|
||||||
<service ref="pooledConnectionFactory" interface="javax.jms.ConnectionFactory">
|
|
||||||
<service-properties>
|
|
||||||
<entry key="name" value="localhost"/>
|
|
||||||
</service-properties>
|
|
||||||
</service>
|
|
||||||
|
|
||||||
</blueprint>
|
|
||||||
|
|
Loading…
Reference in New Issue