Skip to content

Commit

Permalink
added an ActiveMQ component which is automatically pre-configured to …
Browse files Browse the repository at this point in the history
…work well with Apache ActiveMQ. For more details see http://cwiki.apache.org/CAMEL/activemq.html

git-svn-id: https://svn.apache.org/repos/asf/activemq/camel/trunk@540547 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jstrachan committed May 22, 2007
1 parent 66e297e commit 23af793
Show file tree
Hide file tree
Showing 20 changed files with 605 additions and 65 deletions.
6 changes: 5 additions & 1 deletion apache-camel/pom.xml
Expand Up @@ -34,6 +34,10 @@

<dependencies>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-bam</artifactId>
Expand Down Expand Up @@ -188,7 +192,7 @@
<goal>createbundle</goal>
</goals>
<configuration>
<includes>camel-bam,camel-core,camel-cxf,camel-file,camel-http,camel-jaxb,camel-jbi,camel-jms,camel-josql,camel-jpa,camel-mail,camel-mina,camel-rmi,camel-saxon,camel-script,camel-spring,camel-xmpp,commons-logging</includes>
<includes>camel-activemq,camel-bam,camel-core,camel-cxf,camel-file,camel-http,camel-jaxb,camel-jbi,camel-jms,camel-josql,camel-jpa,camel-mail,camel-mina,camel-rmi,camel-saxon,camel-script,camel-spring,camel-xmpp,commons-logging</includes>
</configuration>
</execution>
</executions>
Expand Down
1 change: 1 addition & 0 deletions apache-camel/src/main/descriptors/unix-bin.xml
Expand Up @@ -49,6 +49,7 @@
<unpack>false</unpack>
<scope>runtime</scope>
<includes>
<include>org.apache.camel:camel-activemq</include>
<include>org.apache.camel:camel-bam</include>
<include>org.apache.camel:camel-core</include>
<include>org.apache.camel:camel-cxf</include>
Expand Down
1 change: 1 addition & 0 deletions apache-camel/src/main/descriptors/windows-bin.xml
Expand Up @@ -55,6 +55,7 @@
<unpack>false</unpack>
<scope>runtime</scope>
<includes>
<include>org.apache.camel:camel-activemq</include>
<include>org.apache.camel:camel-bam</include>
<include>org.apache.camel:camel-core</include>
<include>org.apache.camel:camel-cxf</include>
Expand Down
88 changes: 88 additions & 0 deletions components/camel-activemq/pom.xml
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
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.
-->

<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.camel</groupId>
<artifactId>camel-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>camel-activemq</artifactId>
<name>Camel :: ActiveMQ</name>
<description>Camel ActiveMQ support</description>

<dependencies>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>apache-activemq</artifactId>
</dependency>


<!-- testing -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<childDelegation>false</childDelegation>
<useFile>true</useFile>
<excludes>
<!-- TODO - FIXME ASAP -->
<exclude>**/JmsRouteUsingSpringWithAutoWireTest.*</exclude>
</excludes>
</configuration>
</plugin>

