mirror of https://github.com/apache/activemq.git
Merging patch for AMQ-6380 This closes #193
This commit is contained in:
commit
29e6f63d58
|
@ -0,0 +1,11 @@
|
|||
# Activemq-cf
|
||||
|
||||
Allows to create a Pooled ActiveMQ ConnectionFactory from a config.
|
||||
|
||||
## Install
|
||||
|
||||
Install the activemq-client and scr features and this bundle. Then put the example config org.apache.karaf.activemq.cfg in etc.
|
||||
|
||||
service:list ConnectionFactory
|
||||
|
||||
This should show the ConnectionFactory as a service.
|
|
@ -0,0 +1,5 @@
|
|||
# Example ConnectionFactory def for decanter
|
||||
osgi.jndi.service.name=jms/local
|
||||
url=tcp://localhost:61616
|
||||
userName=karaf
|
||||
password=karaf
|
|
@ -0,0 +1,75 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<!--
|
||||
|
||||
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.
|
||||
-->
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>activemq-parent</artifactId>
|
||||
<version>5.14.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>activemq-cf</artifactId>
|
||||
<name>ActiveMQ :: ConnectionFactory</name>
|
||||
<description>ActiveMQ ConnectionFactory service</description>
|
||||
|
||||
<packaging>bundle</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.osgi</groupId>
|
||||
<artifactId>org.osgi.core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.osgi</groupId>
|
||||
<artifactId>org.osgi.compendium</artifactId>
|
||||
<version>5.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>activemq-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>activemq-jms-pool</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<configuration>
|
||||
<instructions>
|
||||
<Export-Package>
|
||||
!*
|
||||
</Export-Package>
|
||||
<Private-Package>
|
||||
org.apache.activemq.osgi.cf
|
||||
</Private-Package>
|
||||
</instructions>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* 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.osgi.cf;
|
||||
|
||||
import java.util.Dictionary;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.jms.ConnectionFactory;
|
||||
|
||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||
import org.apache.activemq.jms.pool.PooledConnectionFactory;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.ServiceRegistration;
|
||||
import org.osgi.service.component.ComponentContext;
|
||||
import org.osgi.service.component.annotations.Activate;
|
||||
import org.osgi.service.component.annotations.Component;
|
||||
import org.osgi.service.component.annotations.ConfigurationPolicy;
|
||||
import org.osgi.service.component.annotations.Deactivate;
|
||||
|
||||
@Component //
|
||||
( //
|
||||
configurationPid = "org.apache.activemq", //
|
||||
immediate = true, //
|
||||
configurationPolicy = ConfigurationPolicy.REQUIRE //
|
||||
)
|
||||
public class ConnectionFactoryProvider {
|
||||
|
||||
private static final String OSGI_JNDI_SERVICE_NAME = "osgi.jndi.service.name";
|
||||
private ServiceRegistration<ConnectionFactory> reg;
|
||||
|
||||
@Activate
|
||||
public void create(ComponentContext compContext) {
|
||||
BundleContext context = compContext.getBundleContext();
|
||||
Dictionary<String, Object> config = compContext.getProperties();
|
||||
String brokerURL = getString(config, "url", "tcp://localhost:61616");
|
||||
String jndiName = getString(config, OSGI_JNDI_SERVICE_NAME, "jms/local");
|
||||
String userName = getString(config, "userName", null);
|
||||
String password = getString(config, "password", null);
|
||||
long expiryTimeout = new Long(getString(config, "expiryTimeout", "0"));
|
||||
int idleTimeout = new Integer(getString(config, "idleTimeout", "30000"));
|
||||
int maxConnections = new Integer(getString(config, "maxConnections", "8"));
|
||||
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(brokerURL);
|
||||
if (userName != null) {
|
||||
cf.setUserName(userName);
|
||||
cf.setPassword(password);
|
||||
}
|
||||
PooledConnectionFactory pcf = new PooledConnectionFactory();
|
||||
pcf.setConnectionFactory(cf);
|
||||
pcf.setExpiryTimeout(expiryTimeout);
|
||||
pcf.setIdleTimeout(idleTimeout);
|
||||
pcf.setMaxConnections(maxConnections);
|
||||
Dictionary<String, String> props = new Hashtable<String, String>();
|
||||
props.put(OSGI_JNDI_SERVICE_NAME, jndiName);
|
||||
reg = context.registerService(ConnectionFactory.class, pcf, props);
|
||||
}
|
||||
|
||||
@Deactivate
|
||||
public void deactivate() {
|
||||
reg.unregister();
|
||||
}
|
||||
|
||||
private String getString(Dictionary<String, Object> config, String key, String defaultValue) {
|
||||
Object value = config.get(key);
|
||||
return value != null ? value.toString() : defaultValue;
|
||||
}
|
||||
}
|
|
@ -36,6 +36,12 @@
|
|||
<bundle dependency="false">mvn:org.apache.xbean/xbean-spring/${xbean-version}</bundle>
|
||||
<bundle>mvn:org.apache.activemq/activemq-osgi/${project.version}</bundle>
|
||||
</feature>
|
||||
|
||||
<feature name="activemq-cf" description="ActiveMQ ConnectionFactory from config" version="${project.version}" resolver="(obr)" start-level="50">
|
||||
<feature>activemq-client</feature>
|
||||
<feature>scr</feature>
|
||||
<bundle>mvn:org.apache.activemq/activemq-cf/${project.version}</bundle>
|
||||
</feature>
|
||||
|
||||
<!-- All bundles needed by the broker -->
|
||||
<feature name="activemq" description="ActiveMQ broker libraries" version="${project.version}" resolver="(obr)" start-level="50">
|
||||
|
|
Loading…
Reference in New Issue