This commit is contained in:
Justin Bertram 2017-10-26 10:43:12 -05:00
commit 77f52f40b6
11 changed files with 625 additions and 0 deletions

View File

@ -0,0 +1,93 @@
# artemis-jms-bridge
An example project showing how to do different varieties of bridging with ActiveMQ Brokers.
## ActiveMQ to Artemis Camel Bridge
This is an example of using Camel in the ActiveMQ broker to bridge messages between ActiveMQ and Artemis.
### Prerequisites
- install ActiveMQ
- install Artemis
### Preparing
From the root directory run `mvn clean package`
Copy activemq-artemis-camel/target/activemq-artemis-camel-1.0.0-SNAPSHOT.war to the deploy dir of the ActiveMQ installation.
Create an instance of the Artemis broker `$ARTEMIS_HOME/bin/artemis create --allow-anonymous --user admin --password password myBroker`
Edit the $ARTEMIS_INSTANCE/etc/broker.xml and change the acceptor to listen to port 61617. Comment or remove all other acceptors.
```xml
<acceptors>
<acceptor name="artemis">tcp://0.0.0.0:61617?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300</acceptor>
</acceptors>
```
### Testing
Start the Artemis broker.
`$ARTEMIS_INSTANCE/bin/artemis run`
Start the ActiveMQ broker.
`$ACTIVEMQ_HOME/bin/standalone`
Send some messages to the ActiveMQ broker.
`./apache-activemq-5.11.0/bin/activemq producer --user admin --password password --destination queue://TEST.FOO`
Log into the Artemis console and browse the messages in the TEST.FOO queue.
## Artemis to ActiveMQ JMS Bridge
This is an example of using the JMS bridge shipped with the Artemis broker to bridge to ActiveMQ.
###Prerequisites
- install ActiveMQ
- install Artemis
###Preparing
From the root dir run `mvn clean package`.
Copy artemis-jms-bridge/target/artemis-jms-bridge-1.0.0-SNAPSHOT.war to the web directory of the Artemis installation.
Create an instance of the Artemis broker `$ARTEMIS_HOME/bin/artemis create --allow-anonymous --user admin --password password myBroker`
Edit the $ARTEMIS_INSTANCE/etc/broker.xml and change the acceptor to use invm.
```xml
<acceptors>
<acceptor name="artemis">tcp://0.0.0.0:61617?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;amqpLowCredits=300</acceptor>
<acceptor name="invm">vm://0</acceptor>
</acceptors>
```
Edit the $ARTEMIS_INSTANCE/etc/bootstrap.xml and add the war file.
```xml
<app url="bridge" war="artemis-jms-bridge-1.0.0-SNAPSHOT.war"/>
```
###Testing
Start the ActiveMQ broker.
`$ACTIVEMQ_HOME/bin/standalone`
Start the Artemis broker.
`$ARTEMIS_INSTANCE/bin/artemis run`
Send some messages to the queue TEST.BAR via the Artemis console.
`$ARTEMIS_INSTANCE/bin/artemis producer --user admin --password password --destination queue://TEST.BAR --url tcp://localhost:61617 --message-count 1`
Log into the ActiveMQ console and browse the messages in the TEST.BAR queue.

View File