</plugins>
</build>
</project>
@@ -0,0 +1,72 @@
/**
*
* 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.camel.component.activemq;

import org.apache.camel.CamelContext;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.component.jms.JmsConfiguration;

/**
* The <a href="http://activemq.apache.org/camel/activemq.html">ActiveMQ Component</a>
*
* @version $Revision: 1.1 $
*/
public class ActiveMQComponent extends JmsComponent {
/**
* Creates an <a href="http://activemq.apache.org/camel/activemq.html">ActiveMQ Component</a>
*
* @return the created component
*/
public static ActiveMQComponent activeMQComponent() {
return new ActiveMQComponent();
}

/**
* Creates an <a href="http://activemq.apache.org/camel/activemq.html">ActiveMQ Component</a>
* connecting to the given broker URL
*
* @param brokerURL the URL to connect to
* @return the created component
*/
public static ActiveMQComponent activeMQComponent(String brokerURL) {
ActiveMQComponent answer = new ActiveMQComponent();
answer.getConfiguration().setBrokerURL(brokerURL);
return answer;
}

public ActiveMQComponent() {
}

public ActiveMQComponent(CamelContext context) {
super(context);
}

public ActiveMQComponent(ActiveMQConfiguration configuration) {
super(configuration);
}

@Override
public ActiveMQConfiguration getConfiguration() {
return (ActiveMQConfiguration) super.getConfiguration();
}

@Override
protected JmsConfiguration createConfiguration() {
return new ActiveMQConfiguration();
}
}
@@ -0,0 +1,76 @@
/**
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.activemq;

import org.apache.activemq.pool.PooledConnectionFactory;
import org.apache.activemq.spring.ActiveMQConnectionFactory;
import org.apache.camel.component.jms.JmsConfiguration;

import javax.jms.ConnectionFactory;

/**
* @version $Revision: 1.1 $
*/
public class ActiveMQConfiguration extends JmsConfiguration {
private String brokerURL = ActiveMQConnectionFactory.DEFAULT_BROKER_URL;

public ActiveMQConfiguration() {
}

public String getBrokerURL() {
return brokerURL;
}

/**
* Sets the broker URL to use to connect to ActiveMQ using the
* <a href="http://activemq.apache.org/configuring-transports.html">ActiveMQ URI format</a>
*
* @param brokerURL the URL of the broker.
*/
public void setBrokerURL(String brokerURL) {
this.brokerURL = brokerURL;
}

@Override
public ActiveMQConnectionFactory getListenerConnectionFactory() {
return (ActiveMQConnectionFactory) super.getListenerConnectionFactory();
}

@Override
public void setListenerConnectionFactory(ConnectionFactory listenerConnectionFactory) {
if (listenerConnectionFactory instanceof ActiveMQConnectionFactory) {
super.setListenerConnectionFactory(listenerConnectionFactory);
}
else {
throw new IllegalArgumentException("ConnectionFactory " + listenerConnectionFactory
+ " is not an instanceof " + ActiveMQConnectionFactory.class.getName());
}
}

@Override
protected ConnectionFactory createListenerConnectionFactory() {
ActiveMQConnectionFactory answer = new ActiveMQConnectionFactory();
answer.setBrokerURL(getBrokerURL());
return answer;
}

@Override
protected ConnectionFactory createTemplateConnectionFactory() {
return new PooledConnectionFactory(getListenerConnectionFactory());
}
}
@@ -0,0 +1,25 @@
<!--
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.
-->
<html>
<head>
</head>
<body>

Defines the <a href="http://activemq.apache.org/camel/activemq.html">ActiveMQ Component</a>

</body>
</html>
@@ -0,0 +1 @@
class=org.apache.camel.component.activemq.ActiveMQComponent
@@ -0,0 +1,60 @@
/**
*
* 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.camel.component.activemq;

import org.apache.activemq.pool.PooledConnectionFactory;
import org.apache.activemq.spring.ActiveMQConnectionFactory;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.Endpoint;
import org.apache.camel.component.jms.JmsConsumer;
import org.apache.camel.component.jms.JmsEndpoint;
import org.apache.camel.component.jms.JmsProducer;
import org.apache.camel.processor.Logger;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.listener.AbstractMessageListenerContainer;

/**
* @version $Revision: 538973 $
*/
public class ActiveMQConfigureTest extends ContextTestSupport {

public void testJmsTemplateUsesPoolingConnectionFactory() throws Exception {
JmsEndpoint endpoint = resolveMandatoryEndpoint("activemq:test.foo");
JmsProducer producer = endpoint.createProducer();

JmsTemplate template = assertIsInstanceOf(JmsTemplate.class, producer.getTemplate());
assertIsInstanceOf(PooledConnectionFactory.class, template.getConnectionFactory());
assertEquals("pubSubDomain", false, template.isPubSubDomain());
}

public void testListenerContainerUsesSpringConnectionFactory() throws Exception {
JmsEndpoint endpoint = resolveMandatoryEndpoint("activemq:topic:test.foo");
JmsConsumer consumer = endpoint.createConsumer(new Logger());

AbstractMessageListenerContainer listenerContainer = consumer.getListenerContainer();
assertIsInstanceOf(ActiveMQConnectionFactory.class, listenerContainer.getConnectionFactory());
assertEquals("pubSubDomain", true, listenerContainer.isPubSubDomain());

}

@Override
protected JmsEndpoint resolveMandatoryEndpoint(String uri) {
Endpoint endpoint = super.resolveMandatoryEndpoint(uri);
return assertIsInstanceOf(JmsEndpoint.class, endpoint);
}
}

0 comments on commit 23af793

Please sign in to comment.