@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed 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 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.artemis.examples</groupId>
<artifactId>artemis-jms-bridge-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>activemq-artemis-camel</artifactId>
<packaging>war</packaging>
<name>ActiveMQ to Artemis Camel Example</name>
<description>An example project showing how to do JMS bridging in ActiveMQ to Artemis using Apache Camel.</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven-war-plugin.version>3.1.0</maven-war-plugin.version>
<camel.version>2.18.1</camel.version>
<spring.version>4.3.4.RELEASE</spring.version>
<slf4j-jboss-logging.version>1.1.0.Final</slf4j-jboss-logging.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>5.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>5.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-jms-client</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.slf4j</groupId>
<artifactId>slf4j-jboss-logging</artifactId>
<version>${slf4j-jboss-logging.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="artemisConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
<property name="userName" value="admin"/>
<property name="password" value="password"/>
</bean>
<bean id="jmsConfig"
class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="artemisConnectionFactory"/>
<property name="concurrentConsumers" value="10"/>
</bean>
<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="jmsConfig"/>
</bean>
<bean id="artemisConnectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory">
<constructor-arg name="url" value="tcp://localhost:61617"/>
<constructor-arg name="user" value="admin"/>
<constructor-arg name="password" value="password"/>
</bean>
<bean id="artemisConfig"
class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="artemisConnectionFactory"/>
<property name="concurrentConsumers" value="10"/>
</bean>
<bean id="artemis"
class="org.apache.camel.component.jms.JmsComponent">
<property name="configuration" ref="artemisConfig"/>
</bean>
<camelContext id="bridgeContext" trace="false" xmlns="http://camel.apache.org/schema/spring">
<route id="bridge_TEST.FOO">
<from uri="activemq:queue:TEST.FOO"/>
<to uri="artemis:queue:TEST.FOO"/>
</route>
</camelContext>
</beans>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed 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.
-->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>JMS Bridge Loader</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:bridge.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>

View File

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed 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 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.artemis.examples</groupId>
<artifactId>artemis-jms-bridge-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>artemis-jms-bridge</artifactId>
<packaging>war</packaging>
<name>Artemis JMS Bridge Example</name>
<description>An example project showing how to do JMS bridging in Artemis to an ActiveMQ.</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven-war-plugin.version>3.1.0</maven-war-plugin.version>
<camel.version>2.18.1</camel.version>
<spring.version>4.3.4.RELEASE</spring.version>
<slf4j-jboss-logging.version>1.1.0.Final</slf4j-jboss-logging.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-client</artifactId>
<version>5.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
<version>5.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-jms-client</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-server</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-jms-server</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.slf4j</groupId>
<artifactId>slf4j-jboss-logging</artifactId>
<version>${slf4j-jboss-logging.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,35 @@
/**
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.artemis.bridge;
import javax.jms.ConnectionFactory;
/**
* @author <a href="mailto:andy.taylor@jboss.org">Andy Taylor</a>
*/
public class ConnectionFactoryFactoryBean implements org.apache.activemq.artemis.jms.bridge.ConnectionFactoryFactory {
private final ConnectionFactory connectionFactory;
public ConnectionFactoryFactoryBean(ConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}
@java.lang.Override
public java.lang.Object createConnectionFactory() throws Exception {
return connectionFactory;
}
}

View File

@ -0,0 +1,36 @@
/**
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.artemis.bridge;
import org.apache.activemq.artemis.jms.bridge.DestinationFactory;
import javax.jms.Destination;
/**
* @author <a href="mailto:andy.taylor@jboss.org">Andy Taylor</a>
*/
public class DestinationFactoryBean implements DestinationFactory {
private final Destination destination;
public DestinationFactoryBean(Destination destination) {
this.destination = destination;
}
@Override
public Destination createDestination() throws Exception {
return destination;
}
}

View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed 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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="activemqConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
<property name="userName" value="admin"/>
<property name="password" value="password"/>
</bean>
<bean id="activemqConnectionFactoryFactory" class="org.artemis.bridge.ConnectionFactoryFactoryBean">
<constructor-arg ref="activemqConnectionFactory"/>
</bean>
<bean id="artemisConnectionFactory" class="org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory">
<constructor-arg value="vm:0"/>
</bean>
<bean id="artemisConnectionFactoryFactory" class="org.artemis.bridge.ConnectionFactoryFactoryBean">
<constructor-arg ref="artemisConnectionFactory"/>
</bean>
<bean id="activemqDestination" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="TEST.BAR"/>
</bean>
<bean id="artemisDestination" class="org.apache.activemq.artemis.jms.client.ActiveMQQueue">
<constructor-arg value="TEST.BAR"/>
</bean>
<bean id="activemqDestinationFactory" class="org.artemis.bridge.DestinationFactoryBean">
<constructor-arg ref="activemqDestination"/>
</bean>
<bean id="artemisDestinationFactory" class="org.artemis.bridge.DestinationFactoryBean">
<constructor-arg ref="artemisDestination"/>
</bean>
<bean id="artemis-jms-bridge" class="org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl" init-method="start" destroy-method="stop">
<property name="bridgeName" value="artemis-jms-bridge"/>
<property name="sourceConnectionFactoryFactory" ref="artemisConnectionFactoryFactory"/>
<property name="targetConnectionFactoryFactory" ref="activemqConnectionFactoryFactory"/>
<property name="sourceDestinationFactory" ref="artemisDestinationFactory"/>
<property name="targetDestinationFactory" ref="activemqDestinationFactory"/>
<property name="qualityOfServiceMode" value="AT_MOST_ONCE"/>
<property name="failureRetryInterval" value="5000"/>
<property name="failoverTimeout" value="5000"/>
<property name="maxRetries" value="-1"/>
<property name="maxBatchSize" value="1"/>
<property name="maxBatchTime" value="-1"/>
</bean>
</beans>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed 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.
-->
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<display-name>JMS Bridge Loader</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:bridge.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>

View File

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed 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 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.artemis.examples</groupId>
<artifactId>artemis-jms-bridge-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Active Messaging Bridge Examples</name>
<description>An example project showing different ways to use bridges with ActiveMQ and Artemis.</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<maven-war-plugin.version>3.1.0</maven-war-plugin.version>
<camel.version>2.18.1</camel.version>
<spring.version>4.3.4.RELEASE</spring.version>
<slf4j-jboss-logging.version>1.1.0.Final</slf4j-jboss-logging.version>
</properties>
<modules>
<module>activemq-artemis-camel</module>
<module>artemis-jms-bridge</module>
</modules>
<repositories>
<repository>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>fuse-public-repository</id>
<name>FuseSource Community Release Repository</name>
<url>https://repo.fusesource.com/nexus/content/groups/public</url>
</repository>
</repositories>
</project>

View File

@ -50,6 +50,7 @@ under the License.
<id>release</id>
<modules>
<module>artemis-ra-rar</module>
<module>artemis-jms-bridge</module>
</modules>
</profile>
</profiles>