[AMQ-8033] Remove activemq-camel (#701)

* [AMQ-8033] Remove activemq-camel

 - Prerequisite for JMS v2.0 support

* [AMQ-8033] Remove activemq-camel

 - Prerequisite for JMS v2.0 support

* [AMQ-8033] Assembly and karaf clean-ups
This commit is contained in:
Matt Pavlovich 2021-09-03 11:21:13 -05:00 committed by GitHub
parent 36f5592348
commit c1a2ff25c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
102 changed files with 5 additions and 8147 deletions

View File

@ -25,10 +25,6 @@
<dependencies>
<!-- activemq -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-camel</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-console</artifactId>
@ -92,7 +88,6 @@
<includes>
<include>${project.groupId}:activemq-client</include>
<include>${project.groupId}:activemq-openwire-legacy</include>
<include>${project.groupId}:activemq-camel</include>
<include>${project.groupId}:activemq-jaas</include>
<include>${project.groupId}:activemq-broker</include>
<include>${project.groupId}:activemq-console</include>
@ -211,13 +206,6 @@
<classifier>sources</classifier>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-camel</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
<optional>true</optional>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-jaas</artifactId>

View File

@ -1,306 +0,0 @@
<?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 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.activemq</groupId>
<artifactId>activemq-parent</artifactId>
<version>5.17.0-SNAPSHOT</version>
</parent>
<artifactId>activemq-camel</artifactId>
<name>ActiveMQ :: Camel</name>
<description>ActiveMQ component for Camel</description>
<packaging>bundle</packaging>
<properties>
<camel.osgi.export.service>
org.apache.camel.spi.ComponentResolver;component=activemq,
org.apache.camel.spi.ComponentResolver;component=broker
</camel.osgi.export.service>
</properties>
<dependencies>
<!-- =============================== -->
<!-- Required Dependencies -->
<!-- =============================== -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jms</artifactId>
<exclusions>
<!-- ActiveMQ is JMS 1.1 spec only -->
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_2.0_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- use the Camel apt compiler plugin -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>apt</artifactId>
<version>${camel-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-spring</artifactId>
</dependency>
<!-- to use AMQ with Camel efficient we would need to use pooling -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-pool</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-annotation_1.0_spec</artifactId>
<optional>true</optional>
</dependency>
<!-- testing helpers -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-unit-tests</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-broker</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.components</groupId>
<artifactId>geronimo-transaction</artifactId>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.objectweb.howl</groupId>
<artifactId>howl</artifactId>
<version>1.0.1-1</version>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jencks</groupId>
<artifactId>jencks</artifactId>
<version>2.2</version>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-jaas</artifactId>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-ra</artifactId>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jdbc</artifactId>
<version>${camel-version}</version>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<inherited>true</inherited>
<configuration>
<instructions>
<Export-Package>
org.apache.activemq.camel*;version:="${project.version}";-noimport:=true
</Export-Package>
<Import-Package>
org.springframework.jms*;version="[4,6)",
org.apache.activemq.pool,
org.apache.camel*;version="${camel-version-range}",
*
</Import-Package>
<Export-Service>
org.apache.camel.spi.ComponentResolver;component=activemq,
org.apache.camel.spi.ComponentResolver;component=broker
</Export-Service>
</instructions>
</configuration>
</plugin>
<!-- Configure which tests are included/excuded -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<childDelegation>false</childDelegation>
<useFile>true</useFile>
<argLine>-Xmx512M</argLine>
<systemProperties>
<property>
<name>org.apache.activemq.default.directory.prefix</name>
<value>target/</value>
</property>
</systemProperties>
<systemPropertyVariables>
<derby.stream.error.file>target/derby.log</derby.stream.error.file>
</systemPropertyVariables>
</configuration>
</plugin>
<!-- use Camel plugins to generate component details -->
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-package-maven-plugin</artifactId>
<version>${camel-version}</version>
<executions>
<execution>
<goals>
<goal>generate-components-list</goal>
</goals>
<phase>generate-resources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>activemq.tests-sanity</id>
<activation>
<property>
<name>activemq.tests</name>
<value>smoke</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/ActiveMQConfigureTest.*</include>
<include>**/ActiveMQJmsHeaderRouteTest.*</include>
<include>**/CamelJmsTest.*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>activemq.tests-autoTransport</id>
<activation>
<property>
<name>activemq.tests</name>
<value>autoTransport</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -1,45 +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.camel;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.management.JMSStatsImpl;
import org.apache.activemq.transport.Transport;
import org.apache.activemq.util.IdGenerator;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
/**
*
*/
public class CamelConnection extends ActiveMQConnection implements CamelContextAware {
private CamelContext camelContext;
protected CamelConnection(Transport transport, IdGenerator clientIdGenerator,
IdGenerator connectionIdGenerator, JMSStatsImpl factoryStats) throws Exception {
super(transport, clientIdGenerator, connectionIdGenerator, factoryStats);
}
public CamelContext getCamelContext() {
return camelContext;
}
public void setCamelContext(CamelContext camelContext) {
this.camelContext = camelContext;
}
}

View File

@ -1,55 +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.camel;
import org.apache.activemq.management.JMSStatsImpl;
import org.apache.activemq.spring.ActiveMQConnectionFactory;
import org.apache.activemq.transport.Transport;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
/**
* A JMS ConnectionFactory which resolves non-JMS destinations or instances of
* {@link CamelDestination} to use the {@link CamelContext} to perform smart routing etc
*
*
*/
public class CamelConnectionFactory extends ActiveMQConnectionFactory implements CamelContextAware {
private CamelContext camelContext;
public CamelConnectionFactory() {
}
public CamelContext getCamelContext() {
return camelContext;
}
public void setCamelContext(CamelContext camelContext) {
this.camelContext = camelContext;
}
// Implementation methods
//-----------------------------------------------------------------------
protected CamelConnection createActiveMQConnection(Transport transport, JMSStatsImpl stats) throws Exception {
CamelConnection connection = new CamelConnection(transport, getClientIdGenerator(), getConnectionIdGenerator(), stats);
CamelContext context = getCamelContext();
if (context != null) {
connection.setCamelContext(context);
}
return connection;
}
}

View File

@ -1,162 +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.camel;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.QueueReceiver;
import javax.jms.QueueSender;
import javax.jms.TopicPublisher;
import javax.jms.TopicSubscriber;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQSession;
import org.apache.activemq.CustomDestination;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.Endpoint;
import org.apache.camel.component.jms.JmsBinding;
import org.apache.camel.component.jms.JmsEndpoint;
/**
*
*/
public class CamelDestination implements CustomDestination, CamelContextAware {
private String uri;
private Endpoint endpoint;
private CamelContext camelContext;
// add in dummy endpoint pending camel release with
// https://issues.apache.org/activemq/browse/CAMEL-1982
private JmsBinding binding = new JmsBinding(new JmsEndpoint());
public CamelDestination() {
}
public CamelDestination(String uri) {
this.uri = uri;
}
public String toString() {
return uri.toString();
}
// CustomDestination interface
//-----------------------------------------------------------------------
public MessageConsumer createConsumer(ActiveMQSession session, String messageSelector) {
return createConsumer(session, messageSelector, false);
}
public MessageConsumer createConsumer(ActiveMQSession session, String messageSelector, boolean noLocal) {
return new CamelMessageConsumer(this, resolveEndpoint(session), session, messageSelector, noLocal);
}
public TopicSubscriber createSubscriber(ActiveMQSession session, String messageSelector, boolean noLocal) {
return createDurableSubscriber(session, null, messageSelector, noLocal);
}
public TopicSubscriber createDurableSubscriber(ActiveMQSession session, String name, String messageSelector, boolean noLocal) {
throw new UnsupportedOperationException("This destination is not a Topic: " + this);
}
public QueueReceiver createReceiver(ActiveMQSession session, String messageSelector) {
throw new UnsupportedOperationException("This destination is not a Queue: " + this);
}
// Producers
//-----------------------------------------------------------------------
public MessageProducer createProducer(ActiveMQSession session) throws JMSException {
return new CamelMessageProducer(this, resolveEndpoint(session), session);
}
public TopicPublisher createPublisher(ActiveMQSession session) throws JMSException {
throw new UnsupportedOperationException("This destination is not a Topic: " + this);
}
public QueueSender createSender(ActiveMQSession session) throws JMSException {
throw new UnsupportedOperationException("This destination is not a Queue: " + this);
}
// Properties
//-----------------------------------------------------------------------
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public Endpoint getEndpoint() {
return endpoint;
}
public void setEndpoint(Endpoint endpoint) {
this.endpoint = endpoint;
}
public CamelContext getCamelContext() {
return camelContext;
}
public void setCamelContext(CamelContext camelContext) {
this.camelContext = camelContext;
}
public JmsBinding getBinding() {
return binding;
}
public void setBinding(JmsBinding binding) {
this.binding = binding;
}
// Implementation methods
//-----------------------------------------------------------------------
/**
* Resolves the Camel Endpoint for this destination
*
* @return
*/
protected Endpoint resolveEndpoint(ActiveMQSession session) {
Endpoint answer = getEndpoint();
if (answer == null) {
answer = resolveCamelContext(session).getEndpoint(getUri());
if (answer == null) {
throw new IllegalArgumentException("No endpoint could be found for URI: " + getUri());
}
}
return answer;
}
protected CamelContext resolveCamelContext(ActiveMQSession session) {
CamelContext answer = getCamelContext();
if (answer == null) {
ActiveMQConnection connection = session.getConnection();
if (connection instanceof CamelConnection) {
CamelConnection camelConnection = (CamelConnection) connection;
answer = camelConnection.getCamelContext();
}
}
if (answer == null) {
throw new IllegalArgumentException("No CamelContext has been configured");
}
return answer;
}
}

View File

@ -1,173 +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.camel;
import javax.jms.IllegalStateException;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import org.apache.activemq.ActiveMQSession;
import org.apache.activemq.util.JMSExceptionSupport;
import org.apache.camel.Consumer;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.PollingConsumer;
import org.apache.camel.Processor;
/**
* A JMS {@link javax.jms.MessageConsumer} which consumes message exchanges from
* a Camel {@link Endpoint}
*
*
*/
public class CamelMessageConsumer implements MessageConsumer {
private final CamelDestination destination;
private final Endpoint endpoint;
private final ActiveMQSession session;
private final String messageSelector;
private final boolean noLocal;
private MessageListener messageListener;
private Consumer consumer;
private PollingConsumer pollingConsumer;
private boolean closed;
public CamelMessageConsumer(CamelDestination destination, Endpoint endpoint, ActiveMQSession session, String messageSelector, boolean noLocal) {
this.destination = destination;
this.endpoint = endpoint;
this.session = session;
this.messageSelector = messageSelector;
this.noLocal = noLocal;
}
public void close() throws JMSException {
if (!closed) {
closed = true;
try {
if (consumer != null) {
consumer.stop();
}
if (pollingConsumer != null) {
pollingConsumer.stop();
}
} catch (JMSException e) {
throw e;
} catch (Exception e) {
throw JMSExceptionSupport.create(e);
}
}
}
public MessageListener getMessageListener() throws JMSException {
return messageListener;
}
public void setMessageListener(MessageListener messageListener) throws JMSException {
this.messageListener = messageListener;
if (messageListener != null && consumer == null) {
consumer = createConsumer();
}
}
public Message receive() throws JMSException {
Exchange exchange = getPollingConsumer().receive();
return createMessage(exchange);
}
public Message receive(long timeoutMillis) throws JMSException {
Exchange exchange = getPollingConsumer().receive(timeoutMillis);
return createMessage(exchange);
}
public Message receiveNoWait() throws JMSException {
Exchange exchange = getPollingConsumer().receiveNoWait();
return createMessage(exchange);
}
// Properties
// -----------------------------------------------------------------------
public CamelDestination getDestination() {
return destination;
}
public Endpoint getEndpoint() {
return endpoint;
}
public String getMessageSelector() {
return messageSelector;
}
public boolean isNoLocal() {
return noLocal;
}
public ActiveMQSession getSession() {
return session;
}
// Implementation methods
// -----------------------------------------------------------------------
protected PollingConsumer getPollingConsumer() throws JMSException {
try {
if (pollingConsumer == null) {
pollingConsumer = endpoint.createPollingConsumer();
pollingConsumer.start();
}
return pollingConsumer;
} catch (JMSException e) {
throw e;
} catch (Exception e) {
throw JMSExceptionSupport.create(e);
}
}
protected Message createMessage(Exchange exchange) throws JMSException {
if (exchange != null) {
Message message = destination.getBinding().makeJmsMessage(exchange, session);
return message;
} else {
return null;
}
}
protected Consumer createConsumer() throws JMSException {
try {
Consumer answer = endpoint.createConsumer(new Processor() {
public void process(Exchange exchange) throws Exception {
Message message = createMessage(exchange);
getMessageListener().onMessage(message);
}
});
answer.start();
return answer;
} catch (JMSException e) {
throw e;
} catch (Exception e) {
throw JMSExceptionSupport.create(e);
}
}
protected void checkClosed() throws javax.jms.IllegalStateException {
if (closed) {
throw new IllegalStateException("The producer is closed");
}
}
}

View File

@ -1,106 +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.camel;
import javax.jms.Destination;
import javax.jms.IllegalStateException;
import javax.jms.JMSException;
import javax.jms.Message;
import org.apache.activemq.ActiveMQMessageProducerSupport;
import org.apache.activemq.ActiveMQSession;
import org.apache.activemq.util.JMSExceptionSupport;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Producer;
import org.apache.camel.component.jms.JmsMessage;
import org.apache.camel.util.ObjectHelper;
/**
* A JMS {@link javax.jms.MessageProducer} which sends message exchanges to a
* Camel {@link Endpoint}
*
*
*/
public class CamelMessageProducer extends ActiveMQMessageProducerSupport {
protected Producer producer;
private final CamelDestination destination;
private final Endpoint endpoint;
private boolean closed;
public CamelMessageProducer(CamelDestination destination, Endpoint endpoint, ActiveMQSession session) throws JMSException {
super(session);
this.destination = destination;
this.endpoint = endpoint;
try {
this.producer = endpoint.createProducer();
} catch (JMSException e) {
throw e;
} catch (Exception e) {
throw JMSExceptionSupport.create(e);
}
}
public CamelDestination getDestination() throws JMSException {
return destination;
}
public Endpoint getEndpoint() {
return endpoint;
}
public void close() throws JMSException {
if (!closed) {
closed = true;
try {
producer.stop();
} catch (JMSException e) {
throw e;
} catch (Exception e) {
throw JMSExceptionSupport.create(e);
}
}
}
public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
CamelDestination camelDestination = null;
if (ObjectHelper.equal(destination, this.destination)) {
camelDestination = this.destination;
} else {
// TODO support any CamelDestination?
throw new IllegalArgumentException("Invalid destination setting: " + destination + " when expected: " + this.destination);
}
try {
Exchange exchange = endpoint.createExchange(ExchangePattern.InOnly);
exchange.setIn(new JmsMessage(message, camelDestination.getBinding()));
producer.process(exchange);
} catch (JMSException e) {
throw e;
} catch (Exception e) {
throw JMSExceptionSupport.create(e);
}
}
protected void checkClosed() throws IllegalStateException {
if (closed) {
throw new IllegalStateException("The producer is closed");
}
}
}

View File

@ -1,48 +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.camel;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueReceiver;
import javax.jms.QueueSender;
import org.apache.activemq.ActiveMQSession;
/**
* A JMS {@link Queue} object which refers to a Camel endpoint
*
*
*/
public class CamelQueue extends CamelDestination implements Queue {
public CamelQueue(String uri) {
super(uri);
}
public String getQueueName() throws JMSException {
return getUri();
}
public QueueSender createSender(ActiveMQSession session) throws JMSException {
return new CamelQueueSender(this, resolveEndpoint(session), session);
}
public QueueReceiver createReceiver(ActiveMQSession session, String messageSelector) {
return new CamelQueueReceiver(this, resolveEndpoint(session), session, messageSelector);
}
}

View File

@ -1,50 +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.camel;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueReceiver;
import org.apache.activemq.ActiveMQSession;
import org.apache.camel.Endpoint;
/**
* A JMS {@link javax.jms.QueueReceiver} which consumes message exchanges from a
* Camel {@link org.apache.camel.Endpoint}
*
*
*/
public class CamelQueueReceiver extends CamelMessageConsumer implements QueueReceiver {
public CamelQueueReceiver(CamelQueue destination, Endpoint endpoint, ActiveMQSession session, String name) {
super(destination, endpoint, session, null, false);
}
/**
* Gets the <CODE>Queue</CODE> associated with this queue receiver.
*
* @return this receiver's <CODE>Queue</CODE>
* @throws JMSException if the JMS provider fails to get the queue for this queue
* receiver due to some internal error.
*/
public Queue getQueue() throws JMSException {
checkClosed();
return (Queue) super.getDestination();
}
}

View File

@ -1,91 +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.camel;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.QueueSender;
import org.apache.activemq.ActiveMQSession;
import org.apache.camel.Endpoint;
/**
* A JMS {@link javax.jms.QueueSender} which sends message exchanges to a Camel
* {@link org.apache.camel.Endpoint}
*
*
*/
public class CamelQueueSender extends CamelMessageProducer implements QueueSender {
public CamelQueueSender(CamelQueue destination, Endpoint endpoint, ActiveMQSession session) throws JMSException {
super(destination, endpoint, session);
}
/**
* Gets the queue associated with this <CODE>QueueSender</CODE>.
*
* @return this sender's queue
* @throws JMSException if the JMS provider fails to get the queue for this
* <CODE>QueueSender</CODE> due to some internal error.
*/
public Queue getQueue() throws JMSException {
return (Queue)super.getDestination();
}
/**
* Sends a message to a queue for an unidentified message producer. Uses the
* <CODE>QueueSender</CODE>'s default delivery mode, priority, and time
* to live. <p/> <p/> Typically, a message producer is assigned a queue at
* creation time; however, the JMS API also supports unidentified message
* producers, which require that the queue be supplied every time a message
* is sent.
*
* @param queue the queue to send this message to
* @param message the message to send
* @throws JMSException if the JMS provider fails to send the message due to
* some internal error.
* @see javax.jms.MessageProducer#getDeliveryMode()
* @see javax.jms.MessageProducer#getTimeToLive()
* @see javax.jms.MessageProducer#getPriority()
*/
public void send(Queue queue, Message message) throws JMSException {
super.send(queue, message);
}
/**
* Sends a message to a queue for an unidentified message producer,
* specifying delivery mode, priority and time to live. <p/> <p/> Typically,
* a message producer is assigned a queue at creation time; however, the JMS
* API also supports unidentified message producers, which require that the
* queue be supplied every time a message is sent.
*
* @param queue the queue to send this message to
* @param message the message to send
* @param deliveryMode the delivery mode to use
* @param priority the priority for this message
* @param timeToLive the message's lifetime (in milliseconds)
* @throws JMSException if the JMS provider fails to send the message due to
* some internal error.
*/
public void send(Queue queue, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
super.send(queue, message, deliveryMode, priority, timeToLive);
}
}

View File

@ -1,73 +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.camel;
import org.apache.activemq.broker.BrokerService;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
/**
* A shutdown hook that can be used to shutdown {@link CamelContext} before the
* ActiveMQ broker is shut down. This is sometimes important as if the broker is
* shutdown before Camel there could be a loss of data due to inflight exchanges
* not yet completed.
* <p>
* This hook can be added to ActiveMQ configuration ({@code activemq.xml}) as in
* the following example:
* <p>
* <code>
* &lt;bean xmlns=&quot;http://www.springframework.org/schema/beans&quot; class=&quot;org.apache.activemq.camel.CamelShutdownHook&quot; /&gt;
* </code>
*/
public final class CamelShutdownHook implements Runnable, CamelContextAware {
private static final Logger LOG = LoggerFactory.getLogger(CamelShutdownHook.class);
private CamelContext camelContext;
@Autowired
public CamelShutdownHook(final BrokerService brokerService) {
brokerService.addPreShutdownHook(this);
}
@Override
public CamelContext getCamelContext() {
return camelContext;
}
@Override
public void run() {
if (camelContext != null) {
try {
camelContext.stop();
} catch (final Exception e) {
LOG.warn("Unable to stop CamelContext", e);
}
} else {
LOG.warn("Unable to stop CamelContext, no CamelContext was set!");
}
}
@Override
public void setCamelContext(final CamelContext camelContext) {
this.camelContext = camelContext;
}
}

View File

@ -1,50 +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.camel;
import javax.jms.JMSException;
import javax.jms.Topic;
import javax.jms.TopicPublisher;
import javax.jms.TopicSubscriber;
import org.apache.activemq.ActiveMQSession;
/**
* A JMS {@link javax.jms.Topic} object which refers to a Camel endpoint
*
*
*/
public class CamelTopic extends CamelDestination implements Topic {
public CamelTopic(String uri) {
super(uri);
}
public String getTopicName() throws JMSException {
return getUri();
}
public TopicPublisher createPublisher(ActiveMQSession session) throws JMSException {
return new CamelTopicPublisher(this, resolveEndpoint(session), session);
}
public TopicSubscriber createDurableSubscriber(ActiveMQSession session, String name, String messageSelector, boolean noLocal) {
return new CamelTopicSubscriber(this, resolveEndpoint(session), session, name, messageSelector, noLocal);
}
}

View File

@ -1,146 +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.camel;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Topic;
import javax.jms.TopicPublisher;
import org.apache.activemq.ActiveMQSession;
import org.apache.camel.Endpoint;
/**
* A JMS {@link javax.jms.TopicPublisher} which sends message exchanges to a
* Camel {@link Endpoint}
*
*
*/
public class CamelTopicPublisher extends CamelMessageProducer implements TopicPublisher {
public CamelTopicPublisher(CamelTopic destination, Endpoint endpoint, ActiveMQSession session) throws JMSException {
super(destination, endpoint, session);
}
/**
* Gets the topic associated with this <CODE>TopicPublisher</CODE>.
*
* @return this publisher's topic
* @throws JMSException if the JMS provider fails to get the topic for this
* <CODE>TopicPublisher</CODE> due to some internal error.
*/
public Topic getTopic() throws JMSException {
return (Topic) super.getDestination();
}
/**
* Publishes a message to the topic. Uses the <CODE>TopicPublisher</CODE>'s
* default delivery mode, priority, and time to live.
*
* @param message the message to publish
* @throws JMSException if the JMS provider fails to publish the message due to
* some internal error.
* @throws javax.jms.MessageFormatException if an invalid message is specified.
* @throws javax.jms.InvalidDestinationException if a client uses this method with a <CODE>TopicPublisher
* </CODE> with an invalid topic.
* @throws java.lang.UnsupportedOperationException
* if a client uses this method with a <CODE>TopicPublisher
* </CODE> that did not specify a topic at creation time.
* @see javax.jms.MessageProducer#getDeliveryMode()
* @see javax.jms.MessageProducer#getTimeToLive()
* @see javax.jms.MessageProducer#getPriority()
*/
public void publish(Message message) throws JMSException {
super.send(message);
}
/**
* Publishes a message to the topic, specifying delivery mode, priority,
* and time to live.
*
* @param message the message to publish
* @param deliveryMode the delivery mode to use
* @param priority the priority for this message
* @param timeToLive the message's lifetime (in milliseconds)
* @throws JMSException if the JMS provider fails to publish the message due to
* some internal error.
* @throws javax.jms.MessageFormatException if an invalid message is specified.
* @throws javax.jms.InvalidDestinationException if a client uses this method with a <CODE>TopicPublisher
* </CODE> with an invalid topic.
* @throws java.lang.UnsupportedOperationException
* if a client uses this method with a <CODE>TopicPublisher
* </CODE> that did not specify a topic at creation time.
*/
public void publish(Message message, int deliveryMode, int priority,
long timeToLive) throws JMSException {
super.send(message, deliveryMode, priority, timeToLive);
}
/**
* Publishes a message to a topic for an unidentified message producer.
* Uses the <CODE>TopicPublisher</CODE>'s default delivery mode,
* priority, and time to live.
* <p/>
* <P>
* Typically, a message producer is assigned a topic at creation time;
* however, the JMS API also supports unidentified message producers, which
* require that the topic be supplied every time a message is published.
*
* @param topic the topic to publish this message to
* @param message the message to publish
* @throws JMSException if the JMS provider fails to publish the message due to
* some internal error.
* @throws javax.jms.MessageFormatException if an invalid message is specified.
* @throws javax.jms.InvalidDestinationException if a client uses this method with an invalid topic.
* @see javax.jms.MessageProducer#getDeliveryMode()
* @see javax.jms.MessageProducer#getTimeToLive()
* @see javax.jms.MessageProducer#getPriority()
*/
public void publish(Topic topic, Message message) throws JMSException {
super.send(topic, message);
}
/**
* Publishes a message to a topic for an unidentified message producer,
* specifying delivery mode, priority and time to live.
* <p/>
* <P>
* Typically, a message producer is assigned a topic at creation time;
* however, the JMS API also supports unidentified message producers, which
* require that the topic be supplied every time a message is published.
*
* @param topic the topic to publish this message to
* @param message the message to publish
* @param deliveryMode the delivery mode to use
* @param priority the priority for this message
* @param timeToLive the message's lifetime (in milliseconds)
* @throws JMSException if the JMS provider fails to publish the message due to
* some internal error.
* @throws javax.jms.MessageFormatException if an invalid message is specified.
* @throws javax.jms.InvalidDestinationException if a client uses this method with an invalid topic.
*/
public void publish(Topic topic, Message message, int deliveryMode,
int priority, long timeToLive) throws JMSException {
super.send(topic, message, deliveryMode, priority, timeToLive);
}
}

View File

@ -1,65 +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.camel;
import javax.jms.JMSException;
import javax.jms.Topic;
import javax.jms.TopicSubscriber;
import org.apache.activemq.ActiveMQSession;
import org.apache.camel.Endpoint;
/**
* A JMS {@link javax.jms.TopicSubscriber} which consumes message exchanges from a
* Camel {@link Endpoint}
*
*
*/
public class CamelTopicSubscriber extends CamelMessageConsumer implements TopicSubscriber {
public CamelTopicSubscriber(CamelTopic destination, Endpoint endpoint, ActiveMQSession session, String name, String messageSelector, boolean noLocal) {
super(destination, endpoint, session, messageSelector, noLocal);
}
/**
* Gets the <CODE>Topic</CODE> associated with this subscriber.
*
* @return this subscriber's <CODE>Topic</CODE>
* @throws javax.jms.JMSException if the JMS provider fails to get the topic for this topic
* subscriber due to some internal error.
*/
public Topic getTopic() throws JMSException {
checkClosed();
return (Topic) super.getDestination();
}
/**
* Gets the <CODE>NoLocal</CODE> attribute for this subscriber. The
* default value for this attribute is false.
*
* @return true if locally published messages are being inhibited
* @throws JMSException if the JMS provider fails to get the <CODE>NoLocal
* </CODE> attribute for this topic subscriber due to some
* internal error.
*/
public boolean getNoLocal() throws JMSException {
checkClosed();
return super.isNoLocal();
}
}

View File

@ -1,294 +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.camel.camelplugin;
import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerContext;
import org.apache.activemq.broker.BrokerFilter;
import org.apache.activemq.broker.ConnectionContext;
import org.apache.activemq.broker.ConsumerBrokerExchange;
import org.apache.activemq.broker.ProducerBrokerExchange;
import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.broker.region.MessageReference;
import org.apache.activemq.broker.region.Subscription;
import org.apache.activemq.command.ConsumerControl;
import org.apache.activemq.command.Message;
import org.apache.activemq.command.MessageAck;
import org.apache.activemq.command.MessageDispatch;
import org.apache.activemq.command.MessagePull;
import org.apache.activemq.command.Response;
import org.apache.activemq.command.TransactionId;
import org.apache.activemq.spring.Utils;
import org.apache.activemq.usage.Usage;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.RoutesDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.Resource;
import java.io.File;
import java.io.InputStream;
import java.util.List;
import java.util.concurrent.CountDownLatch;
/**
* A StatisticsBroker You can retrieve a Map Message for a Destination - or
* Broker containing statistics as key-value pairs The message must contain a
* replyTo Destination - else its ignored
*
*/
public class CamelRoutesBroker extends BrokerFilter {
private static Logger LOG = LoggerFactory.getLogger(CamelRoutesBroker.class);
private String routesFile = "";
private int checkPeriod = 1000;
private Resource theRoutes;
private DefaultCamelContext camelContext;
private long lastRoutesModified = -1;
private CountDownLatch countDownLatch;
/**
* Overide methods to pause the broker whilst camel routes are loaded
*/
@Override
public void send(ProducerBrokerExchange producerExchange, Message message) throws Exception {
blockWhileLoadingCamelRoutes();
super.send(producerExchange, message);
}
@Override
public void acknowledge(ConsumerBrokerExchange consumerExchange, MessageAck ack) throws Exception {
blockWhileLoadingCamelRoutes();
super.acknowledge(consumerExchange, ack);
}
@Override
public Response messagePull(ConnectionContext context, MessagePull pull) throws Exception {
blockWhileLoadingCamelRoutes();
return super.messagePull(context, pull);
}
@Override
public void processConsumerControl(ConsumerBrokerExchange consumerExchange, ConsumerControl control) {
blockWhileLoadingCamelRoutes();
super.processConsumerControl(consumerExchange, control);
}
@Override
public void reapplyInterceptor() {
blockWhileLoadingCamelRoutes();
super.reapplyInterceptor();
}
@Override
public void beginTransaction(ConnectionContext context, TransactionId xid) throws Exception {
blockWhileLoadingCamelRoutes();
super.beginTransaction(context, xid);
}
@Override
public int prepareTransaction(ConnectionContext context, TransactionId xid) throws Exception {
blockWhileLoadingCamelRoutes();
return super.prepareTransaction(context, xid);
}
@Override
public void rollbackTransaction(ConnectionContext context, TransactionId xid) throws Exception {
blockWhileLoadingCamelRoutes();
super.rollbackTransaction(context, xid);
}
@Override
public void commitTransaction(ConnectionContext context, TransactionId xid, boolean onePhase) throws Exception {
blockWhileLoadingCamelRoutes();
super.commitTransaction(context, xid, onePhase);
}
@Override
public void forgetTransaction(ConnectionContext context, TransactionId transactionId) throws Exception {
blockWhileLoadingCamelRoutes();
super.forgetTransaction(context, transactionId);
}
@Override
public void preProcessDispatch(MessageDispatch messageDispatch) {
blockWhileLoadingCamelRoutes();
super.preProcessDispatch(messageDispatch);
}
@Override
public void postProcessDispatch(MessageDispatch messageDispatch) {
blockWhileLoadingCamelRoutes();
super.postProcessDispatch(messageDispatch);
}
@Override
public boolean sendToDeadLetterQueue(ConnectionContext context, MessageReference messageReference, Subscription subscription, Throwable poisonCause) {
blockWhileLoadingCamelRoutes();
return super.sendToDeadLetterQueue(context, messageReference, subscription, poisonCause);
}
@Override
public void messageConsumed(ConnectionContext context, MessageReference messageReference) {
blockWhileLoadingCamelRoutes();
super.messageConsumed(context, messageReference);
}
@Override
public void messageDelivered(ConnectionContext context, MessageReference messageReference) {
blockWhileLoadingCamelRoutes();
super.messageDelivered(context, messageReference);
}
@Override
public void messageDiscarded(ConnectionContext context, Subscription sub, MessageReference messageReference) {
blockWhileLoadingCamelRoutes();
super.messageDiscarded(context, sub, messageReference);
}
@Override
public void isFull(ConnectionContext context, Destination destination, Usage<?> usage) {
blockWhileLoadingCamelRoutes();
super.isFull(context, destination, usage);
}
@Override
public void nowMasterBroker() {
blockWhileLoadingCamelRoutes();
super.nowMasterBroker();
}
/*
* Properties
*/
public String getRoutesFile() {
return routesFile;
}
public void setRoutesFile(String routesFile) {
this.routesFile = routesFile;
}
public int getCheckPeriod() {
return checkPeriod;
}
public void setCheckPeriod(int checkPeriod) {
this.checkPeriod = checkPeriod;
}
public CamelRoutesBroker(Broker next) {
super(next);
}
@Override
public void start() throws Exception {
super.start();
LOG.info("Starting CamelRoutesBroker");
camelContext = new DefaultCamelContext();
camelContext.setName("EmbeddedCamel-" + getBrokerName());
camelContext.start();
getBrokerService().getScheduler().executePeriodically(new Runnable() {
@Override
public void run() {
try {
loadCamelRoutes();
} catch (Throwable e) {
LOG.error("Failed to load Camel Routes", e);
}
}
}, getCheckPeriod());
}
@Override
public void stop() throws Exception {
CountDownLatch latch = this.countDownLatch;
if (latch != null){
latch.countDown();
}
if (camelContext != null){
camelContext.stop();
}
super.stop();
}
private void loadCamelRoutes() throws Exception{
if (theRoutes == null) {
String fileToUse = getRoutesFile();
if (fileToUse == null || fileToUse.trim().isEmpty()) {
BrokerContext brokerContext = getBrokerService().getBrokerContext();
if (brokerContext != null) {
String uri = brokerContext.getConfigurationUrl();
Resource resource = Utils.resourceFromString(uri);
if (resource.exists()) {
fileToUse = resource.getFile().getParent();
fileToUse += File.separator;
fileToUse += "routes.xml";
}
}
}
if (fileToUse != null && !fileToUse.isEmpty()){
theRoutes = Utils.resourceFromString(fileToUse);
setRoutesFile(theRoutes.getFile().getAbsolutePath());
}
}
if (!isStopped() && camelContext != null && theRoutes != null && theRoutes.exists()){
long lastModified = theRoutes.lastModified();
if (lastModified != lastRoutesModified){
CountDownLatch latch = new CountDownLatch(1);
this.countDownLatch = latch;
lastRoutesModified = lastModified;
List<RouteDefinition> currentRoutes = camelContext.getRouteDefinitions();
for (RouteDefinition rd:currentRoutes){
camelContext.stopRoute(rd);
camelContext.removeRouteDefinition(rd);
}
InputStream is = theRoutes.getInputStream();
RoutesDefinition routesDefinition = camelContext.loadRoutesDefinition(is);
for (RouteDefinition rd: routesDefinition.getRoutes()){
camelContext.startRoute(rd);
}
is.close();
latch.countDown();
this.countDownLatch=null;
}
}
}
private void blockWhileLoadingCamelRoutes(){
CountDownLatch latch = this.countDownLatch;
if (latch != null){
try {
latch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}

View File

@ -1,67 +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.camel.camelplugin;
import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A CamelRoutesBrokerPlugin
*
* load camel routes dynamically from a routes.xml file located in same directory as ActiveMQ.xml
*
* @org.apache.xbean.XBean element="camelRoutesBrokerPlugin"
*
*/
public class CamelRoutesBrokerPlugin implements BrokerPlugin {
private static Logger LOG = LoggerFactory.getLogger(CamelRoutesBrokerPlugin.class);
private String routesFile = "";
private int checkPeriod =1000;
public String getRoutesFile() {
return routesFile;
}
public void setRoutesFile(String routesFile) {
this.routesFile = routesFile;
}
public int getCheckPeriod() {
return checkPeriod;
}
public void setCheckPeriod(int checkPeriod) {
this.checkPeriod = checkPeriod;
}
/**
* @param broker
* @return the plug-in
* @throws Exception
* @see org.apache.activemq.broker.BrokerPlugin#installPlugin(org.apache.activemq.broker.Broker)
*/
public Broker installPlugin(Broker broker) throws Exception {
CamelRoutesBroker answer = new CamelRoutesBroker(broker);
answer.setCheckPeriod(getCheckPeriod());
answer.setRoutesFile(getRoutesFile());
LOG.info("Installing CamelRoutesBroker");
return answer;
}
}

View File

@ -1,249 +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.camel.component;
import java.net.URISyntaxException;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.jms.Connection;
import org.apache.activemq.EnhancedConnection;
import org.apache.activemq.Service;
import org.apache.activemq.advisory.DestinationSource;
import org.apache.camel.CamelContext;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.component.jms.JmsConfiguration;
import org.apache.camel.util.IntrospectionSupport;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.URISupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.connection.SingleConnectionFactory;
import org.springframework.jms.core.JmsTemplate;
/**
* The <a href="http://activemq.apache.org/camel/activemq.html">ActiveMQ Component</a>
*/
public class ActiveMQComponent extends JmsComponent {
private final CopyOnWriteArrayList<SingleConnectionFactory> singleConnectionFactoryList =
new CopyOnWriteArrayList<SingleConnectionFactory>();
private final CopyOnWriteArrayList<Service> pooledConnectionFactoryServiceList =
new CopyOnWriteArrayList<Service>();
private static final transient Logger LOG = LoggerFactory.getLogger(ActiveMQComponent.class);
private boolean exposeAllQueues;
private CamelEndpointLoader endpointLoader;
private EnhancedConnection connection;
DestinationSource source;
/**
* Creates an <a href="http://camel.apache.org/activemq.html">ActiveMQ Component</a>
*
* @return the created component
*/
public static ActiveMQComponent activeMQComponent() {
return new ActiveMQComponent();
}
/**
* Creates an <a href="http://camel.apache.org/activemq.html">ActiveMQ Component</a>
* connecting to the given <a href="http://activemq.apache.org/configuring-transports.html">broker URL</a>
*
* @param brokerURL the URL to connect to
* @return the created component
*/
public static ActiveMQComponent activeMQComponent(String brokerURL) {
ActiveMQComponent answer = new ActiveMQComponent();
if (answer.getConfiguration() instanceof ActiveMQConfiguration) {
((ActiveMQConfiguration) answer.getConfiguration())
.setBrokerURL(brokerURL);
}
return answer;
}
public ActiveMQComponent() {
}
public ActiveMQComponent(CamelContext context) {
super(context);
}
public ActiveMQComponent(ActiveMQConfiguration configuration) {
super();
setConfiguration(configuration);
}
/**
* 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>
*/
public void setBrokerURL(String brokerURL) {
if (getConfiguration() instanceof ActiveMQConfiguration) {
((ActiveMQConfiguration)getConfiguration()).setBrokerURL(brokerURL);
}
}
public void setTrustAllPackages(boolean trustAllPackages) {
if (getConfiguration() instanceof ActiveMQConfiguration) {
((ActiveMQConfiguration)getConfiguration()).setTrustAllPackages(trustAllPackages);
}
}
public boolean isExposeAllQueues() {
return exposeAllQueues;
}
/**
* If enabled this will cause all Queues in the ActiveMQ broker to be eagerly populated into the CamelContext
* so that they can be easily browsed by any Camel tooling. This option is disabled by default.
*/
public void setExposeAllQueues(boolean exposeAllQueues) {
this.exposeAllQueues = exposeAllQueues;
}
/**
* Enables or disables whether a PooledConnectionFactory will be used so that when
* messages are sent to ActiveMQ from outside of a message consuming thread, pooling will be used rather
* than the default with the Spring {@link JmsTemplate} which will create a new connection, session, producer
* for each message then close them all down again.
* <p/>
* The default value is true. Note that this requires an extra dependency on commons-pool2.
*/
public void setUsePooledConnection(boolean usePooledConnection) {
if (getConfiguration() instanceof ActiveMQConfiguration) {
((ActiveMQConfiguration)getConfiguration()).setUsePooledConnection(usePooledConnection);
}
}
/**
* Enables or disables whether a Spring {@link SingleConnectionFactory} will be used so that when
* messages are sent to ActiveMQ from outside of a message consuming thread, pooling will be used rather
* than the default with the Spring {@link JmsTemplate} which will create a new connection, session, producer
* for each message then close them all down again.
* <p/>
* The default value is false and a pooled connection is used by default.
*/
public void setUseSingleConnection(boolean useSingleConnection) {
if (getConfiguration() instanceof ActiveMQConfiguration) {
((ActiveMQConfiguration)getConfiguration()).setUseSingleConnection(useSingleConnection);
}
}
protected void addPooledConnectionFactoryService(Service pooledConnectionFactoryService) {
pooledConnectionFactoryServiceList.add(pooledConnectionFactoryService);
}
protected void addSingleConnectionFactory(SingleConnectionFactory singleConnectionFactory) {
singleConnectionFactoryList.add(singleConnectionFactory);
}
@Override
@SuppressWarnings("unchecked")
protected String convertPathToActualDestination(String path, Map<String, Object> parameters) {
// support ActiveMQ destination options using the destination. prefix
// http://activemq.apache.org/destination-options.html
Map options = IntrospectionSupport.extractProperties(parameters, "destination.");
String query;
try {
query = URISupport.createQueryString(options);
} catch (URISyntaxException e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
// if we have destination options then append them to the destination name
if (ObjectHelper.isNotEmpty(query)) {
return path + "?" + query;
} else {
return path;
}
}
@Override
protected void doStart() throws Exception {
super.doStart();
if (isExposeAllQueues()) {
createDestinationSource();
endpointLoader = new CamelEndpointLoader(getCamelContext(), source);
endpointLoader.afterPropertiesSet();
}
// use OriginalDestinationPropagateStrategy by default if no custom stategy has been set
if (getMessageCreatedStrategy() == null) {
setMessageCreatedStrategy(new OriginalDestinationPropagateStrategy());
}
}
protected void createDestinationSource() {
try {
if (source == null) {
if (connection == null) {
Connection value = getConfiguration().getConnectionFactory().createConnection();
if (value instanceof EnhancedConnection) {
connection = (EnhancedConnection) value;
} else {
throw new IllegalArgumentException("Created JMS Connection is not an EnhancedConnection: " + value);
}
connection.start();
}
source = connection.getDestinationSource();
}
} catch (Throwable t) {
LOG.info("Can't get destination source, endpoint completer will not work", t);
}
}
@Override
protected void doStop() throws Exception {
if (source != null) {
source.stop();
source = null;
}
if (connection != null) {
connection.close();
connection = null;
}
for (Service s : pooledConnectionFactoryServiceList) {
s.stop();
}
pooledConnectionFactoryServiceList.clear();
for (SingleConnectionFactory s : singleConnectionFactoryList) {
s.destroy();
}
singleConnectionFactoryList.clear();
super.doStop();
}
@Override
public void setConfiguration(JmsConfiguration configuration) {
if (configuration instanceof ActiveMQConfiguration) {
((ActiveMQConfiguration) configuration).setActiveMQComponent(this);
}
super.setConfiguration(configuration);
}
@Override
protected JmsConfiguration createConfiguration() {
ActiveMQConfiguration answer = new ActiveMQConfiguration();
answer.setActiveMQComponent(this);
return answer;
}
}

View File

@ -1,203 +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.camel.component;
import java.lang.reflect.Constructor;
import javax.jms.ConnectionFactory;
import org.apache.activemq.Service;
import org.apache.activemq.spring.ActiveMQConnectionFactory;
import org.apache.camel.component.jms.JmsConfiguration;
import org.springframework.jms.connection.JmsTransactionManager;
import org.springframework.jms.connection.SingleConnectionFactory;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.transaction.PlatformTransactionManager;
/**
*
*/
public class ActiveMQConfiguration extends JmsConfiguration {
private ActiveMQComponent activeMQComponent;
private String brokerURL = ActiveMQConnectionFactory.DEFAULT_BROKER_URL;
private boolean useSingleConnection = false;
private boolean usePooledConnection = true;
private boolean trustAllPackages;
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;
}
public boolean isUseSingleConnection() {
return useSingleConnection;
}
/**
* @deprecated - use JmsConfiguration#getUsername()
* @see JmsConfiguration#getUsername()
*/
@Deprecated
public String getUserName() {
return getUsername();
}
/**
* @deprecated - use JmsConfiguration#setUsername(String)
* @see JmsConfiguration#setUsername(String)
*/
@Deprecated
public void setUserName(String userName) {
setUsername(userName);
}
/**
* Enables or disables whether a Spring {@link SingleConnectionFactory} will be used so that when
* messages are sent to ActiveMQ from outside of a message consuming thread, pooling will be used rather
* than the default with the Spring {@link JmsTemplate} which will create a new connection, session, producer
* for each message then close them all down again.
* <p/>
* The default value is false and a pooled connection is used by default.
*/
public void setUseSingleConnection(boolean useSingleConnection) {
this.useSingleConnection = useSingleConnection;
}
public boolean isUsePooledConnection() {
return usePooledConnection;
}
/**
* Enables or disables whether a PooledConnectionFactory will be used so that when
* messages are sent to ActiveMQ from outside of a message consuming thread, pooling will be used rather
* than the default with the Spring {@link JmsTemplate} which will create a new connection, session, producer
* for each message then close them all down again.
* <p/>
* The default value is true. Note that this requires an extra dependency on commons-pool2.
*/
public void setUsePooledConnection(boolean usePooledConnection) {
this.usePooledConnection = usePooledConnection;
}
public boolean isTrustAllPackages() {
return trustAllPackages;
}
/**
* ObjectMessage objects depend on Java serialization of marshal/unmarshal object payload.
* This process is generally considered unsafe as malicious payload can exploit the host system.
* That's why starting with versions 5.12.2 and 5.13.0, ActiveMQ enforces users to explicitly whitelist packages
* that can be exchanged using ObjectMessages.
* <br/>
* This option can be set to <tt>true</tt> to trust all packages (eg whitelist is *).
* <p/>
* See more details at: http://activemq.apache.org/objectmessage.html
*/
public void setTrustAllPackages(boolean trustAllPackages) {
this.trustAllPackages = trustAllPackages;
}
/**
* Factory method to create a default transaction manager if one is not specified
*/
@Override
protected PlatformTransactionManager createTransactionManager() {
JmsTransactionManager answer = new JmsTransactionManager(getConnectionFactory());
answer.afterPropertiesSet();
return answer;
}
protected void setActiveMQComponent(ActiveMQComponent activeMQComponent) {
this.activeMQComponent = activeMQComponent;
}
@Override
protected ConnectionFactory createConnectionFactory() {
ActiveMQConnectionFactory answer = new ActiveMQConnectionFactory();
answer.setTrustAllPackages(trustAllPackages);
if (getUsername() != null) {
answer.setUserName(getUsername());
}
if (getPassword() != null) {
answer.setPassword(getPassword());
}
if (answer.getBeanName() == null) {
answer.setBeanName("Camel");
}
answer.setBrokerURL(getBrokerURL());
if (isUseSingleConnection()) {
SingleConnectionFactory scf = new SingleConnectionFactory(answer);
if (activeMQComponent != null) {
activeMQComponent.addSingleConnectionFactory(scf);
}
return scf;
}
else if (isUsePooledConnection()) {
ConnectionFactory pcf = createPooledConnectionFactory(answer);
if (activeMQComponent != null) {
activeMQComponent.addPooledConnectionFactoryService((Service) pcf);
}
return pcf;
}
else {
return answer;
}
}
protected ConnectionFactory createPooledConnectionFactory(ActiveMQConnectionFactory connectionFactory) {
// lets not use classes directly to avoid a runtime dependency on commons-pool2
// for folks not using this option
try {
Class type = loadClass("org.apache.activemq.pool.PooledConnectionFactory", getClass().getClassLoader());
Constructor constructor = type.getConstructor(org.apache.activemq.ActiveMQConnectionFactory.class);
return (ConnectionFactory) constructor.newInstance(connectionFactory);
}
catch (Exception e) {
throw new RuntimeException("Failed to instantiate PooledConnectionFactory: " + e, e);
}
}
private static Class<?> loadClass(String name, ClassLoader loader) throws ClassNotFoundException {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
if (contextClassLoader != null) {
try {
return contextClassLoader.loadClass(name);
}
catch (ClassNotFoundException e) {
try {
return loader.loadClass(name);
}
catch (ClassNotFoundException e1) {
throw e1;
}
}
} else {
return loader.loadClass(name);
}
}
}

View File

@ -1,33 +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.camel.component;
import org.apache.camel.component.jms.JmsConsumer;
import org.apache.camel.component.jms.JmsEndpoint;
import org.apache.camel.spi.UriEndpoint;
/**
* The activemq component allows messages to be sent to (or consumed from) Apache ActiveMQ.
*
* This component extends the Camel JMS component.
*/
@UriEndpoint(scheme = "activemq", title = "ActiveMQ", syntax = "activemq:destinationType:destinationName", consumerClass = JmsConsumer.class, label = "messaging")
public class ActiveMQEndpoint extends JmsEndpoint {
// needed for component documentation
}

View File

@ -1,179 +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.camel.component;
import java.util.Set;
import javax.annotation.PostConstruct;
import org.apache.activemq.advisory.DestinationEvent;
import org.apache.activemq.advisory.DestinationListener;
import org.apache.activemq.advisory.DestinationSource;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.Endpoint;
import org.apache.camel.component.jms.JmsEndpoint;
import org.apache.camel.component.jms.JmsQueueEndpoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A helper bean which populates a {@link CamelContext} with ActiveMQ Queue endpoints
*
* @org.apache.xbean.XBean
*/
public class CamelEndpointLoader implements CamelContextAware {
private static final transient Logger LOG = LoggerFactory.getLogger(CamelEndpointLoader.class);
private CamelContext camelContext;
private ActiveMQComponent component;
DestinationSource source;
public CamelEndpointLoader() {
}
public CamelEndpointLoader(CamelContext camelContext, DestinationSource source) {
this.camelContext = camelContext;
this.source = source;
}
/**
* JSR-250 callback wrapper; converts checked exceptions to runtime exceptions
*
* delegates to afterPropertiesSet, done to prevent backwards incompatible signature change
*
* fix: AMQ-4676
*/
@PostConstruct
private void postConstruct() {
try {
afterPropertiesSet();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
/**
*
* @throws Exception
* @org.apache.xbean.InitMethod
*/
public void afterPropertiesSet() throws Exception {
if (source != null) {
source.setDestinationListener(new DestinationListener() {
@Override
public void onDestinationEvent(DestinationEvent event) {
try {
ActiveMQDestination destination = event.getDestination();
if (destination instanceof ActiveMQQueue) {
ActiveMQQueue queue = (ActiveMQQueue) destination;
if (event.isAddOperation()) {
addQueue(queue);
} else {
removeQueue(queue);
}
} else if (destination instanceof ActiveMQTopic) {
ActiveMQTopic topic = (ActiveMQTopic) destination;
if (event.isAddOperation()) {
addTopic(topic);
} else {
removeTopic(topic);
}
}
} catch (Exception e) {
LOG.warn("Caught: " + e, e);
}
}
});
Set<ActiveMQQueue> queues = source.getQueues();
for (ActiveMQQueue queue : queues) {
addQueue(queue);
}
Set<ActiveMQTopic> topics = source.getTopics();
for (ActiveMQTopic topic : topics) {
addTopic(topic);
}
}
}
// Properties
//-------------------------------------------------------------------------
@Override
public CamelContext getCamelContext() {
return camelContext;
}
@Override
public void setCamelContext(CamelContext camelContext) {
this.camelContext = camelContext;
}
public ActiveMQComponent getComponent() {
if (component == null) {
component = camelContext.getComponent("activemq", ActiveMQComponent.class);
}
return component;
}
public void setComponent(ActiveMQComponent component) {
this.component = component;
}
// Implementation methods
//-------------------------------------------------------------------------
protected void addQueue(ActiveMQQueue queue) throws Exception {
String queueUri = getQueueUri(queue);
ActiveMQComponent jmsComponent = getComponent();
Endpoint endpoint = new JmsQueueEndpoint(queueUri, jmsComponent, queue.getPhysicalName(), jmsComponent.getConfiguration());
camelContext.addEndpoint(queueUri, endpoint);
}
protected String getQueueUri(ActiveMQQueue queue) {
return "activemq:" + queue.getPhysicalName();
}
protected void removeQueue(ActiveMQQueue queue) throws Exception {
String queueUri = getQueueUri(queue);
// lur cache of endpoints so they will disappear in time
// this feature needs a new component api - list available endpoints
camelContext.removeEndpoints(queueUri);
}
protected void addTopic(ActiveMQTopic topic) throws Exception {
String topicUri = getTopicUri(topic);
ActiveMQComponent jmsComponent = getComponent();
Endpoint endpoint = new JmsEndpoint(topicUri, jmsComponent, topic.getPhysicalName(), true, jmsComponent.getConfiguration());
camelContext.addEndpoint(topicUri, endpoint);
}
protected String getTopicUri(ActiveMQTopic topic) {
return "activemq:topic:" + topic.getPhysicalName();
}
protected void removeTopic(ActiveMQTopic topic) throws Exception {
String topicUri = getTopicUri(topic);
// lur cache of endpoints so they will disappear in time
// this feature needs a new component api - list available endpoints
camelContext.removeEndpoints(topicUri);
}
}

View File

@ -1,56 +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.camel.component;
import javax.jms.Message;
import javax.jms.Session;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQMessage;
import org.apache.camel.Exchange;
import org.apache.camel.component.jms.JmsMessage;
import org.apache.camel.component.jms.MessageCreatedStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A strategy to enrich JMS message with their original destination if the Camel
* route originates from a JMS destination.
*/
public class OriginalDestinationPropagateStrategy implements MessageCreatedStrategy {
private static final transient Logger LOG = LoggerFactory.getLogger(OriginalDestinationPropagateStrategy.class);
@Override
public void onMessageCreated(Message message, Session session, Exchange exchange, Throwable cause) {
if (exchange.getIn() instanceof JmsMessage) {
JmsMessage msg = exchange.getIn(JmsMessage.class);
Message jms = msg.getJmsMessage();
if (jms != null && jms instanceof ActiveMQMessage && message instanceof ActiveMQMessage) {
ActiveMQMessage amq = (ActiveMQMessage) jms;
if (amq.getOriginalDestination() == null) {
ActiveMQDestination from = amq.getDestination();
if (from != null) {
LOG.trace("Setting OriginalDestination: {} on {}", from, message);
((ActiveMQMessage) message).setOriginalDestination(from);
}
}
}
}
}
}

View File

@ -1,95 +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.camel.component.broker;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.activemq.broker.view.MessageBrokerView;
import org.apache.activemq.broker.view.MessageBrokerViewRegistry;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.camel.ComponentConfiguration;
import org.apache.camel.Endpoint;
import org.apache.camel.component.jms.JmsConfiguration;
import org.apache.camel.impl.UriEndpointComponent;
import org.apache.camel.spi.EndpointCompleter;
import static org.apache.camel.util.ObjectHelper.removeStartingCharacters;
/**
* The <a href="http://activemq.apache.org/broker-camel-component.html">Broker Camel component</a> allows to use Camel
* routing to move messages through the broker.
*/
public class BrokerComponent extends UriEndpointComponent implements EndpointCompleter {
public BrokerComponent() {
super(BrokerEndpoint.class);
}
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
BrokerConfiguration brokerConfiguration = new BrokerConfiguration();
setProperties(brokerConfiguration, parameters);
byte destinationType = ActiveMQDestination.QUEUE_TYPE;
if (remaining.startsWith(JmsConfiguration.QUEUE_PREFIX)) {
remaining = removeStartingCharacters(remaining.substring(JmsConfiguration.QUEUE_PREFIX.length()), '/');
} else if (remaining.startsWith(JmsConfiguration.TOPIC_PREFIX)) {
destinationType = ActiveMQDestination.TOPIC_TYPE;
remaining = removeStartingCharacters(remaining.substring(JmsConfiguration.TOPIC_PREFIX.length()), '/');
} else if (remaining.startsWith(JmsConfiguration.TEMP_QUEUE_PREFIX)) {
destinationType = ActiveMQDestination.TEMP_QUEUE_TYPE;
remaining = removeStartingCharacters(remaining.substring(JmsConfiguration.TEMP_QUEUE_PREFIX.length()), '/');
} else if (remaining.startsWith(JmsConfiguration.TEMP_TOPIC_PREFIX)) {
destinationType = ActiveMQDestination.TEMP_TOPIC_TYPE;
remaining = removeStartingCharacters(remaining.substring(JmsConfiguration.TEMP_TOPIC_PREFIX.length()), '/');
}
ActiveMQDestination destination = ActiveMQDestination.createDestination(remaining, destinationType);
BrokerEndpoint brokerEndpoint = new BrokerEndpoint(uri, this, remaining, destination, brokerConfiguration);
setProperties(brokerEndpoint, parameters);
return brokerEndpoint;
}
@Override
public List<String> completeEndpointPath(ComponentConfiguration componentConfiguration, String completionText) {
String brokerName = String.valueOf(componentConfiguration.getParameter("brokerName"));
MessageBrokerView messageBrokerView = MessageBrokerViewRegistry.getInstance().lookup(brokerName);
if (messageBrokerView != null) {
String destinationName = completionText;
Set<? extends ActiveMQDestination> set = messageBrokerView.getQueues();
if (completionText.startsWith("topic:")) {
set = messageBrokerView.getTopics();
destinationName = completionText.substring(6);
} else if (completionText.startsWith("queue:")) {
destinationName = completionText.substring(6);
}
ArrayList<String> answer = new ArrayList<String>();
for (ActiveMQDestination destination : set) {
if (destination.getPhysicalName().startsWith(destinationName)) {
answer.add(destination.getPhysicalName());
}
}
return answer;
}
return null;
}
}

View File

@ -1,39 +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.camel.component.broker;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
@UriParams
public class BrokerConfiguration {
@UriParam
private String brokerName = "";
public String getBrokerName() {
return brokerName;
}
/**
* Name of the broker
*/
public void setBrokerName(String brokerName) {
this.brokerName = brokerName;
}
}

View File

@ -1,66 +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.camel.component.broker;
import org.apache.activemq.broker.ProducerBrokerExchange;
import org.apache.activemq.broker.inteceptor.MessageInterceptor;
import org.apache.activemq.command.Message;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.Processor;
import org.apache.camel.component.jms.JmsBinding;
import org.apache.camel.impl.DefaultConsumer;
public class BrokerConsumer extends DefaultConsumer implements MessageInterceptor {
private final JmsBinding jmsBinding = new JmsBinding();
public BrokerConsumer(Endpoint endpoint, Processor processor) {
super(endpoint, processor);
}
@Override
protected void doStart() throws Exception {
super.doStart();
((BrokerEndpoint) getEndpoint()).addMessageInterceptor(this);
}
@Override
protected void doStop() throws Exception {
((BrokerEndpoint) getEndpoint()).removeMessageInterceptor(this);
super.doStop();
}
@Override
public void intercept(ProducerBrokerExchange producerExchange, Message message) {
Exchange exchange = getEndpoint().createExchange(ExchangePattern.InOnly);
exchange.setIn(new BrokerJmsMessage((javax.jms.Message) message, jmsBinding));
exchange.setProperty(Exchange.BINDING, jmsBinding);
exchange.setProperty(BrokerEndpoint.PRODUCER_BROKER_EXCHANGE, producerExchange);
try {
getProcessor().process(exchange);
} catch (Exception e) {
exchange.setException(e);
}
if (exchange.getException() != null) {
getExceptionHandler().handleException("Error processing intercepted message: " + message, exchange, exchange.getException());
}
}
}

View File

@ -1,138 +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.camel.component.broker;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.apache.activemq.broker.ProducerBrokerExchange;
import org.apache.activemq.broker.inteceptor.MessageInterceptor;
import org.apache.activemq.broker.inteceptor.MessageInterceptorRegistry;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.Message;
import org.apache.camel.Consumer;
import org.apache.camel.MultipleConsumersSupport;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.Service;
import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.impl.DefaultEndpoint;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriPath;
import org.apache.camel.util.UnsafeUriCharactersEncoder;
@ManagedResource(description = "Managed Camel Broker Endpoint")
@UriEndpoint(scheme = "broker", syntax = "broker:destination", consumerClass = BrokerConsumer.class, title = "Broker", label = "messaging")
public class BrokerEndpoint extends DefaultEndpoint implements MultipleConsumersSupport, Service {
static final String PRODUCER_BROKER_EXCHANGE = "producerBrokerExchange";
private MessageInterceptorRegistry messageInterceptorRegistry;
private List<MessageInterceptor> messageInterceptorList = new CopyOnWriteArrayList<MessageInterceptor>();
@UriPath(name = "destination") @Metadata(required = "true")
private String destinationName;
private final ActiveMQDestination destination;
@UriParam
private final BrokerConfiguration configuration;
public BrokerEndpoint(String uri, BrokerComponent component, String destinationName, ActiveMQDestination destination, BrokerConfiguration configuration) {
super(UnsafeUriCharactersEncoder.encode(uri), component);
this.destinationName = destinationName;
this.destination = destination;
this.configuration = configuration;
}
@Override
public Producer createProducer() throws Exception {
BrokerProducer producer = new BrokerProducer(this);
return producer;
}
@Override
public Consumer createConsumer(Processor processor) throws Exception {
BrokerConsumer consumer = new BrokerConsumer(this, processor);
configureConsumer(consumer);
return consumer;
}
@Override
public boolean isSingleton() {
return false;
}
@Override
public boolean isMultipleConsumersSupported() {
return true;
}
public ActiveMQDestination getDestination() {
return destination;
}
/**
* The name of the JMS destination
*/
public String getDestinationName() {
return destinationName;
}
@Override
protected void doStart() throws Exception {
super.doStart();
messageInterceptorRegistry = MessageInterceptorRegistry.getInstance().get(configuration.getBrokerName());
for (MessageInterceptor messageInterceptor : messageInterceptorList) {
addMessageInterceptor(messageInterceptor);
}
messageInterceptorList.clear();
}
@Override
protected void doStop() throws Exception {
super.doStop();
}
protected void addMessageInterceptor(MessageInterceptor messageInterceptor) {
if (isStarted()) {
messageInterceptorRegistry.addMessageInterceptor(destination, messageInterceptor);
} else {
messageInterceptorList.add(messageInterceptor);
}
}
protected void removeMessageInterceptor(MessageInterceptor messageInterceptor) {
messageInterceptorRegistry.removeMessageInterceptor(destination, messageInterceptor);
}
protected void inject(ProducerBrokerExchange producerBrokerExchange, Message message) throws Exception {
ProducerBrokerExchange pbe = producerBrokerExchange;
if (message != null) {
message.setDestination(destination);
if (producerBrokerExchange != null && producerBrokerExchange.getRegionDestination() != null){
if (!producerBrokerExchange.getRegionDestination().getActiveMQDestination().equals(destination)){
//The message broker will create a new ProducerBrokerExchange with the
//correct region broker set
pbe = null;
}
}
messageInterceptorRegistry.injectMessage(pbe, message);
}
}
}

View File

@ -1,53 +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.camel.component.broker;
import javax.jms.Message;
import org.apache.camel.component.jms.JmsBinding;
import org.apache.camel.component.jms.JmsMessage;
import org.apache.camel.component.jms.JmsMessageHelper;
import org.apache.camel.util.ObjectHelper;
public class BrokerJmsMessage extends JmsMessage {
public BrokerJmsMessage(Message jmsMessage, JmsBinding binding) {
super(jmsMessage, binding);
}
@Override
public String toString() {
if (getJmsMessage() != null) {
return "BrokerJmsMessage[JMSMessageID: " + JmsMessageHelper.getJMSMessageID(getJmsMessage());
} else {
return "BrokerJmsMessage@" + ObjectHelper.getIdentityHashCode(this);
}
}
@Override
public void copyFrom(org.apache.camel.Message that) {
super.copyFrom(that);
if (that instanceof JmsMessage && getJmsMessage() == null) {
setJmsMessage(((JmsMessage) that).getJmsMessage());
}
}
@Override
public BrokerJmsMessage newInstance() {
return new BrokerJmsMessage(null, getBinding());
}
}

View File

@ -1,115 +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.camel.component.broker;
import org.apache.activemq.broker.ProducerBrokerExchange;
import org.apache.activemq.command.ActiveMQMessage;
import org.apache.camel.AsyncCallback;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.component.jms.JmsMessage;
import org.apache.camel.impl.DefaultAsyncProducer;
import javax.jms.JMSException;
import java.util.Map;
public class BrokerProducer extends DefaultAsyncProducer {
private final BrokerEndpoint brokerEndpoint;
public BrokerProducer(BrokerEndpoint endpoint) {
super(endpoint);
brokerEndpoint = endpoint;
}
@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
try {
//In the middle of the broker - InOut doesn't make any sense
//so we do in only
return processInOnly(exchange, callback);
} catch (Throwable e) {
// must catch exception to ensure callback is invoked as expected
// to let Camel error handling deal with this
exchange.setException(e);
callback.done(true);
return true;
}
}
protected boolean processInOnly(final Exchange exchange, final AsyncCallback callback) {
try {
ActiveMQMessage message = getMessage(exchange);
if (message != null) {
message.setDestination(brokerEndpoint.getDestination());
//if the ProducerBrokerExchange is null the broker will create it
ProducerBrokerExchange producerBrokerExchange = (ProducerBrokerExchange) exchange.getProperty(BrokerEndpoint.PRODUCER_BROKER_EXCHANGE);
brokerEndpoint.inject(producerBrokerExchange, message);
}
} catch (Exception e) {
exchange.setException(e);
}
callback.done(true);
return true;
}
private ActiveMQMessage getMessage(Exchange exchange) throws IllegalStateException, JMSException {
Message camelMessage = getMessageFromExchange(exchange);
checkOriginalMessage(camelMessage);
ActiveMQMessage result = (ActiveMQMessage) ((JmsMessage) camelMessage).getJmsMessage();
applyNewHeaders(result, camelMessage.getHeaders());
return result;
}
private Message getMessageFromExchange(Exchange exchange) {
if (exchange.hasOut()) {
return exchange.getOut();
}
return exchange.getIn();
}
private void checkOriginalMessage(Message camelMessage) throws IllegalStateException {
/**
* We purposely don't want to support injecting messages half-way through
* broker processing - use the activemq camel component for that - but
* we will support changing message headers and destinations.
*/
if (!(camelMessage instanceof JmsMessage)) {
throw new IllegalStateException("Not the original message from the broker " + camelMessage);
}
javax.jms.Message message = ((JmsMessage) camelMessage).getJmsMessage();
if (!(message instanceof ActiveMQMessage)) {
throw new IllegalStateException("Not the original message from the broker " + message);
}
}
private void applyNewHeaders(ActiveMQMessage message, Map<String, Object> headers) throws JMSException {
for (Map.Entry<String, Object> entry : headers.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if(value == null) {
continue;
}
message.setObjectProperty(key, value.toString(), false);
}
}
}

View File

@ -1,29 +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.
-->
<html>
<head>
</head>
<body>
Defines the <a href="http://camel.apache.org/activemq.html">ActiveMQ Component</a> for
<a href="http://camel.apache.org">Camel</a> to provide great
<a href="http://camel.apache.org/enterprise-integration-patterns.html">Enterprise Integration Patterns</a>
integration for ActiveMQ users.
</body>
</html>

View File

@ -1,42 +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.camel.converter;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.camel.Converter;
/**
*
*/
@Converter
public class ActiveMQConverter {
/**
* Converts a URL in ActiveMQ syntax to a destination such as to support
* "queue://foo.bar" or 'topic://bar.whatnot". Things default to queues if no scheme.
*
* This allows ActiveMQ destinations to be passed around as Strings and converted back again.
*
* @param name is the name of the queue or the full URI using prefixes queue:// or topic://
* @return the ActiveMQ destination
*/
@Converter
public static ActiveMQDestination toDestination(String name) {
return ActiveMQDestination.createDestination(name, ActiveMQDestination.QUEUE_TYPE);
}
}

View File

@ -1,103 +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.camel.converter;
import java.io.Serializable;
import javax.jms.JMSException;
import javax.jms.MessageListener;
import javax.jms.Message;
import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.command.ActiveMQObjectMessage;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.apache.camel.Converter;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.component.jms.JmsBinding;
import org.apache.camel.component.jms.JmsEndpoint;
/**
*
*/
@Converter
public class ActiveMQMessageConverter {
private JmsBinding binding = new JmsBinding();
/**
* Converts the inbound message exchange to an ActiveMQ JMS message
*
* @return the ActiveMQ message
*/
@Converter
public ActiveMQMessage toMessage(Exchange exchange) throws JMSException {
ActiveMQMessage message = createActiveMQMessage(exchange);
getBinding().appendJmsProperties(message, exchange);
return message;
}
/**
* Allows a JMS {@link MessageListener} to be converted to a Camel {@link Processor}
* so that we can provide better
* <a href="">Bean Integration</a> so that we can use any JMS MessageListener in
* in Camel as a bean
* @param listener the JMS message listener
* @return a newly created Camel Processor which when invoked will invoke
* {@link MessageListener#onMessage(Message)}
*/
@Converter
public Processor toProcessor(final MessageListener listener) {
return new Processor() {
public void process(Exchange exchange) throws Exception {
Message message = toMessage(exchange);
listener.onMessage(message);
}
@Override
public String toString() {
return "Processor of MessageListener: " + listener;
}
};
}
private static ActiveMQMessage createActiveMQMessage(Exchange exchange) throws JMSException {
Object body = exchange.getIn().getBody();
if (body instanceof String) {
ActiveMQTextMessage answer = new ActiveMQTextMessage();
answer.setText((String) body);
return answer;
} else if (body instanceof Serializable) {
ActiveMQObjectMessage answer = new ActiveMQObjectMessage();
answer.setObject((Serializable) body);
return answer;
} else {
return new ActiveMQMessage();
}
}
// Properties
//-------------------------------------------------------------------------
public JmsBinding getBinding() {
return binding;
}
public void setBinding(JmsBinding binding) {
this.binding = binding;
}
}

View File

@ -1,28 +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.
-->
<html>
<head>
</head>
<body>
Defines the <a href="http://camel.apache.org/type-converter.html">Type Converters</a> for working
with JMS and ActiveMQ with <a href="http://camel.apache.org/">Camel</a>
<a href="http://camel.apache.org/enterprise-integration-patterns.html">Enterprise Integration Patterns</a>
</body>
</html>

View File

@ -1,29 +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.
-->
<html>
<head>
</head>
<body>
Defines a JMS client which is capable of sending and receiving messages to
<a href="http://camel.apache.org">Apache Camel</a>
<a href="http://camel.apache.org/endpoint.html">endpoints</a> to provide
<a href="http://camel.apache.org/enterprise-integration-patterns.html">Enterprise Integration Patterns</a>
integration in any JMS client application.
</body>
</html>

View File

@ -1,19 +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.
#
org.apache.activemq.camel.converter.ActiveMQConverter
org.apache.activemq.camel.converter.ActiveMQMessageConverter

View File

@ -1,18 +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.
#
class=org.apache.activemq.camel.component.ActiveMQComponent

View File

@ -1,18 +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.
#
class=org.apache.activemq.camel.component.broker.BrokerComponent

View File

@ -1,22 +0,0 @@
<?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.
-->
<person user="james">
<firstName>James</firstName>
<lastName>Strachan</lastName>
<city>London</city>
</person>

View File

@ -1,96 +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.camel;
import static org.junit.Assert.fail;
import org.apache.activemq.camel.AMQ2611Test.Consumer;
import org.apache.activemq.camel.component.ActiveMQComponent;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.junit.After;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AMQ2240Test {
private static final Logger LOG = LoggerFactory.getLogger(AMQ2240Test.class);
private CamelContext camelContext = null;
@After
public void destroyCamelContext() throws Exception {
if (camelContext != null) {
camelContext.stop();
camelContext = null;
}
}
@Test
public void testBadVMTransportOptionsJMSPrefix() throws Exception {
try{
final String vmUri = "vm://localhost?" +
"jms.redeliveryPolicy.maximumRedeliveries=0&" +
"jms.redeliveryPolicy.initialRedeliveryDelay=500&" +
"jms.useAsyncSend=false&jms.sendTimeout=ABC&" +
"jms.maxXXXXReconnectAttempts=1&jms.timeout=3000";
LOG.info("creating context with bad URI: " + vmUri);
ActiveMQComponent amq = ActiveMQComponent.activeMQComponent(vmUri);
amq.getConfiguration().getConnectionFactory();
fail("Should have received an exception from the bad URI.");
} catch(Exception e) {
// Expected
}
}
@Test
public void testBadVMTransportOptionsBrokerPrefix() throws Exception {
try {
final String vmUri = "vm://localhost?" +
"broker.XXX=foo&broker.persistent=XXX&broker.useJmx=false";
LOG.info("creating context with bad URI: " + vmUri);
ActiveMQComponent amq = ActiveMQComponent.activeMQComponent(vmUri);
camelContext = new DefaultCamelContext();
camelContext.addComponent("activemq", amq);
final String queueEndpointName = "activemq:queuetest.Queue";
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from(queueEndpointName).bean(Consumer.class, "consume");
}
});
camelContext.start();
final ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBody(queueEndpointName, "message");
fail("Should have received an exception from the bad URI.");
} catch(Exception e) {
// Expected
}
}
}

View File

@ -1,88 +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.camel;
import junit.framework.TestCase;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.camel.component.ActiveMQComponent;
import org.apache.camel.Body;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AMQ2611Test extends TestCase {
private static final String BROKER_URL = "tcp://localhost:61616";
private static final String QUEUE_NAME = "test.queue";
private static final Logger log = LoggerFactory.getLogger(AMQ2611Test.class);
private BrokerService brokerService = null;
private CamelContext camelContext = null;
private void createBroker() throws Exception {
brokerService = new BrokerService();
brokerService.addConnector(BROKER_URL);
brokerService.start();
}
public static class Consumer {
public void consume(@Body String message) {
log.info("consume message = " + message);
}
}
private void createCamelContext() throws Exception {
log.info("creating context and sending message");
camelContext = new DefaultCamelContext();
camelContext.addComponent("activemq", ActiveMQComponent.activeMQComponent(BROKER_URL));
final String queueEndpointName = "activemq:queue" + QUEUE_NAME;
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from(queueEndpointName).bean(Consumer.class, "consume");
}
});
camelContext.start();
final ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
producerTemplate.sendBody(queueEndpointName, "message");
}
private void destroyCamelContext() throws Exception {
log.info("destroying context");
camelContext.stop();
camelContext = null;
}
public void testConnections() {
try {
createBroker();
int i = 0;
while (i++ < 5) {
createCamelContext();
Thread.sleep(1000);
destroyCamelContext();
Thread.sleep(1000);
assertEquals(0, brokerService.getConnectorByName(BROKER_URL).getConnections().size());
}
} catch (Exception e) {
log.warn("run", e);
}
}
}

View File

@ -1,49 +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.camel;
import org.apache.activemq.camel.component.ActiveMQComponent;
import org.apache.activemq.camel.component.ActiveMQConfiguration;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class ActiveMQComponentFactoryUserNamePasswordTest extends CamelSpringTestSupport {
@Override
protected AbstractApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("org/apache/activemq/camel/ActiveMQComponentFactoryUserNamePassword.xml");
}
@Test
public void testActiveMQ() throws Exception {
ActiveMQComponent comp = context.getComponent("activemq", ActiveMQComponent.class);
assertNotNull(comp);
ActiveMQConfiguration config = (ActiveMQConfiguration) comp.getConfiguration();
assertNotNull(config);
assertEquals("admin2", config.getUserName());
assertEquals("secret2", config.getPassword());
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
template.sendBody("activemq:queue:bar", "Hello World");
assertMockEndpointsSatisfied();
}
}

View File

@ -1,49 +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.camel;
import org.apache.activemq.camel.component.ActiveMQComponent;
import org.apache.activemq.camel.component.ActiveMQConfiguration;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class ActiveMQComponentUserNamePasswordTest extends CamelSpringTestSupport {
@Override
protected AbstractApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("org/apache/activemq/camel/ActiveMQComponentUserNamePassword.xml");
}
@Test
public void testActiveMQ() throws Exception {
ActiveMQComponent comp = context.getComponent("activemq", ActiveMQComponent.class);
assertNotNull(comp);
ActiveMQConfiguration config = (ActiveMQConfiguration) comp.getConfiguration();
assertNotNull(config);
assertEquals("admin", config.getUserName());
assertEquals("secret", config.getPassword());
getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
template.sendBody("activemq:queue:foo", "Hello World");
assertMockEndpointsSatisfied();
}
}

View File

@ -1,80 +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.camel;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.camel.component.ActiveMQComponent;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class BrokerPreShutdownHookTest {
static class TestProcessor implements Processor {
boolean messageReceived;
@Override
public void process(final Exchange exchange) throws Exception {
messageReceived = true;
}
}
@Test
public void testShouldCleanlyShutdownCamelBeforeStoppingBroker() throws Exception {
final BrokerService broker = new BrokerService();
broker.setBrokerName("testBroker");
broker.setUseJmx(true);
broker.setPersistent(false);
broker.addConnector("vm://testBroker");
final DefaultCamelContext camel = new DefaultCamelContext();
camel.setName("test-camel");
final CamelShutdownHook hook = new CamelShutdownHook(broker);
hook.setCamelContext(camel);
broker.start();
camel.addComponent("testq", ActiveMQComponent.activeMQComponent("vm://testBroker?create=false"));
final TestProcessor processor = new TestProcessor();
camel.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("testq:test.in").delay(200).process(processor);
}
});
camel.start();
final ProducerTemplate producer = camel.createProducerTemplate();
producer.sendBody("testq:test.in", "Hi!");
producer.stop();
broker.stop();
assertTrue("Message should be received", processor.messageReceived);
assertTrue("Camel context should be stopped", camel.isStopped());
assertTrue("Broker should be stopped", broker.isStopped());
}
}

View File

@ -1,47 +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.camel;
import org.apache.camel.CamelContext;
import org.apache.camel.EndpointInject;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class CamelDestinationExclusiveConsumerTest {
@Autowired
protected CamelContext camelContext;
@EndpointInject(uri = "mock:results")
protected MockEndpoint expectedEndpoint;
@Test
public void testMocksAreValid() throws Exception {
expectedEndpoint.expectedMessageCount(1);
MockEndpoint.assertIsSatisfied(camelContext);
}
}

View File

@ -1,147 +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.camel;
import java.util.Hashtable;
import javax.naming.Context;
import org.apache.activemq.EmbeddedBrokerTestSupport;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.util.jndi.JndiContext;
/**
* A helper class for test cases which use an embedded broker and use Camel to
* do the routing
*
*/
public abstract class CamelEmbeddedBrokerTestSupport extends EmbeddedBrokerTestSupport {
protected CamelContext camelContext;
protected ProducerTemplate template;
@Override
protected void setUp() throws Exception {
bindAddress = "tcp://localhost:61616";
super.setUp();
camelContext = createCamelContext();
addCamelRoutes(camelContext);
assertValidContext(camelContext);
camelContext.start();
template = camelContext.createProducerTemplate();
template.start();
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
if (template != null) {
template.stop();
}
if (camelContext != null) {
camelContext.stop();
}
}
protected CamelContext createCamelContext() throws Exception {
return new DefaultCamelContext(createJndiContext());
}
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Context createJndiContext() throws Exception {
return new JndiContext(new Hashtable());
}
protected void addCamelRoutes(CamelContext camelContext) throws Exception {
}
/**
* Resolves a mandatory endpoint for the given URI or an exception is thrown
*
* @param uri
* the Camel <a href="">URI</a> to use to create or resolve an
* endpoint
* @return the endpoint
*/
protected Endpoint resolveMandatoryEndpoint(String uri) {
return resolveMandatoryEndpoint(camelContext, uri);
}
/**
* Resolves a mandatory endpoint for the given URI and expected type or an
* exception is thrown
*
* @param uri
* the Camel <a href="">URI</a> to use to create or resolve an
* endpoint
* @return the endpoint
*/
protected <T extends Endpoint> T resolveMandatoryEndpoint(String uri, Class<T> endpointType) {
return resolveMandatoryEndpoint(camelContext, uri, endpointType);
}
/**
* Resolves an endpoint and asserts that it is found
*/
protected Endpoint resolveMandatoryEndpoint(CamelContext context, String uri) {
Endpoint endpoint = context.getEndpoint(uri);
assertNotNull("No endpoint found for URI: " + uri, endpoint);
return endpoint;
}
/**
* Resolves an endpoint and asserts that it is found
*/
protected <T extends Endpoint> T resolveMandatoryEndpoint(CamelContext context, String uri, Class<T> endpointType) {
T endpoint = context.getEndpoint(uri, endpointType);
assertNotNull("No endpoint found for URI: " + uri, endpoint);
return endpoint;
}
/**
* Resolves the mandatory Mock endpoint using a URI of the form
* <code>mock:someName</code>
*
* @param uri
* the URI which typically starts with "mock:" and has some name
* @return the mandatory mock endpoint or an exception is thrown if it could
* not be resolved
*/
protected MockEndpoint getMockEndpoint(String uri) {
return resolveMandatoryEndpoint(uri, MockEndpoint.class);
}
/**
* Asserts that all the expectations of the Mock endpoints are valid
*/
protected void assertMockEndpointsSatisifed() throws InterruptedException {
MockEndpoint.assertIsSatisfied(camelContext);
}
protected void assertValidContext(CamelContext context) {
assertNotNull("No context found!", context);
}
}

View File

@ -1,111 +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.camel;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.network.DiscoveryNetworkConnector;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import java.net.URI;
import java.util.Arrays;
public class CamelJmsRequestReplyNobTest extends CamelSpringTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(CamelJmsRequestReplyNobTest.class);
@Test
public void testRoundTrip() throws Exception {
Destination destination = getMandatoryBean(Destination.class, "consumeFrom");
// lets create a message
ConnectionFactory factoryCON = getMandatoryBean(ConnectionFactory.class, "CON");
Connection consumerConnection = factoryCON.createConnection();
consumerConnection.start();
Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
LOG.info("Consuming from: " + destination);
MessageConsumer consumer = consumerSession.createConsumer(destination);
// lets create a message
ConnectionFactory factoryPRO = getMandatoryBean(ConnectionFactory.class, "PRO");
Connection producerConnection = factoryPRO.createConnection();
producerConnection.start();
Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = producerSession.createProducer(producerSession.createQueue("incoming1"));
Message message = producerSession.createTextMessage("Where are you");
message.setStringProperty("foo", "bar");
producer.send(message);
message = consumer.receive(10000);
assertNotNull("Should have received a message from destination: " + destination, message);
TextMessage textMessage = assertIsInstanceOf(TextMessage.class, message);
assertEquals("Message body", "If you don't ask me my name, I'm not going to tell you!", textMessage.getText());
}
private BrokerService createBroker(String name) throws Exception {
BrokerService brokerService = new BrokerService();
brokerService.setDeleteAllMessagesOnStartup(true);
brokerService.setBrokerName(name);
brokerService.setUseJmx(false);
brokerService.setPersistent(false);
brokerService.addConnector("tcp://0.0.0.0:0");
return brokerService;
}
BrokerService producerBroker, consumerBroker;
@SuppressWarnings("unchecked")
@Override
protected AbstractXmlApplicationContext createApplicationContext() {
try {
consumerBroker = createBroker("CON");
producerBroker = createBroker("PRO");
DiscoveryNetworkConnector discoveryNetworkConnector = new DiscoveryNetworkConnector();
discoveryNetworkConnector.setUri(new URI("static:" + consumerBroker.getTransportConnectorByScheme("tcp").getPublishableConnectString()));
discoveryNetworkConnector.setDuplex(true);
discoveryNetworkConnector.setNetworkTTL(2);
discoveryNetworkConnector.setDynamicallyIncludedDestinations(Arrays.asList(new ActiveMQDestination[]{new ActiveMQQueue("service1")}));
discoveryNetworkConnector.setDestinationFilter("ActiveMQ.Advisory.TempQueue,ActiveMQ.Advisory.TempTopic,ActiveMQ.Advisory.Consumer.Queue.>");
producerBroker.addNetworkConnector(discoveryNetworkConnector);
consumerBroker.start();
producerBroker.start();
} catch (Exception e) {
throw new RuntimeException("Failed to start broker", e);
}
return new ClassPathXmlApplicationContext("org/apache/activemq/camel/requestReply.xml");
}
}

View File

@ -1,105 +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.camel;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
*
*/
public class CamelJmsTest extends CamelSpringTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(CamelJmsTest.class);
protected String expectedBody = "<hello>world!</hello>";
@Test
public void testSendingViaJmsIsReceivedByCamel() throws Exception {
MockEndpoint result = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
result.expectedBodiesReceived(expectedBody);
result.message(0).header("foo").isEqualTo("bar");
// lets create a message
Destination destination = getMandatoryBean(Destination.class, "sendTo");
ConnectionFactory factory = getMandatoryBean(ConnectionFactory.class, "connectionFactory");
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(destination);
// now lets send a message
ObjectMessage message = session.createObjectMessage(expectedBody);
message.setStringProperty("foo", "bar");
producer.send(message);
result.assertIsSatisfied();
LOG.info("Received message: " + result.getReceivedExchanges());
}
@Test
public void testConsumingViaJMSReceivesMessageFromCamel() throws Exception {
// lets create a message
Destination destination = getMandatoryBean(Destination.class, "consumeFrom");
ConnectionFactory factory = getMandatoryBean(ConnectionFactory.class, "connectionFactory");
ProducerTemplate template = getMandatoryBean(ProducerTemplate.class, "camelTemplate");
assertNotNull("template is valid", template);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
LOG.info("Consuming from: " + destination);
MessageConsumer consumer = session.createConsumer(destination);
// now lets send a message
template.sendBody("seda:consumer", expectedBody);
Message message = consumer.receive(5000);
assertNotNull("Should have received a message from destination: " + destination, message);
TextMessage textMessage = assertIsInstanceOf(TextMessage.class, message);
assertEquals("Message body", expectedBody, textMessage.getText());
LOG.info("Received message: " + message);
}
protected int getExpectedRouteCount() {
return 0;
}
protected ClassPathXmlApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("org/apache/activemq/camel/spring.xml");
}
}

View File

@ -1,158 +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.camel;
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import junit.framework.TestCase;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.camel.component.ActiveMQComponent;
import org.apache.activemq.util.ThreadTracker;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.junit.Assert;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// see: https://issues.apache.org/activemq/browse/AMQ-2966
public class CamelVMTransportRoutingTest extends TestCase {
private static final Logger log = LoggerFactory.getLogger(CamelVMTransportRoutingTest.class);
private BrokerService broker = null;
private TransportConnector connector = null;
private CamelContext camelContext = null;
private Connection senderConnection;
private Connection receiverConnection1;
private Connection receiverConnection2;
private final String MSG_STRING = "MESSAGE-TEXT";
private final String SENDER_TOPIC = "A";
private final String RECEIVER_TOPIC = "B";
@SuppressWarnings("unused")
public void testSendReceiveWithCamelRouteIntercepting() throws Exception {
final int MSG_COUNT = 1000;
Session sendSession = senderConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session receiverSession1 = receiverConnection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session receiverSession2 = receiverConnection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination sendTo = sendSession.createTopic(SENDER_TOPIC);
Destination receiveFrom = receiverSession1.createTopic(RECEIVER_TOPIC);
TextMessage message = sendSession.createTextMessage(MSG_STRING);
MessageConsumer receiver1 = receiverSession1.createConsumer(receiveFrom);
MessageConsumer receiver2 = receiverSession2.createConsumer(receiveFrom);
MessageProducer sender = sendSession.createProducer(sendTo);
for( int i = 0; i < MSG_COUNT; ++i ) {
sender.send(message);
}
for( int i = 0; i < MSG_COUNT; ++i ) {
log.debug("Attempting Received for Message #" + i);
TextMessage received1 = (TextMessage) receiver1.receive(5000);
Assert.assertNotNull(received1);
Assert.assertEquals(MSG_STRING, received1.getText());
}
}
protected BrokerService createBroker() throws Exception {
BrokerService service = new BrokerService();
service.setPersistent(false);
service.setUseJmx(false);
connector = service.addConnector("tcp://localhost:0");
return service;
}
@Override
public void setUp() throws Exception {
broker = createBroker();
broker.start();
broker.waitUntilStarted();
Thread.sleep(1000);
createCamelContext();
ActiveMQConnectionFactory connFactory = new ActiveMQConnectionFactory(connector.getConnectUri());
senderConnection = connFactory.createConnection();
receiverConnection1 = connFactory.createConnection();
receiverConnection2 = connFactory.createConnection();
receiverConnection1.start();
receiverConnection2.start();
}
@Override
public void tearDown() throws Exception {
if( senderConnection != null ) {
senderConnection.close();
}
if( receiverConnection1 != null ) {
receiverConnection1.close();
}
if( receiverConnection2 != null ) {
receiverConnection2.close();
}
camelContext.stop();
broker.stop();
ThreadTracker.result();
}
private void createCamelContext() throws Exception {
final String fromEndpoint = "activemq:topic:" + SENDER_TOPIC;
final String toEndpoint = "activemq:topic:" + RECEIVER_TOPIC;
log.info("creating context and sending message");
camelContext = new DefaultCamelContext();
camelContext.addComponent("activemq",
ActiveMQComponent.activeMQComponent("vm://localhost?create=false&waitForStart=10000"));
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from(fromEndpoint).to(toEndpoint);
}
});
camelContext.start();
}
}

View File

@ -1,98 +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.camel;
import javax.jms.Connection;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.util.Wait;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class DlqTest extends CamelSpringTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(DlqTest.class);
BrokerService broker = null;
int messageCount;
@Test
public void testSendToDlq() throws Exception {
sendJMSMessageToKickOffRoute();
LOG.info("Wait for dlq message...");
assertTrue(Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return broker.getAdminView().getTotalEnqueueCount() == 2;
}
}));
}
private void sendJMSMessageToKickOffRoute() throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://testDlq");
factory.setWatchTopicAdvisories(false);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(new ActiveMQQueue("fidEtpOrders"));
TextMessage message = session.createTextMessage("Some Text, messageCount:" + messageCount++);
message.setJMSCorrelationID("pleaseCorrelate");
producer.send(message);
connection.close();
}
private BrokerService createBroker(boolean deleteAllMessages) throws Exception {
BrokerService brokerService = new BrokerService();
brokerService.setDeleteAllMessagesOnStartup(deleteAllMessages);
brokerService.setBrokerName("testDlq");
brokerService.setAdvisorySupport(false);
brokerService.setDataDirectory("target/data");
return brokerService;
}
@Override
protected AbstractXmlApplicationContext createApplicationContext() {
deleteDirectory("target/data");
// make broker available to recovery processing on app context start
try {
broker = createBroker(true);
broker.start();
} catch (Exception e) {
throw new RuntimeException("Failed to start broker", e);
}
return new ClassPathXmlApplicationContext("org/apache/activemq/camel/dlq.xml");
}
public static class CanError {
public String enrich(String body) throws Exception {
LOG.info("Got body: " + body);
throw new RuntimeException("won't enrich today!");
}
}
}

View File

@ -1,140 +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
* <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.apache.activemq.camel;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.*;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ConnectionInfo;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import javax.jms.*;
import javax.jms.Connection;
import java.util.concurrent.atomic.AtomicInteger;
public class JmsBridge extends CamelSpringTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(JmsBridge.class);
BrokerService brokerSub = null;
BrokerService brokerPub = null;
int messageCount;
final int backLog = 50;
final int errorLimit = 10;
AtomicInteger sendCount = new AtomicInteger();
AtomicInteger connectionCount = new AtomicInteger();
@Test
public void testBridgeWorks() throws Exception {
sendJMSMessageToKickOffRoute();
consumeMessages();
LOG.info("ConnectionCount: " + connectionCount.get());
assertEquals("x connections", 5 + errorLimit, connectionCount.get());
}
private void consumeMessages() throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://sub");
factory.setWatchTopicAdvisories(false);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(new ActiveMQQueue("to"));
int messagesToConsume = messageCount;
while (messagesToConsume > 0) {
Message message = consumer.receive(5000);
if (message != null) {
messagesToConsume--;
}
}
}
private void sendJMSMessageToKickOffRoute() throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://pub");
factory.setWatchTopicAdvisories(false);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(new ActiveMQQueue("from"));
for (int i = 0; i < backLog; i++) {
TextMessage message = session.createTextMessage("Some Text, messageCount:" + messageCount++);
message.setIntProperty("seq", messageCount);
producer.send(message);
}
connection.close();
}
private BrokerService createBroker(String name, int port, boolean deleteAllMessages) throws Exception {
BrokerService brokerService = new BrokerService();
brokerService.setDeleteAllMessagesOnStartup(deleteAllMessages);
brokerService.setBrokerName(name);
brokerService.setAdvisorySupport(false);
brokerService.setUseJmx(false);
brokerService.setDataDirectory("target/data");
if (port > 0) {
brokerService.addConnector("tcp://0.0.0.0:" + port);
}
return brokerService;
}
@SuppressWarnings("unchecked")
@Override
protected AbstractXmlApplicationContext createApplicationContext() {
try {
brokerSub = createBroker("sub", 61617, true);
brokerSub.setPlugins(new BrokerPlugin[]{new BrokerPluginSupport() {
@Override
public void send(ProducerBrokerExchange producerExchange, org.apache.activemq.command.Message messageSend) throws Exception {
if (sendCount.incrementAndGet() <= errorLimit) {
throw new RuntimeException("You need to try send " + errorLimit + " times!");
}
super.send(producerExchange, messageSend);
}
@Override
public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception {
if (((TransportConnector) context.getConnector()).getConnectUri().getScheme().equals("tcp") && connectionCount.incrementAndGet() <= errorLimit) {
throw new SecurityException("You need to try connect " + errorLimit + " times!");
}
super.addConnection(context, info);
}
}});
brokerSub.start();
brokerPub = createBroker("pub", 61616, true);
brokerPub.start();
} catch (Exception e) {
throw new RuntimeException("Failed to start broker", e);
}
return new ClassPathXmlApplicationContext("org/apache/activemq/camel/jmsBridge.xml");
}
}

View File

@ -1,100 +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.camel;
import javax.jms.Connection;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class JmsConsumeSendTransacted extends CamelSpringTestSupport {
BrokerService broker = null;
int messageCount;
@Test
public void testTransactedRoute() throws Exception {
sendJMSMessageToKickOffRoute();
// camel route will use a single transaction for send and and ack
consumeMessages();
}
private void consumeMessages() throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://testTran");
factory.setWatchTopicAdvisories(false);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(new ActiveMQQueue("to"));
int messagesToConsume = messageCount;
while (messagesToConsume > 0) {
Message message = consumer.receive(5000);
if (message != null) {
messagesToConsume--;
}
}
}
private void sendJMSMessageToKickOffRoute() throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://testTran");
factory.setWatchTopicAdvisories(false);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(new ActiveMQQueue("from"));
TextMessage message = session.createTextMessage("Some Text, messageCount:" + messageCount++);
message.setIntProperty("seq", messageCount);
producer.send(message);
connection.close();
}
private BrokerService createBroker(boolean deleteAllMessages) throws Exception {
BrokerService brokerService = new BrokerService();
brokerService.setDeleteAllMessagesOnStartup(deleteAllMessages);
brokerService.setBrokerName("testTran");
brokerService.setAdvisorySupport(false);
brokerService.setUseJmx(false);
brokerService.setDataDirectory("target/data");
brokerService.addConnector("tcp://0.0.0.0:61616");
return brokerService;
}
@SuppressWarnings("unchecked")
@Override
protected AbstractXmlApplicationContext createApplicationContext() {
try {
broker = createBroker(true);
broker.start();
} catch (Exception e) {
throw new RuntimeException("Failed to start broker", e);
}
return new ClassPathXmlApplicationContext("org/apache/activemq/camel/jmsConsumeSendTransacted.xml");
}
}

View File

@ -1,185 +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.camel;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.jms.Connection;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.sql.DataSource;
import javax.transaction.TransactionManager;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.policy.SharedDeadLetterStrategy;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.util.Wait;
import org.apache.camel.Exchange;
import org.apache.camel.component.jms.JmsMessage;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.transaction.jta.JtaTransactionManager;
/**
* shows rollback and redelivery dlq respected with external tm
*/
public class JmsJdbcXARollbackTest extends CamelSpringTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(JmsJdbcXARollbackTest.class);
BrokerService broker = null;
int messageCount;
public java.sql.Connection initDb() throws Exception {
String createStatement =
"CREATE TABLE SCP_INPUT_MESSAGES (" +
"id int NOT NULL GENERATED ALWAYS AS IDENTITY, " +
"messageId varchar(96) NOT NULL, " +
"messageCorrelationId varchar(96) NOT NULL, " +
"messageContent varchar(2048) NOT NULL, " +
"PRIMARY KEY (id) )";
java.sql.Connection conn = getJDBCConnection();
try {
conn.createStatement().execute(createStatement);
} catch (SQLException alreadyExists) {
log.info("ex on create tables", alreadyExists);
}
try {
conn.createStatement().execute("DELETE FROM SCP_INPUT_MESSAGES");
} catch (SQLException ex) {
log.info("ex on create delete all", ex);
}
return conn;
}
private java.sql.Connection getJDBCConnection() throws Exception {
DataSource dataSource = getMandatoryBean(DataSource.class, "managedDataSourceWithRecovery");
return dataSource.getConnection();
}
private int dumpDb(java.sql.Connection jdbcConn) throws Exception {
int count = 0;
ResultSet resultSet = jdbcConn.createStatement().executeQuery("SELECT * FROM SCP_INPUT_MESSAGES");
while (resultSet.next()) {
count++;
log.info("message - seq:" + resultSet.getInt(1)
+ ", id: " + resultSet.getString(2)
+ ", corr: " + resultSet.getString(3)
+ ", content: " + resultSet.getString(4));
}
return count;
}
@Test
public void testConsumeRollback() throws Exception {
java.sql.Connection jdbcConn = initDb();
initTMRef();
sendJMSMessageToKickOffRoute();
// should go to dlq eventually
Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return consumedFrom(SharedDeadLetterStrategy.DEFAULT_DEAD_LETTER_QUEUE_NAME);
}
});
assertEquals("message in db, commit to db worked", 0, dumpDb(jdbcConn));
assertFalse("Nothing to to out q", consumedFrom("scp_transacted_out"));
}
private boolean consumedFrom(String qName) throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://testXA");
factory.setWatchTopicAdvisories(false);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(new ActiveMQQueue(qName));
Message message = consumer.receive(500);
LOG.info("Got from queue:{} {}", qName, message);
connection.close();
return message != null;
}
static TransactionManager[] transactionManager = new TransactionManager[1];
private void initTMRef() {
transactionManager[0] = getMandatoryBean(JtaTransactionManager.class, "jtaTransactionManager").getTransactionManager();
}
private void sendJMSMessageToKickOffRoute() throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://testXA");
factory.setWatchTopicAdvisories(false);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(new ActiveMQQueue("scp_transacted"));
TextMessage message = session.createTextMessage("Some Text, messageCount:" + messageCount++);
message.setJMSCorrelationID("pleaseCorrelate");
producer.send(message);
connection.close();
}
private BrokerService createBroker(boolean deleteAllMessages) throws Exception {
BrokerService brokerService = new BrokerService();
brokerService.setDeleteAllMessagesOnStartup(deleteAllMessages);
brokerService.setBrokerName("testXA");
brokerService.setAdvisorySupport(false);
brokerService.setUseJmx(false);
brokerService.setDataDirectory("target/data");
brokerService.addConnector("tcp://0.0.0.0:61616");
return brokerService;
}
@SuppressWarnings("unchecked")
@Override
protected AbstractXmlApplicationContext createApplicationContext() {
deleteDirectory("target/data/howl");
// make broker available to recovery processing on app context start
try {
broker = createBroker(true);
broker.start();
} catch (Exception e) {
throw new RuntimeException("Failed to start broker", e);
}
return new ClassPathXmlApplicationContext("org/apache/activemq/camel/jmsXajdbcRollback.xml");
}
public static class MarkRollbackOnly {
public String enrich(Exchange exchange) throws Exception {
LOG.info("Got exchange: " + exchange);
LOG.info("Got message: " + ((JmsMessage)exchange.getIn()).getJmsMessage());
LOG.info("Current tx: " + transactionManager[0].getTransaction());
LOG.info("Marking rollback only...");
transactionManager[0].getTransaction().setRollbackOnly();
return "Some Text";
}
}
}

View File

@ -1,209 +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.camel;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.concurrent.Executors;
import javax.jms.Connection;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.sql.DataSource;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerPlugin;
import org.apache.activemq.broker.BrokerPluginSupport;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.ConnectionContext;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.TransactionId;
import org.apache.activemq.util.Wait;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* shows broker 'once only delivery' and recovery with XA
*/
public class JmsJdbcXATest extends CamelSpringTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(JmsJdbcXATest.class);
BrokerService broker = null;
int messageCount;
public java.sql.Connection initDb() throws Exception {
String createStatement =
"CREATE TABLE SCP_INPUT_MESSAGES (" +
"id int NOT NULL GENERATED ALWAYS AS IDENTITY, " +
"messageId varchar(96) NOT NULL, " +
"messageCorrelationId varchar(96) NOT NULL, " +
"messageContent varchar(2048) NOT NULL, " +
"PRIMARY KEY (id) )";
java.sql.Connection conn = getJDBCConnection();
try {
conn.createStatement().execute(createStatement);
} catch (SQLException alreadyExists) {
log.info("ex on create tables", alreadyExists);
}
try {
conn.createStatement().execute("DELETE FROM SCP_INPUT_MESSAGES");
} catch (SQLException ex) {
log.info("ex on create delete all", ex);
}
return conn;
}
private java.sql.Connection getJDBCConnection() throws Exception {
DataSource dataSource = getMandatoryBean(DataSource.class, "managedDataSourceWithRecovery");
return dataSource.getConnection();
}
private int dumpDb(java.sql.Connection jdbcConn) throws Exception {
int count = 0;
ResultSet resultSet = jdbcConn.createStatement().executeQuery("SELECT * FROM SCP_INPUT_MESSAGES");
while (resultSet.next()) {
count++;
log.info("message - seq:" + resultSet.getInt(1)
+ ", id: " + resultSet.getString(2)
+ ", corr: " + resultSet.getString(3)
+ ", content: " + resultSet.getString(4));
}
return count;
}
@Test
public void testRecoveryCommit() throws Exception {
java.sql.Connection jdbcConn = initDb();
sendJMSMessageToKickOffRoute();
LOG.info("waiting for route to kick in, it will kill the broker on first 2pc commit");
// will be stopped by the plugin on first 2pc commit
broker.waitUntilStopped();
assertEquals("message in db, commit to db worked", 1, dumpDb(jdbcConn));
LOG.info("Broker stopped, restarting...");
broker = createBroker(false);
broker.start();
broker.waitUntilStarted();
assertEquals("pending transactions", 1, broker.getBroker().getPreparedTransactions(null).length);
// TM stays actively committing first message ack which won't get redelivered - xa once only delivery
LOG.info("waiting for recovery to complete");
assertTrue("recovery complete in time", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return broker.getBroker().getPreparedTransactions(null).length == 0;
}
}));
// verify recovery complete
assertEquals("recovery complete", 0, broker.getBroker().getPreparedTransactions(null).length);
final java.sql.Connection freshConnection = getJDBCConnection();
assertTrue("did not get replay", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 1 == dumpDb(freshConnection);
}
}));
assertEquals("still one message in db", 1, dumpDb(freshConnection));
// let once complete ok
sendJMSMessageToKickOffRoute();
assertTrue("got second message", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 2 == dumpDb(freshConnection);
}
}));
assertEquals("two messages in db", 2, dumpDb(freshConnection));
}
private void sendJMSMessageToKickOffRoute() throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://testXA");
factory.setWatchTopicAdvisories(false);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(new ActiveMQQueue("scp_transacted"));
TextMessage message = session.createTextMessage("Some Text, messageCount:" + messageCount++);
message.setJMSCorrelationID("pleaseCorrelate");
producer.send(message);
connection.close();
}
private BrokerService createBroker(boolean deleteAllMessages) throws Exception {
BrokerService brokerService = new BrokerService();
brokerService.setDeleteAllMessagesOnStartup(deleteAllMessages);
brokerService.setBrokerName("testXA");
brokerService.setAdvisorySupport(false);
brokerService.setUseJmx(false);
brokerService.setDataDirectory("target/data");
brokerService.addConnector("tcp://0.0.0.0:61616");
return brokerService;
}
@SuppressWarnings("unchecked")
@Override
protected AbstractXmlApplicationContext createApplicationContext() {
deleteDirectory("target/data/howl");
// make broker available to recovery processing on app context start
try {
broker = createBroker(true);
broker.setPlugins(new BrokerPlugin[]{
new BrokerPluginSupport() {
@Override
public void commitTransaction(ConnectionContext context,
TransactionId xid, boolean onePhase) throws Exception {
if (onePhase) {
super.commitTransaction(context, xid, onePhase);
} else {
// die before doing the commit
// so commit will hang as if reply is lost
context.setDontSendReponse(true);
Executors.newSingleThreadExecutor().execute(new Runnable() {
@Override
public void run() {
LOG.info("Stopping broker post commit...");
try {
broker.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
}
});
broker.start();
} catch (Exception e) {
throw new RuntimeException("Failed to start broker", e);
}
return new ClassPathXmlApplicationContext("org/apache/activemq/camel/jmsXajdbc.xml");
}
}

View File

@ -1,87 +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.camel;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.Exchange;
import org.apache.camel.component.jms.JmsBinding;
import org.apache.camel.component.jms.JmsMessage;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.apache.camel.util.ExchangeHelper;
import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import javax.jms.*;
import java.util.concurrent.TimeUnit;
public class ObjectMessageTest extends CamelSpringTestSupport {
@Test
public void testUntrusted() throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost");
Connection conn = factory.createConnection();
conn.start();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = sess.createProducer(sess.createTopic("foo"));
ObjectMessage msg = sess.createObjectMessage();
ObjectPayload payload = new ObjectPayload();
payload.payload = "test";
msg.setObject(payload);
producer.send(msg);
Thread.sleep(1000);
MockEndpoint resultActiveMQ = resolveMandatoryEndpoint("mock:result-activemq", MockEndpoint.class);
resultActiveMQ.expectedMessageCount(1);
resultActiveMQ.assertIsSatisfied();
assertCorrectObjectReceived(resultActiveMQ);
MockEndpoint resultTrusted = resolveMandatoryEndpoint("mock:result-trusted", MockEndpoint.class);
resultTrusted.expectedMessageCount(1);
resultTrusted.assertIsSatisfied();
assertCorrectObjectReceived(resultTrusted);
MockEndpoint resultCamel = resolveMandatoryEndpoint("mock:result-camel", MockEndpoint.class);
resultCamel.expectedMessageCount(1);
resultCamel.assertIsNotSatisfied();
MockEndpoint resultEmpty = resolveMandatoryEndpoint("mock:result-empty", MockEndpoint.class);
resultEmpty.expectedMessageCount(1);
resultEmpty.assertIsNotSatisfied();
}
protected void assertCorrectObjectReceived(MockEndpoint result) {
Exchange exchange = result.getReceivedExchanges().get(0);
// This should be a JMS Exchange
assertNotNull(ExchangeHelper.getBinding(exchange, JmsBinding.class));
JmsMessage in = (JmsMessage) exchange.getIn();
assertNotNull(in);
assertIsInstanceOf(ObjectMessage.class, in.getJmsMessage());
ObjectPayload received = exchange.getIn().getBody(ObjectPayload.class);
assertEquals("test", received.payload);
}
@Override
protected AbstractApplicationContext createApplicationContext() {
AbstractApplicationContext context = new ClassPathXmlApplicationContext("org/apache/activemq/camel/jms-object-message.xml");
return context;
}
}

View File

@ -1,25 +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.camel;
import java.io.Serializable;
public class ObjectPayload implements Serializable {
private static final long serialVersionUID = 121277L;
public String payload;
}

View File

@ -1,36 +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.camel;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.Message;
/**
*
*/
public class SetGroupIdProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
// lets copy the IN to the OUT message
Message out = exchange.getOut();
out.copyFrom(exchange.getIn());
// now lets set a header
out.setHeader("JMSXGroupID", "ABC");
}
}

View File

@ -1,65 +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.camel;
import java.util.List;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.EndpointInject;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.util.ObjectHelper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class SetHeaderTest {
private static final transient Logger LOG = LoggerFactory.getLogger(SetHeaderTest.class);
@Autowired
protected CamelContext camelContext;
@EndpointInject(uri = "mock:results")
protected MockEndpoint expectedEndpoint;
@Test
public void testMocksAreValid() throws Exception {
// lets add more expectations
expectedEndpoint.expectedMessageCount(1);
expectedEndpoint.message(0).header("JMSXGroupID").isEqualTo("ABC");
MockEndpoint.assertIsSatisfied(camelContext);
// lets dump the received messages
List<Exchange> list = expectedEndpoint.getReceivedExchanges();
for (Exchange exchange : list) {
Object body = exchange.getIn().getBody();
LOG.debug("Received: body: " + body + " of type: " + ObjectHelper.className(body) + " on: " + exchange);
}
}
}

View File

@ -1,140 +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.camel;
import java.util.concurrent.atomic.AtomicLong;
import javax.jms.Connection;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
import org.apache.activemq.util.Wait;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.component.jms.JmsMessage;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TransactedConsumeTest extends CamelSpringTestSupport {
private static final Logger LOG = LoggerFactory.getLogger(TransactedConsumeTest.class);
BrokerService broker = null;
int messageCount = 100000;
@Test
public void testConsume() throws Exception {
LOG.info("Wait for dequeue message...");
assertTrue(Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return broker.getAdminView().getTotalDequeueCount() >= messageCount;
}
}, 20 * 60 * 1000));
long duration = System.currentTimeMillis() - firstConsumed.get();
LOG.info("Done message consumption in " + duration + "millis");
}
private void sendJMSMessageToKickOffRoute() throws Exception {
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://test");
factory.setWatchTopicAdvisories(false);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(new ActiveMQQueue("scp_transacted"));
for (int i=0; i<messageCount;i++) {
TextMessage message = session.createTextMessage("Some Text, messageCount:" + i);
message.setJMSCorrelationID("pleaseCorrelate");
producer.send(message);
}
LOG.info("Sent: " + messageCount);
connection.close();
}
private BrokerService createBroker(boolean deleteAllMessages) throws Exception {
BrokerService brokerService = new BrokerService();
brokerService.setDeleteAllMessagesOnStartup(deleteAllMessages);
brokerService.setBrokerName("test");
PolicyMap policyMap = new PolicyMap();
PolicyEntry defaultPolicy = new PolicyEntry();
policyMap.setDefaultEntry(defaultPolicy);
brokerService.setDestinationPolicy(policyMap);
brokerService.setAdvisorySupport(false);
brokerService.setDataDirectory("target/data");
//AMQPersistenceAdapter amq = new AMQPersistenceAdapter();
//amq.setDirectory(new File("target/data"));
//brokerService.setPersistenceAdapter(amq);
KahaDBPersistenceAdapter kahaDBPersistenceAdapter = (KahaDBPersistenceAdapter)
brokerService.getPersistenceAdapter();
kahaDBPersistenceAdapter.setEnableJournalDiskSyncs(false);
brokerService.addConnector("tcp://localhost:61616");
return brokerService;
}
@Override
protected AbstractXmlApplicationContext createApplicationContext() {
deleteDirectory("target/data");
// make broker available to recovery processing on app context start
try {
broker = createBroker(true);
broker.start();
} catch (Exception e) {
throw new RuntimeException("Failed to start broker", e);
}
try {
sendJMSMessageToKickOffRoute();
} catch (Exception e) {
throw new RuntimeException("Failed to fill q", e);
}
return new ClassPathXmlApplicationContext("org/apache/activemq/camel/transactedconsume.xml");
}
static AtomicLong firstConsumed = new AtomicLong();
static AtomicLong consumed = new AtomicLong();
static class ConnectionLog implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
if (consumed.getAndIncrement() == 0) {
firstConsumed.set(System.currentTimeMillis());
}
ActiveMQTextMessage m = (ActiveMQTextMessage) ((JmsMessage)exchange.getIn()).getJmsMessage();
//Thread.currentThread().sleep(500);
if (consumed.get() %500 == 0) {
LOG.info("received on " + m.getConnection().toString());
}
}
}
}

View File

@ -1,127 +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.camel.camelplugin;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerRegistry;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.xbean.XBeanBrokerFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import javax.jms.Connection;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.Topic;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
public class CamelPluginConfigTest {
protected static final String CONF_ROOT = "src/test/resources/org/apache/activemq/camel/camelplugin/";
protected static final String TOPIC_NAME = "test.topic";
protected static final String QUEUE_NAME = "test.queue";
protected BrokerService brokerService;
protected ActiveMQConnectionFactory factory;
protected Connection producerConnection;
protected Connection consumerConnection;
protected Session consumerSession;
protected Session producerSession;
protected int messageCount = 1000;
protected int timeOutInSeconds = 10;
@Before
public void setUp() throws Exception {
brokerService = createBroker(new FileSystemResource(CONF_ROOT + "camel-routes-activemq.xml"));
factory = new ActiveMQConnectionFactory(BrokerRegistry.getInstance().findFirst().getVmConnectorURI());
consumerConnection = factory.createConnection();
consumerConnection.start();
producerConnection = factory.createConnection();
producerConnection.start();
consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
}
protected BrokerService createBroker(String resource) throws Exception {
return createBroker(new ClassPathResource(resource));
}
protected BrokerService createBroker(Resource resource) throws Exception {
XBeanBrokerFactory factory = new XBeanBrokerFactory();
BrokerService broker = factory.createBroker(resource.getURI());
return broker;
}
@After
public void tearDown() throws Exception {
if (producerConnection != null) {
producerConnection.close();
}
if (consumerConnection != null) {
consumerConnection.close();
}
if (brokerService != null) {
brokerService.stop();
}
}
@Test
public void testReRouteAll() throws Exception {
Thread.sleep(2000);
final ActiveMQQueue queue = new ActiveMQQueue(QUEUE_NAME);
Topic topic = consumerSession.createTopic(TOPIC_NAME);
final CountDownLatch latch = new CountDownLatch(messageCount);
MessageConsumer consumer = consumerSession.createConsumer(queue);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(javax.jms.Message message) {
try {
latch.countDown();
} catch (Throwable e) {
e.printStackTrace();
}
}
});
MessageProducer producer = producerSession.createProducer(topic);
for (int i = 0; i < messageCount; i++) {
javax.jms.Message message = producerSession.createTextMessage("test: " + i);
producer.send(message);
}
latch.await(timeOutInSeconds, TimeUnit.SECONDS);
assertEquals(0, latch.getCount());
}
}

View File

@ -1,98 +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.camel.component;
import org.apache.activemq.spring.ActiveMQConnectionFactory;
import org.apache.activemq.pool.PooledConnectionFactory;
import org.apache.camel.Endpoint;
import org.apache.camel.component.jms.JmsConfiguration;
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.CamelLogProcessor;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.listener.AbstractMessageListenerContainer;
import org.springframework.jms.connection.SingleConnectionFactory;
/**
*
*/
public class ActiveMQConfigureTest extends CamelTestSupport {
@Test
public void testJmsTemplateUsesPoolingConnectionFactory() throws Exception {
JmsEndpoint endpoint = resolveMandatoryEndpoint("activemq:test.foo");
JmsProducer producer = (JmsProducer) endpoint.createProducer();
JmsTemplate template = assertIsInstanceOf(JmsTemplate.class, producer.getInOutTemplate());
assertEquals("pubSubDomain", false, template.isPubSubDomain());
assertIsInstanceOf(PooledConnectionFactory.class, template.getConnectionFactory());
}
@Test
public void testJmsTemplateUsesSingleConnectionFactory() throws Exception {
JmsEndpoint endpoint = resolveMandatoryEndpoint("activemq:test.foo?useSingleConnection=true");
JmsProducer producer = (JmsProducer) endpoint.createProducer();
JmsTemplate template = assertIsInstanceOf(JmsTemplate.class, producer.getInOutTemplate());
assertEquals("pubSubDomain", false, template.isPubSubDomain());
SingleConnectionFactory connectionFactory = assertIsInstanceOf(SingleConnectionFactory.class, template.getConnectionFactory());
assertIsInstanceOf(ActiveMQConnectionFactory.class, connectionFactory.getTargetConnectionFactory());
}
@Test
public void testSessionTransactedWithoutTransactionManager() throws Exception {
JmsEndpoint endpoint = resolveMandatoryEndpoint("activemq:test.foo?transacted=true&lazyCreateTransactionManager=false");
JmsConfiguration configuration = endpoint.getConfiguration();
assertIsInstanceOf(ActiveMQConfiguration.class, configuration);
assertTrue("The JMS sessions are not transacted!", endpoint.isTransacted());
assertTrue("The JMS sessions are not transacted!", configuration.isTransacted());
assertNull("A transaction manager has been lazy-created!", endpoint.getTransactionManager());
assertNull("A transaction manager has been lazy-created!", configuration.getTransactionManager());
}
@Test
public void testJmsTemplateDoesNotUsePoolingConnectionFactory() throws Exception {
JmsEndpoint endpoint = resolveMandatoryEndpoint("activemq:test.foo?usePooledConnection=false");
JmsProducer producer = (JmsProducer) endpoint.createProducer();
JmsTemplate template = assertIsInstanceOf(JmsTemplate.class, producer.getInOutTemplate());
assertEquals("pubSubDomain", false, template.isPubSubDomain());
assertIsInstanceOf(ActiveMQConnectionFactory.class, template.getConnectionFactory());
}
@Test
public void testListenerContainerUsesSpringConnectionFactory() throws Exception {
JmsEndpoint endpoint = resolveMandatoryEndpoint("activemq:topic:test.foo");
JmsConsumer consumer = endpoint.createConsumer(new CamelLogProcessor());
AbstractMessageListenerContainer listenerContainer = consumer.getListenerContainer();
assertEquals("pubSubDomain", true, listenerContainer.isPubSubDomain());
assertIsInstanceOf(PooledConnectionFactory.class, listenerContainer.getConnectionFactory());
}
@Override
protected JmsEndpoint resolveMandatoryEndpoint(String uri) {
Endpoint endpoint = super.resolveMandatoryEndpoint(uri);
return assertIsInstanceOf(JmsEndpoint.class, endpoint);
}
}

View File

@ -1,49 +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.camel.component;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsMessage;
/**
*
*/
public class ActiveMQJmsHeaderRouteForceTest extends ActiveMQJmsHeaderRouteTest {
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
// do not map jms message as we want to tamper with the JMS message directly, and not use the Camel API for that
from("activemq:test.a?mapJmsMessage=false").process(new Processor() {
public void process(Exchange exchange) throws Exception {
// lets set the custom JMS headers using the JMS API
JmsMessage jmsMessage = assertIsInstanceOf(JmsMessage.class, exchange.getIn());
jmsMessage.getJmsMessage().setJMSReplyTo(replyQueue);
jmsMessage.getJmsMessage().setJMSCorrelationID(correlationID);
jmsMessage.getJmsMessage().setJMSType(messageType); }
// force sending the incoming JMS Message, as we want to tamper with the JMS API directly
// instead of using the Camel API for setting JMS headers.
}).to("activemq:test.b?preserveMessageQos=true&forceSendOriginalMessage=true");
from("activemq:test.b").to("mock:result");
}
};
}
}

View File

@ -1,99 +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.camel.component;
import java.util.Date;
import java.util.List;
import javax.jms.Destination;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.AssertionClause;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
/**
*
*/
public class ActiveMQJmsHeaderRouteTest extends CamelTestSupport {
private static final transient Logger LOG = LoggerFactory.getLogger(ActiveMQJmsHeaderRouteTest.class);
protected Object expectedBody = "<time>" + new Date() + "</time>";
protected ActiveMQQueue replyQueue = new ActiveMQQueue("test.reply.queue");
protected String correlationID = "ABC-123";
protected String messageType = getClass().getName();
@Test
public void testForwardingAMessageAcrossJMSKeepingCustomJMSHeaders() throws Exception {
MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
resultEndpoint.expectedBodiesReceived(expectedBody);
AssertionClause firstMessageExpectations = resultEndpoint.message(0);
firstMessageExpectations.header("cheese").isEqualTo(123);
firstMessageExpectations.header("JMSReplyTo").isEqualTo(replyQueue);
firstMessageExpectations.header("JMSCorrelationID").isEqualTo(correlationID);
firstMessageExpectations.header("JMSType").isEqualTo(messageType);
template.sendBodyAndHeader("activemq:test.a", expectedBody, "cheese", 123);
resultEndpoint.assertIsSatisfied();
List<Exchange> list = resultEndpoint.getReceivedExchanges();
Exchange exchange = list.get(0);
Object replyTo = exchange.getIn().getHeader("JMSReplyTo");
LOG.info("Reply to is: " + replyTo);
Destination destination = assertIsInstanceOf(Destination.class, replyTo);
assertEquals("ReplyTo", replyQueue.toString(), destination.toString());
}
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
camelContext.setTracing(true);
// START SNIPPET: example
camelContext.addComponent("activemq", activeMQComponent("vm://localhost?broker.persistent=false"));
// END SNIPPET: example
return camelContext;
}
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from("activemq:test.a").process(new Processor() {
public void process(Exchange exchange) throws Exception {
// lets set the custom JMS headers using the Camel API
exchange.getIn().setHeader("JMSReplyTo", replyQueue);
exchange.getIn().setHeader("JMSCorrelationID", correlationID);
exchange.getIn().setHeader("JMSType", messageType);
}
}).to("activemq:test.b?preserveMessageQos=true");
from("activemq:test.b").to("mock:result");
}
};
}
}

View File

@ -1,76 +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
* <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.apache.activemq.camel.component;
import javax.jms.Message;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQMessage;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsMessage;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
import static org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
public class ActiveMQOriginalDestinationTest extends CamelTestSupport {
@Test
public void testActiveMQOriginalDestination() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
template.sendBody("activemq:queue:foo", "Hello World");
assertMockEndpointsSatisfied();
// consume from bar
Exchange out = consumer.receive("activemq:queue:bar", 5000);
assertNotNull(out);
// and we should have foo as the original destination
JmsMessage msg = out.getIn(JmsMessage.class);
Message jms = msg.getJmsMessage();
ActiveMQMessage amq = assertIsInstanceOf(ActiveMQMessage.class, jms);
ActiveMQDestination original = amq.getOriginalDestination();
assertNotNull(original);
assertEquals("foo", original.getPhysicalName());
assertEquals("Queue", original.getDestinationTypeAsString());
}
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
camelContext.addComponent("activemq", activeMQComponent("vm://localhost?broker.persistent=false"));
return camelContext;
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("activemq:queue:foo")
.to("activemq:queue:bar")
.to("mock:result");
}
};
}
}

View File

@ -1,112 +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.camel.component;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.jms.Destination;
import static org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
import org.apache.activemq.camel.converter.ActiveMQConverter;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.AssertionClause;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
*/
public class ActiveMQReplyToHeaderUsingConverterTest extends CamelTestSupport {
private static final transient Logger LOG = LoggerFactory.getLogger(ActiveMQReplyToHeaderUsingConverterTest.class);
protected Object expectedBody = "<time>" + new Date() + "</time>";
protected String replyQueueName = "queue://test.my.reply.queue";
protected String correlationID = "ABC-123";
protected String groupID = "GROUP-XYZ";
protected String messageType = getClass().getName();
protected boolean useReplyToHeader = false;
@Test
public void testSendingAMessageFromCamelSetsCustomJmsHeaders() throws Exception {
MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
resultEndpoint.expectedBodiesReceived(expectedBody);
AssertionClause firstMessage = resultEndpoint.message(0);
firstMessage.header("cheese").isEqualTo(123);
firstMessage.header("JMSCorrelationID").isEqualTo(correlationID);
if (useReplyToHeader) {
firstMessage.header("JMSReplyTo").isEqualTo(ActiveMQConverter.toDestination(replyQueueName));
}
firstMessage.header("JMSType").isEqualTo(messageType);
firstMessage.header("JMSXGroupID").isEqualTo(groupID);
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("cheese", 123);
if (useReplyToHeader) {
headers.put("JMSReplyTo", replyQueueName);
}
headers.put("JMSCorrelationID", correlationID);
headers.put("JMSType", messageType);
headers.put("JMSXGroupID", groupID);
template.sendBodyAndHeaders("activemq:test.a", expectedBody, headers);
resultEndpoint.assertIsSatisfied();
List<Exchange> list = resultEndpoint.getReceivedExchanges();
Exchange exchange = list.get(0);
Message in = exchange.getIn();
Object replyTo = in.getHeader("JMSReplyTo");
LOG.info("Reply to is: " + replyTo);
if (useReplyToHeader) {
Destination destination = assertIsInstanceOf(Destination.class, replyTo);
assertEquals("ReplyTo", replyQueueName, destination.toString());
}
assertMessageHeader(in, "cheese", 123);
assertMessageHeader(in, "JMSCorrelationID", correlationID);
assertMessageHeader(in, "JMSType", messageType);
assertMessageHeader(in, "JMSXGroupID", groupID);
}
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
// START SNIPPET: example
camelContext.addComponent("activemq", activeMQComponent("vm://localhost?broker.persistent=false"));
// END SNIPPET: example
return camelContext;
}
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from("activemq:test.a").to("activemq:test.b?preserveMessageQos=true");
from("activemq:test.b").to("mock:result");
}
};
}
}

View File

@ -1,86 +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.camel.component;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsEndpoint;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Before;
import org.junit.Test;
import org.springframework.jms.connection.JmsTransactionManager;
import static org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
/**
*
*/
public class ActiveMQRouteTest extends CamelTestSupport {
private static final String EXPECTED_BODY = "Hello there!";
protected MockEndpoint resultEndpoint;
protected String startEndpointUri = "activemq:queue:test.a";
@Test
public void testJmsRouteWithTextMessage() throws Exception {
resultEndpoint.expectedBodiesReceived(EXPECTED_BODY);
resultEndpoint.message(0).header("cheese").isEqualTo(123);
sendExchange(EXPECTED_BODY);
resultEndpoint.assertIsSatisfied();
}
protected void sendExchange(final Object expectedBody) {
template.sendBodyAndHeader(startEndpointUri, expectedBody, "cheese", 123);
}
@Before
public void setUp() throws Exception {
super.setUp();
resultEndpoint = (MockEndpoint) context.getEndpoint("mock:result");
}
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
// START SNIPPET: example
camelContext.addComponent("activemq", activeMQComponent("vm://localhost?broker.persistent=false"));
// END SNIPPET: example
return camelContext;
}
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from(startEndpointUri).to("activemq:queue:test.b");
from("activemq:queue:test.b").to("mock:result");
JmsEndpoint endpoint1 = (JmsEndpoint) endpoint("activemq:topic:quote.IONA");
endpoint1.getConfiguration().setTransactionManager(new JmsTransactionManager());
endpoint1.getConfiguration().setTransacted(true);
from(endpoint1).to("mock:transactedClient");
JmsEndpoint endpoint2 = (JmsEndpoint) endpoint("activemq:topic:quote.IONA");
endpoint2.getConfiguration().setTransacted(false);
from(endpoint2).to("mock:nonTrasnactedClient");
}
};
}
}

View File

@ -1,70 +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.camel.component;
import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.command.DataStructure;
import org.apache.activemq.command.DestinationInfo;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.Message;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsMessage;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
/**
*
*/
public class AdvisoryConsumerExample extends CamelTestSupport {
@Test
public void testWorks() throws Exception {
// lets create a new queue
template.sendBody("activemq:NewQueue." + System.currentTimeMillis(), "<hello>world!</hello>");
Thread.sleep(10000);
}
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
// lets force the creation of a queue up front
from("activemq:InitialQueue").to("log:Messages");
from("activemq:topic:ActiveMQ.Advisory.Queue?cacheLevelName=CACHE_CONSUMER").process(new Processor() {
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
if (in instanceof JmsMessage) {
JmsMessage jmsMessage = (JmsMessage) in;
javax.jms.Message value = jmsMessage.getJmsMessage();
if (value instanceof ActiveMQMessage) {
ActiveMQMessage activeMQMessage = (ActiveMQMessage) value;
DataStructure structure = activeMQMessage.getDataStructure();
if (structure instanceof DestinationInfo) {
DestinationInfo destinationInfo = (DestinationInfo) structure;
System.out.println("Received: " + destinationInfo);
}
}
}
}
});
}
};
}
}

View File

@ -1,111 +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.camel.component;
import org.apache.activemq.EmbeddedBrokerTestSupport;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.BrowsableEndpoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
/**
* Shows that we can see the queues inside ActiveMQ via Camel
* by enabling the {@link ActiveMQComponent#setExposeAllQueues(boolean)} flag
*
*
*/
public class AutoExposeQueuesInCamelTest extends EmbeddedBrokerTestSupport {
private static final transient Logger LOG = LoggerFactory.getLogger(AutoExposeQueuesInCamelTest.class);
protected ActiveMQQueue sampleQueue = new ActiveMQQueue("foo.bar");
protected ActiveMQTopic sampleTopic = new ActiveMQTopic("cheese");
protected CamelContext camelContext = new DefaultCamelContext();
ActiveMQComponent component;
public void testWorks() throws Exception {
Thread.sleep(2000);
LOG.debug("Looking for endpoints...");
broker.getAdminView().addQueue("runtime");
Thread.sleep(1000);
// Changed from using CamelContextHelper.getSingletonEndpoints here because JMS Endpoints in Camel
// are always non-singleton
List<BrowsableEndpoint> endpoints = getEndpoints(camelContext, BrowsableEndpoint.class);
for (BrowsableEndpoint endpoint : endpoints) {
LOG.debug("Endpoint: " + endpoint);
}
assertEquals("Should have found an endpoint: "+ endpoints, 2, endpoints.size());
}
public <T> List<T> getEndpoints(CamelContext camelContext, Class<T> type) {
List<T> answer = new ArrayList<T>();
Collection<Endpoint> endpoints = camelContext.getEndpoints();
for (Endpoint endpoint : endpoints) {
if (type.isInstance(endpoint)) {
T value = type.cast(endpoint);
answer.add(value);
}
}
return answer;
}
@Override
protected void setUp() throws Exception {
super.setUp();
// lets configure the ActiveMQ component for Camel
component = new ActiveMQComponent();
component.setBrokerURL(bindAddress);
component.setExposeAllQueues(true);
camelContext.addComponent("activemq", component);
camelContext.start();
}
@Override
protected void tearDown() throws Exception {
camelContext.stop();
super.tearDown();
}
@Override
protected BrokerService createBroker() throws Exception {
BrokerService broker = super.createBroker();
broker.setDestinations(new ActiveMQDestination[]{
sampleQueue,
sampleTopic
});
return broker;
}
}

View File

@ -1,195 +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.camel.component;
import static org.junit.Assert.assertNotNull;
import java.util.concurrent.TimeUnit;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.pool.PooledConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ComplexRequestReplyTest {
private static final Logger LOG = LoggerFactory.getLogger(ComplexRequestReplyTest.class);
private BrokerService brokerA = null;
private BrokerService brokerB = null;
private CamelContext senderContext = null;
private CamelContext brokerAContext = null;
private CamelContext brokerBContext = null;
private final String fromEndpoint = "direct:test";
private final String toEndpoint = "activemq:queue:send";
private final String brokerEndpoint = "activemq:send";
private String brokerAUri;
private String brokerBUri;
private String connectionUri;
@Before
public void setUp() throws Exception {
createBrokerA();
brokerAUri = brokerA.getTransportConnectors().get(0).getPublishableConnectString();
createBrokerB();
brokerBUri = brokerB.getTransportConnectors().get(0).getPublishableConnectString();
connectionUri = "failover:(" + brokerAUri + "," + brokerBUri + ")?randomize=false";
senderContext = createSenderContext();
}
@After
public void tearDown() throws Exception {
try {
shutdownBrokerA();
} catch (Exception ex) {}
try {
shutdownBrokerB();
} catch (Exception e) {}
}
@Test
public void testSendThenFailoverThenSend() throws Exception {
ProducerTemplate requester = senderContext.createProducerTemplate();
LOG.info("*** Sending Request 1");
String response = (String) requester.requestBody(fromEndpoint, "This is a request");
assertNotNull(response != null);
LOG.info("Got response: " + response);
/**
* You actually don't need to restart the broker, just wait long enough and the next
* next send will take out a closed connection and reconnect, and if you happen to hit
* the broker you weren't on last time, then you will see the failure.
*/
TimeUnit.SECONDS.sleep(20);
/**
* I restart the broker after the wait that exceeds the idle timeout value of the
* PooledConnectionFactory to show that it doesn't matter now as the older connection
* has already been closed.
*/
LOG.info("Restarting Broker A now.");
shutdownBrokerA();
createBrokerA();
LOG.info("*** Sending Request 2");
response = (String) requester.requestBody(fromEndpoint, "This is a request");
assertNotNull(response != null);
LOG.info("Got response: " + response);
}
private CamelContext createSenderContext() throws Exception {
ActiveMQConnectionFactory amqFactory = new ActiveMQConnectionFactory(connectionUri);
amqFactory.setWatchTopicAdvisories(false);
PooledConnectionFactory pooled = new PooledConnectionFactory(amqFactory);
pooled.setMaxConnections(1);
pooled.setMaximumActiveSessionPerConnection(500);
// If this is not zero the connection could get closed and the request
// reply can fail.
pooled.setIdleTimeout(0);
CamelContext camelContext = new DefaultCamelContext();
ActiveMQComponent amqComponent = new ActiveMQComponent();
amqComponent.setConnectionFactory(pooled);
camelContext.addComponent("activemq", amqComponent);
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from(fromEndpoint).inOut(toEndpoint);
}
});
camelContext.start();
return camelContext;
}
private void createBrokerA() throws Exception {
brokerA = createBroker("brokerA");
brokerAContext = createBrokerCamelContext("brokerA");
brokerA.start();
brokerA.waitUntilStarted();
}
private void shutdownBrokerA() throws Exception {
try {
brokerAContext.stop();
} catch (Exception e) {
brokerA.stop();
brokerA.waitUntilStopped();
brokerA = null;
}
}
private void createBrokerB() throws Exception {
brokerB = createBroker("brokerB");
brokerBContext = createBrokerCamelContext("brokerB");
brokerB.start();
brokerB.waitUntilStarted();
}
private void shutdownBrokerB() throws Exception {
try {
brokerBContext.stop();
} finally {
brokerB.stop();
brokerB.waitUntilStopped();
brokerB = null;
}
}
private BrokerService createBroker(String name) throws Exception {
BrokerService service = new BrokerService();
service.setPersistent(false);
service.setUseJmx(false);
service.setBrokerName(name);
service.addConnector("tcp://localhost:0");
return service;
}
private CamelContext createBrokerCamelContext(String brokerName) throws Exception {
CamelContext camelContext = new DefaultCamelContext();
camelContext.addComponent("activemq",
ActiveMQComponent.activeMQComponent("vm://"+brokerName+"?create=false&waitForStart=10000"));
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from(brokerEndpoint).setBody().simple("Returning ${body}").log("***Reply sent to ${header.JMSReplyTo} CoorId = ${header.JMSCorrelationID}");
}
});
camelContext.start();
return camelContext;
}
}

View File

@ -1,118 +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.camel.component;
import java.util.HashMap;
import java.util.Map;
import javax.jms.Destination;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Headers;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
/**
*
*/
public class InvokeRequestReplyUsingJmsReplyToHeaderTest extends CamelTestSupport {
private static final transient Logger LOG = LoggerFactory.getLogger(ActiveMQReplyToHeaderUsingConverterTest.class);
protected String replyQueueName = "queue://test.reply";
protected Object correlationID = "ABC-123";
protected Object groupID = "GROUP-XYZ";
private MyServer myBean = new MyServer();
@Test
public void testPerformRequestReplyOverJms() throws Exception {
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("cheese", 123);
headers.put("JMSReplyTo", replyQueueName);
headers.put("JMSCorrelationID", correlationID);
headers.put("JMSXGroupID", groupID);
Exchange reply = template.request("activemq:test.server?replyTo=queue:test.reply", new Processor() {
public void process(Exchange exchange) {
exchange.getIn().setBody("James");
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("cheese", 123);
headers.put("JMSReplyTo", replyQueueName);
headers.put("JMSCorrelationID", correlationID);
headers.put("JMSXGroupID", groupID);
exchange.getIn().setHeaders(headers);
}
});
Message in = reply.getIn();
Object replyTo = in.getHeader("JMSReplyTo");
LOG.info("Reply to is: " + replyTo);
LOG.info("Received headers: " + in.getHeaders());
LOG.info("Received body: " + in.getBody());
assertMessageHeader(in, "JMSCorrelationID", correlationID);
Map<String,Object> receivedHeaders = myBean.getHeaders();
assertThat(receivedHeaders, hasKey("JMSReplyTo"));
assertThat(receivedHeaders, hasEntry("JMSXGroupID", groupID));
assertThat(receivedHeaders, hasEntry("JMSCorrelationID", correlationID));
replyTo = receivedHeaders.get("JMSReplyTo");
LOG.info("Reply to is: " + replyTo);
Destination destination = assertIsInstanceOf(Destination.class, replyTo);
assertEquals("ReplyTo", replyQueueName, destination.toString());
}
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
// START SNIPPET: example
camelContext.addComponent("activemq", activeMQComponent("vm://localhost?broker.persistent=false"));
// END SNIPPET: example
return camelContext;
}
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from("activemq:test.server").bean(myBean);
}
};
}
protected static class MyServer {
private Map<String,Object> headers;
public String process(@Headers Map<String,Object> headers, String body) {
this.headers = headers;
LOG.info("process() invoked with headers: " + headers);
return "Hello " + body;
}
public Map<String,Object> getHeaders() {
return headers;
}
}
}

View File

@ -1,82 +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.camel.component;
import javax.jms.ConnectionFactory;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.pool.PooledConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
import static org.apache.camel.component.jms.JmsComponent.jmsComponentAutoAcknowledge;
/**
* A simple request / reply test
*/
public class JmsSimpleRequestReplyTest extends CamelTestSupport {
protected String componentName = "activemq";
@Test
public void testRequestReply() throws Exception {
MockEndpoint result = getMockEndpoint("mock:result");
result.expectedMessageCount(1);
template.requestBody("activemq:queue:hello", "Hello World");
result.assertIsSatisfied();
}
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
ConnectionFactory connectionFactory = createConnectionFactory(null);
camelContext.addComponent("activemq", jmsComponentAutoAcknowledge(connectionFactory));
return camelContext;
}
public static ConnectionFactory createConnectionFactory(String options) {
String url = "vm://test-broker?broker.persistent=false&broker.useJmx=false";
if (options != null) {
url = url + "&" + options;
}
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
// use a pooled connection factory
PooledConnectionFactory pooled = new PooledConnectionFactory(connectionFactory);
pooled.setMaxConnections(8);
return pooled;
}
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from("activemq:queue:hello").process(new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("Bye World");
assertNotNull(exchange.getIn().getHeader("JMSReplyTo"));
}
}).to("mock:result");
}
};
}
}

View File

@ -1,207 +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.camel.component.broker;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerRegistry;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.xbean.BrokerFactoryBean;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import javax.jms.*;
import java.util.Enumeration;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class BrokerComponentXMLConfigTest {
protected static final String CONF_ROOT = "src/test/resources/org/apache/activemq/camel/component/broker/";
protected static final String TOPIC_NAME = "test.broker.component.topic";
protected static final String QUEUE_NAME = "test.broker.component.queue";
protected static final String ROUTE_QUEUE_NAME = "test.broker.component.route";
protected static final String DIVERTED_QUEUE_NAME = "test.broker.component.ProcessLater";
protected static final int DIVERT_COUNT = 100;
protected BrokerService brokerService;
protected ActiveMQConnectionFactory factory;
protected Connection producerConnection;
protected Connection consumerConnection;
protected Session consumerSession;
protected Session producerSession;
protected int messageCount = 1000;
protected int timeOutInSeconds = 10;
@Before
public void setUp() throws Exception {
brokerService = createBroker(new FileSystemResource(CONF_ROOT + "broker-camel.xml"));
factory = new ActiveMQConnectionFactory(BrokerRegistry.getInstance().findFirst().getVmConnectorURI());
consumerConnection = factory.createConnection();
consumerConnection.start();
producerConnection = factory.createConnection();
producerConnection.start();
consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
}
protected BrokerService createBroker(String resource) throws Exception {
return createBroker(new ClassPathResource(resource));
}
protected BrokerService createBroker(Resource resource) throws Exception {
BrokerFactoryBean factory = new BrokerFactoryBean(resource);
factory.afterPropertiesSet();
BrokerService broker = factory.getBroker();
assertTrue("Should have a broker!", broker != null);
// Broker is already started by default when using the XML file
// broker.start();
return broker;
}
@After
public void tearDown() throws Exception {
if (producerConnection != null) {
producerConnection.close();
}
if (consumerConnection != null) {
consumerConnection.close();
}
if (brokerService != null) {
brokerService.stop();
}
}
@Test
public void testReRouteAll() throws Exception {
final ActiveMQQueue queue = new ActiveMQQueue(QUEUE_NAME);
Topic topic = consumerSession.createTopic(TOPIC_NAME);
final CountDownLatch latch = new CountDownLatch(messageCount);
MessageConsumer consumer = consumerSession.createConsumer(queue);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(javax.jms.Message message) {
try {
assertEquals(9, message.getJMSPriority());
latch.countDown();
} catch (Throwable e) {
e.printStackTrace();
}
}
});
MessageProducer producer = producerSession.createProducer(topic);
for (int i = 0; i < messageCount; i++) {
javax.jms.Message message = producerSession.createTextMessage("test: " + i);
producer.send(message);
}
latch.await(timeOutInSeconds, TimeUnit.SECONDS);
assertEquals(0, latch.getCount());
}
@Test
public void testRouteWithDestinationLimit() throws Exception {
final ActiveMQQueue routeQueue = new ActiveMQQueue(ROUTE_QUEUE_NAME);
final CountDownLatch routeLatch = new CountDownLatch(DIVERT_COUNT);
MessageConsumer messageConsumer = consumerSession.createConsumer(routeQueue);
messageConsumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(javax.jms.Message message) {
try {
routeLatch.countDown();
} catch (Throwable e) {
e.printStackTrace();
}
}
});
final CountDownLatch divertLatch = new CountDownLatch(messageCount - DIVERT_COUNT);
MessageConsumer divertConsumer = consumerSession.createConsumer(new ActiveMQQueue(DIVERTED_QUEUE_NAME));
divertConsumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(javax.jms.Message message) {
try {
divertLatch.countDown();
} catch (Throwable e) {
e.printStackTrace();
}
}
});
MessageProducer producer = producerSession.createProducer(routeQueue);
for (int i = 0; i < messageCount; i++) {
javax.jms.Message message = producerSession.createTextMessage("test: " + i);
producer.send(message);
}
routeLatch.await(timeOutInSeconds, TimeUnit.SECONDS);
divertLatch.await(timeOutInSeconds, TimeUnit.SECONDS);
assertEquals(0, routeLatch.getCount());
assertEquals(0, divertLatch.getCount());
}
@Test
public void testPreserveOriginalHeaders() throws Exception {
final ActiveMQQueue queue = new ActiveMQQueue(QUEUE_NAME);
Topic topic = consumerSession.createTopic(TOPIC_NAME);
final CountDownLatch latch = new CountDownLatch(messageCount);
MessageConsumer consumer = consumerSession.createConsumer(queue);
consumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(javax.jms.Message message) {
try {
assertEquals("321", message.getStringProperty("JMSXGroupID"));
assertEquals("custom", message.getStringProperty("CustomHeader"));
latch.countDown();
} catch (Throwable e) {
e.printStackTrace();
}
}
});
MessageProducer producer = producerSession.createProducer(topic);
for (int i = 0; i < messageCount; i++) {
javax.jms.Message message = producerSession.createTextMessage("test: " + i);
message.setStringProperty("JMSXGroupID", "123");
producer.send(message);
}
latch.await(timeOutInSeconds, TimeUnit.SECONDS);
assertEquals(0, latch.getCount());
}
}

View File

@ -1,61 +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.camel.converter;
import javax.jms.MessageListener;
import javax.jms.Message;
import javax.jms.TextMessage;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
/**
*
*/
public class InvokeJmsMessageListenerTest extends CamelTestSupport {
protected MyMessageListener messageListener = new MyMessageListener();
private String expectedBody = "<hello>world!</hello>";
@Test
public void testCamelInvokesMessageListener() throws Exception {
template.sendBody("direct:start", expectedBody);
Message message = messageListener.message;
assertNotNull("Should have invoked the message listener!", message);
TextMessage textMessage = assertIsInstanceOf(TextMessage.class, message);
assertEquals("body", expectedBody, textMessage.getText());
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from("direct:start").bean(messageListener);
}
};
}
protected static class MyMessageListener implements MessageListener {
public Message message;
public void onMessage(Message message) {
this.message = message;
}
}
}

View File

@ -1,72 +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.camel.converter;
import java.util.List;
import javax.jms.Message;
import javax.jms.TextMessage;
import static org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent;
import org.apache.activemq.spring.ConsumerBean;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
/**
*
*/
public class InvokeMessageListenerTest extends CamelTestSupport {
protected MockEndpoint resultEndpoint;
protected String startEndpointUri = "activemq:queue:test.a";
protected ConsumerBean listener = new ConsumerBean();
@Test
public void testSendTextMessage() throws Exception {
String expectedBody = "Hello there!";
template.sendBodyAndHeader(startEndpointUri, expectedBody, "cheese", 123);
listener.assertMessagesArrived(1);
List<Message> list = listener.flushMessages();
assertTrue("Should have received some messages!", !list.isEmpty());
Message message = list.get(0);
log.debug("Received: " + message);
TextMessage textMessage = assertIsInstanceOf(TextMessage.class, message);
assertEquals("Text mesage body: " + textMessage, expectedBody, textMessage.getText());
}
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
camelContext.addComponent("activemq",
activeMQComponent("vm://localhost?broker.persistent=false"));
return camelContext;
}
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() throws Exception {
from(startEndpointUri).bean(listener);
}
};
}
}

View File

@ -1,35 +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.
## ---------------------------------------------------------------------------
#
# The logging properties used during tests..
#
log4j.rootLogger=INFO, out, stdout
#log4j.logger.org.apache.activemq=DEBUG
# CONSOLE appender not used by default
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
# File appender
log4j.appender.out=org.apache.log4j.FileAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
log4j.appender.out.file=target/activemq-test.log
log4j.appender.out.append=true

View File

@ -1,58 +0,0 @@
<?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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.apache.org/schema/core"
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
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq:queue:bar"/>
<to uri="mock:result"/>
</route>
</camelContext>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" factory-method="activeMQComponent">
<constructor-arg index="0" value="vm://testBroker2"/>
<property name="username" value="admin2"/>
<property name="password" value="secret2"/>
</bean>
<broker brokerName="testBroker2" persistent="false" useShutdownHook="false" deleteAllMessagesOnStartup="true"
xmlns="http://activemq.apache.org/schema/core">
<transportConnectors>
<transportConnector uri="vm://testBroker2"/>
</transportConnectors>
<plugins>
<simpleAuthenticationPlugin>
<users>
<authenticationUser username="admin2" password="secret2" groups="users,admins"/>
</users>
</simpleAuthenticationPlugin>
</plugins>
</broker>
</beans>

View File

@ -1,58 +0,0 @@
<?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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.apache.org/schema/core"
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
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq:queue:foo"/>
<to uri="mock:result"/>
</route>
</camelContext>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="vm://testBroker"/>
<property name="username" value="admin"/>
<property name="password" value="secret"/>
</bean>
<broker brokerName="testBroker" persistent="false" useShutdownHook="false" deleteAllMessagesOnStartup="true"
xmlns="http://activemq.apache.org/schema/core">
<transportConnectors>
<transportConnector uri="vm://testBroker"/>
</transportConnectors>
<plugins>
<simpleAuthenticationPlugin>
<users>
<authenticationUser username="admin" password="secret" groups="users,admins"/>
</users>
</simpleAuthenticationPlugin>
</plugins>
</broker>
</beans>

View File

@ -1,48 +0,0 @@
<?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.
-->
<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-2.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<!-- START SNIPPET: e1 -->
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file://src/test/data?noop=true"/>
<to uri="activemq:queue:foo"/>
</route>
<route>
<!-- use consumer.exclusive ActiveMQ destination option, notice we have to prefix with destination. -->
<from uri="activemq:foo?destination.consumer.exclusive=true&amp;destination.consumer.prefetchSize=50"/>
<to uri="mock:results"/>
</route>
</camelContext>
<!-- END SNIPPET: e1 -->
<bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
</bean>
<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="vm://localhost"/>
</bean>
</beans>

View File

@ -1,53 +0,0 @@
<?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.
-->
<!-- START SNIPPET: example -->
<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-2.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file://src/test/data?noop=true"/>
<to uri="activemq:testQ-input"/>
</route>
<route>
<from uri="activemq:testQ-input"/>
<process ref="groupIdInsertionProcessor"/>
<to uri="activemq:testQ-output"/>
</route>
<route>
<from uri="activemq:testQ-output"/>
<to uri="mock:results"/>
</route>
</camelContext>
<bean id="groupIdInsertionProcessor" class="org.apache.activemq.camel.SetGroupIdProcessor"/>
<bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
</bean>
<bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="vm://localhost"/>
</bean>
</beans>
<!-- END SNIPPET: example -->

View File

@ -1,29 +0,0 @@
<?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.
-->
<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-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<broker xmlns="http://activemq.apache.org/schema/core" persistent="false">
<plugins>
<camelRoutesBrokerPlugin checkPeriod="100" />
</plugins>
</broker>
</beans>

View File

@ -1,22 +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.
-->
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="test">
<from uri="broker:topic:test.topic"/>
<to uri="broker:queue:test.queue"/>
</route>
</routes>

View File

@ -1,37 +0,0 @@
<?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.
-->
<!-- START SNIPPET: example -->
<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-2.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<template id="camelTemplate"/>
</camelContext>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="exposeAllQueues" value="true"/>
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
</bean>
</beans>
<!-- END SNIPPET: example -->

View File

@ -1,33 +0,0 @@
<?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.
-->
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:amq="http://activemq.apache.org/schema/core"
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-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<amq:broker brokerName="testBroker" persistent="false" useShutdownHook="false" deleteAllMessagesOnStartup="true">
<amq:transportConnectors>
<amq:transportConnector uri="tcp://localhost:61635"/>
</amq:transportConnectors>
</amq:broker>
<import resource="camel.xml" />
</beans>

View File

@ -1,60 +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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<camelContext id="camel" trace="false" xmlns="http://camel.apache.org/schema/spring">
<route id="brokerComponentTest">
<from uri="broker:topic:test.broker.>"/>
<setHeader headerName="JMSPriority">
<constant>9</constant>
</setHeader>
<setHeader headerName="JMSXGroupID">
<constant>321</constant>
</setHeader>
<setHeader headerName="CustomHeader">
<constant>custom</constant>
</setHeader>
<to uri="broker:queue:test.broker.component.queue"/>
</route>
<route id="brokerComponentDLQAboveLimitTest">
<from uri="broker:queue:test.broker.component.route"/>
<choice>
<when>
<spel>#{@destinationView.enqueueCount >= 100}</spel>
<to uri="broker:queue:test.broker.component.ProcessLater"/>
</when>
<otherwise>
<to uri="broker:queue:test.broker.component.route"/>
</otherwise>
</choice>
</route>
</camelContext>
<bean id="brokerView" class="org.apache.activemq.broker.view.MessageBrokerView">
<constructor-arg value="testBroker"/>
</bean>
<bean id="destinationView" factory-bean="brokerView" factory-method="getDestinationView">
<constructor-arg value="test.broker.component.route"/>
</bean>
</beans>

View File

@ -1,71 +0,0 @@
<?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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd
">
<bean id="transactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="pooledConnectionFactory"/>
</bean>
<bean id="localJMS" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="pooledConnectionFactory"/>
<property name="transactionManager" ref="transactionManager"/>
<property name="transacted" value="true"/>
</bean>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route id="orders">
<from uri="localJMS:fidEtpOrders" />
<transacted/>
<!-- <log loggingLevel="INFO" message="from activemq:fidessaTrades: ${body}" /> -->
<bean ref="canError" method="enrich" />
<wireTap uri="localJMS:ordersTap" />
<to uri="localJMS:fidessaOrders" />
</route>
</camelContext>
<bean id="activemqConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://testDlq" />
<property name="redeliveryPolicy" ref="redeliveryPolicy"/>
</bean>
<bean id="redeliveryPolicy" class="org.apache.activemq.RedeliveryPolicy">
<property name="maximumRedeliveries" value="1"/>
</bean>
<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="maxConnections" value="8" />
<property name="connectionFactory" ref="activemqConnectionFactory" />
</bean>
<!-- only for jta - not jms tm
bean id="resourceManager" class="org.apache.activemq.jms.pool.GenericResourceManager" init-method="recoverResource">
<property name="transactionManager" ref="transactionManager" />
<property name="connectionFactory" ref="activemqConnectionFactory" />
<property name="resourceName" value="activemq.default" />
</bean -->
<bean id="canError" class="org.apache.activemq.camel.DlqTest$CanError"/>
</beans>

View File

@ -1,116 +0,0 @@
<?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.
-->
<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-2.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq-activemq:topic:foo"/>
<to uri="mock:result-activemq"/>
</route>
<route>
<from uri="activemq-camel:topic:foo"/>
<to uri="mock:result-camel"/>
</route>
<route>
<from uri="activemq-empty:topic:foo"/>
<to uri="mock:result-empty"/>
</route>
<route>
<from uri="activemq-trusted:topic:foo"/>
<to uri="mock:result-trusted"/>
</route>
</camelContext>
<!-- configuration for activemq-camel endpoint -->
<bean id="camelConnectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
<property name="trustedPackages">
<list>
<value>org.apache.camel</value>
</list>
</property>
</bean>
<bean id="camelConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="camelConnectionFactory"/>
</bean>
<bean id="activemq-camel" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="camelConfig"/>
</bean>
<!-- configuration for activemq-activemq endpoint -->
<bean id="activemqConnectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
<property name="trustedPackages">
<list>
<value>org.apache.activemq</value>
</list>
</property>
</bean>
<bean id="activemqConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="activemqConnectionFactory"/>
</bean>
<bean id="activemq-activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="activemqConfig"/>
</bean>
<!-- configuration for activemq-empty endpoint -->
<bean id="emptyConnectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
<property name="trustedPackages">
<list>
<value></value>
</list>
</property>
</bean>
<bean id="emptyConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="emptyConnectionFactory"/>
</bean>
<bean id="activemq-empty" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="emptyConfig"/>
</bean>
<!-- configuration for activemq-trusted endpoint -->
<bean id="trustedConnectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
<property name="trustAllPackages" value="true"/>
</bean>
<bean id="trustedConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="trustedConnectionFactory"/>
</bean>
<bean id="activemq-trusted" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="trustedConfig"/>
</bean>
</beans>

View File

@ -1,85 +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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<context:annotation-config/>
<context:property-placeholder properties-ref="inlineSharedValues"/>
<bean id="inlineSharedValues"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<!-- we want to match the producer connection pool with the concurrentConsumers.
Increase this to get concurrent parallel transactions -->
<prop key="concurrentSends">5</prop>
</props>
</property>
</bean>
<!-- from broker -->
<bean id="cfPub" class="org.apache.activemq.ActiveMQConnectionFactory">
<!-- we don't want mesages to go to the DLQ, hense infinite redeliveries -->
<property name="brokerURL"
value="failover:(tcp://localhost:61616)?jms.redeliveryPolicy.maximumRedeliveries=-1"/>
</bean>
<bean id="pooledCfPub" class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="maxConnections" value="1"/>
<property name="connectionFactory" ref="cfPub"/>
</bean>
<bean id="activemq-pub" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="pooledCfPub"/>
<property name="transacted" value="true"/>
<property name="concurrentConsumers" value="${concurrentSends}"/>
<property name="cacheLevelName" value="CACHE_CONSUMER"/>
</bean>
<!-- to broker -->
<bean id="cfSub" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="failover:(tcp://localhost:61617)"/>
<property name="disableTimeStampsByDefault" value="true"/>
<property name="copyMessageOnSend" value="false"/>
</bean>
<bean id="pooledCfSub" class="org.apache.activemq.pool.PooledConnectionFactory">
<property name="maxConnections" value="${concurrentSends}"/>
<property name="connectionFactory" ref="cfSub"/>
</bean>
<bean id="activemq-sub" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="pooledCfSub"/>
<property name="forceSendOriginalMessage" value="true"/>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring" id="camel-bridge">
<route id="move-route">
<from uri="activemq-pub:queue:from"/>
<to uri="activemq-sub:queue:to"/>
</route>
</camelContext>
</beans>

View File

@ -1,57 +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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<context:annotation-config />
<bean id="cf" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="failover:(tcp://localhost:61616)"/>
</bean>
<bean id="pooledCf" class="org.apache.activemq.pool.PooledConnectionFactory">
<!-- match maxConnections to the number of routes that share the connection factory -->
<property name="maxConnections" value="10"/>
<!-- match maximumActive (which is active sessions) >= concurrentConsumers in the MLC -->
<property name="maximumActiveSessionPerConnection" value="1"/>
<property name="connectionFactory" ref="cf"/>
</bean>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<!-- set cf - so that inbound and outbound endpoints share the connection pool and transacted session -->
<property name="connectionFactory" ref="pooledCf" />
<property name="transacted" value="true" />
<property name="concurrentConsumers" value="1" />
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring" id="camel-queue-transporter">
<route id="move-route">
<from uri="activemq:queue:from" />
<to uri="activemq:queue:to" />
</route>
</camelContext>
</beans>

View File

@ -1,111 +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.
-->
<!-- START SNIPPET: jms_jdbc_xa -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd
">
<context:annotation-config />
<!-- broker creation in code so it can be restarted and modified to test recovery -->
<!-- use jencks factory beans to easily configure howl and geronimo transaction manager -->
<bean id="xidFactory" class="org.apache.geronimo.transaction.manager.XidFactoryImpl"/>
<!-- Transaction log -->
<bean id="transactionLog" class="org.jencks.factory.HowlLogFactoryBean">
<property name="logFileDir" value="target/data/howl/txlog"/>
<property name="xidFactory" ref="xidFactory"/>
</bean>
<bean id="jenckTransactionManager" class="org.jencks.factory.TransactionManagerFactoryBean">
<property name="transactionLog" ref="transactionLog"/>
</bean>
<bean id="activemqConnectionFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616?jms.dispatchAsync=false"/>
</bean>
<!-- register ActiveMQ with Geronimo to allow out of band transaction recovery/completion on a new connection
the resourceName gives the ActiveMQ XAResource an identity, Geronimo NamedXAResource in the transaction log
-->
<bean id="resourceManager" class="org.apache.activemq.pool.ActiveMQResourceManager" init-method="recoverResource">
<property name="transactionManager" ref="jenckTransactionManager"/>
<property name="connectionFactory" ref="activemqConnectionFactory"/>
<property name="resourceName" value="activemq.broker"/>
</bean>
<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactoryBean"
depends-on="jenckTransactionManager">
<property name="maxConnections" value="1"/>
<property name="transactionManager" ref="jenckTransactionManager"/>
<property name="connectionFactory" ref="activemqConnectionFactory"/>
<property name="resourceName" value="activemq.broker"/>
</bean>
<!-- Configure the Spring framework (used by camel) to use JTA transactions from Geronimo -->
<bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="jenckTransactionManager"/>
</bean>
<!-- Define the activemq Camel component so we can integrate with the AMQ broker -->
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"
depends-on="pooledConnectionFactory">
<property name="transacted" value="true"/>
<property name="transactionManager" ref="jtaTransactionManager"/>
<property name="connectionFactory" ref="pooledConnectionFactory"/>
<!-- cache level is important, can be cache connection or none, as session needs to be enlisted
in the current transaction they can't be cached, with default cache sessions, they are created
up front, before the transaction (required for the route) -->
<property name="cacheLevel" value="0"/>
</bean>
<bean id="managedDataSourceWithRecovery" class="org.apache.commons.dbcp2.managed.BasicManagedDataSource" destroy-method="close">
<property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="url" value="jdbc:derby:target/XatestDs;create=true" />
<property name="username" value="user" />
<property name="password" value="secret" />
<property name="transactionManager" ref="jenckTransactionManager" />
</bean>
<bean id="required" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="jenckTransactionManager"/>
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/>
</bean>
<!-- the route, from jms to jdbc in an xa transaction -->
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route id="queueToDbTransacted">
<from uri="activemq:queue:scp_transacted"/>
<transacted ref="required"/>
<convertBodyTo type="java.lang.String"/>
<to uri="log:BeforeSettingBody?showAll=true"/>
<setBody>
<simple>INSERT INTO SCP_INPUT_MESSAGES(messageId, messageCorrelationId, messageContent)
VALUES('${in.header.JMSMessageId}','${in.header.JMSCorrelationId}','${in.body}')
</simple>
</setBody>
<to uri="jdbc:managedDataSourceWithRecovery?resetAutoCommit=false"/>
</route>
</camelContext>
</beans>
<!-- END SNIPPET: jms_jdbc_xa -->

View File

@ -1,116 +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.
-->
<!-- START SNIPPET: jms_jdbc_xa -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd
">
<context:annotation-config />
<!-- broker creation in code so it can be restarted and modified to test recovery -->
<!-- use jencks factory beans to easily configure howl and geronimo transaction manager -->
<bean id="xidFactory" class="org.apache.geronimo.transaction.manager.XidFactoryImpl"/>
<!-- Transaction log -->
<bean id="transactionLog" class="org.jencks.factory.HowlLogFactoryBean">
<property name="logFileDir" value="target/data/howl/txlog"/>
<property name="xidFactory" ref="xidFactory"/>
</bean>
<bean id="jenckTransactionManager" class="org.jencks.factory.TransactionManagerFactoryBean">
<property name="transactionLog" ref="transactionLog"/>
</bean>
<bean id="activemqConnectionFactory" class="org.apache.activemq.ActiveMQXAConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616?jms.dispatchAsync=false&amp;jms.redeliveryPolicy.maximumRedeliveries=2&amp;jms.redeliveryPolicy.initialRedeliveryDelay=100"/>
</bean>
<!-- register ActiveMQ with Geronimo to allow out of band transaction recovery/completion on a new connection
the resourceName gives the ActiveMQ XAResource an identity, Geronimo NamedXAResource in the transaction log
-->
<bean id="resourceManager" class="org.apache.activemq.pool.ActiveMQResourceManager" init-method="recoverResource">
<property name="transactionManager" ref="jenckTransactionManager"/>
<property name="connectionFactory" ref="activemqConnectionFactory"/>
<property name="resourceName" value="activemq.broker"/>
</bean>
<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactoryBean"
depends-on="jenckTransactionManager">
<property name="maxConnections" value="1"/>
<property name="transactionManager" ref="jenckTransactionManager"/>
<property name="connectionFactory" ref="activemqConnectionFactory"/>
<property name="resourceName" value="activemq.broker"/>
</bean>
<!-- Configure the Spring framework (used by camel) to use JTA transactions from Geronimo -->
<bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager" ref="jenckTransactionManager"/>
</bean>
<!-- Define the activemq Camel component so we can integrate with the AMQ broker -->
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"
depends-on="pooledConnectionFactory">
<property name="transacted" value="true"/>
<property name="transactionManager" ref="jtaTransactionManager"/>
<property name="connectionFactory" ref="pooledConnectionFactory"/>
<!-- cache level is important, can be cache connection or none, as session needs to be enlisted
in the current transaction they can't be cached, with default cache sessions, they are created
up front, before the transaction (required for the route) -->
<property name="cacheLevel" value="0"/>
</bean>
<bean id="managedDataSourceWithRecovery" class="org.apache.commons.dbcp2.managed.BasicManagedDataSource" destroy-method="close">
<property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="url" value="jdbc:derby:target/XatestDs;create=true" />
<property name="username" value="user" />
<property name="password" value="secret" />
<property name="transactionManager" ref="jenckTransactionManager" />
</bean>
<bean id="required" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="jenckTransactionManager"/>
<property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/>
</bean>
<bean id="markRollback" class="org.apache.activemq.camel.JmsJdbcXARollbackTest.MarkRollbackOnly"/>
<!-- the route, from jms to jdbc in an xa transaction -->
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route id="queueToDbTransacted">
<from uri="activemq:queue:scp_transacted"/>
<transacted ref="required"/>
<bean ref="markRollback" method="enrich" />
<convertBodyTo type="java.lang.String"/>
<to uri="log:BeforeSettingBody?showAll=true"/>
<to uri="activemq:queue:scp_transacted_out"/>
<setBody>
<simple>INSERT INTO SCP_INPUT_MESSAGES(messageId, messageCorrelationId, messageContent)
VALUES('${in.header.JMSMessageId}','${in.header.JMSCorrelationId}','${in.body}')
</simple>
</setBody>
<to uri="jdbc:managedDataSourceWithRecovery?resetAutoCommit=false"/>
</route>
</camelContext>
</beans>
<!-- END SNIPPET: jms_jdbc_xa -->

View File

@ -1,76 +0,0 @@
<?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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route id="initial-consume-reply1">
<from uri="amqPRO:queue:incoming1"/>
<to uri="amqPRO:queue:service1?replyToType=Temporary&amp;requestTimeout=35000" pattern="InOut"/>
<log message="After inOut via temp: body ${body}"/>
<to uri="seda:consumer"/>
</route>
<route id="consume-process-reply1">
<from uri="amqCON:queue:service1"/>
<choice>
<when>
<simple>${body} contains 'What is your name?'</simple>
<transform>
<simple>bobbie!</simple>
</transform>
</when>
<otherwise>
<transform>
<simple>If you don't ask me my name, I'm not going to tell you!</simple>
</transform>
</otherwise>
</choice>
<log message="${body}"/>
</route>
</camelContext>
<bean id="CON" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://CON?create=false"/>
</bean>
<bean id="PRO" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://PRO??create=false"/>
</bean>
<bean id="consumeFrom" class="org.apache.activemq.camel.CamelDestination">
<property name="uri" value="seda:consumer"/>
</bean>
<bean id="camelTemplate" class="org.apache.camel.spring.CamelProducerTemplateFactoryBean"/>
<bean id="amqPRO" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="vm://PRO?create=false"></property>
</bean>
<bean id="amqCON" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="vm://CON?create=false"></property>
</bean>
</beans>

View File

@ -1,49 +0,0 @@
<?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.
-->
<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-2.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
<!-- START SNIPPET: example -->
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"/>
<bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
</bean>
<bean id="sendTo" class="org.apache.activemq.camel.CamelDestination">
<property name="uri" value="mock:result"/>
</bean>
<bean id="consumeFrom" class="org.apache.activemq.camel.CamelDestination">
<property name="uri" value="seda:consumer"/>
</bean>
<bean id="camelTemplate" class="org.apache.camel.spring.CamelProducerTemplateFactoryBean"/>
<!-- END SNIPPET: example -->
<!--
<bean id="connectionFactory" class="org.apache.camel.jms.CamelConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
</bean>
-->
</beans>

View File

@ -1,141 +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.
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd
">
<context:annotation-config/>
<bean id="vhfBatchListenerJMSConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616?jms.prefetchPolicy.all=1"/>
</bean>
<bean id="vhfBatchListenerPooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
<!-- match maxConnections to the number of routes that share the connection factory -->
<property name="maxConnections" value="10"/>
<!-- match maximumActive (which is active sessions) >= concurrentConsumers in the MLC -->
<property name="maximumActiveSessionPerConnection" value="1"/>
<property name="connectionFactory" ref="vhfBatchListenerJMSConnectionFactory"/>
</bean>
<!-- JMS Transaction manager -->
<bean id="vhfBatchListenerJMSTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="vhfBatchListenerPooledConnectionFactory"/>
</bean>
<!-- JMS Configuration -->
<bean id="vhfBatchListenerJMSConfig" class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="vhfBatchListenerPooledConnectionFactory"/>
<property name="transactionManager" ref="vhfBatchListenerJMSTransactionManager"/>
<property name="transacted" value="true"/>
<property name="concurrentConsumers" value="1"/>
<property name="cacheLevelName" value="CACHE_CONSUMER"/>
</bean>
<!-- JMS Transaction policy -->
<bean id="vhfBatchListenerTransaction" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
<property name="transactionManager" ref="vhfBatchListenerJMSTransactionManager"/>
</bean>
<!-- ActiveMQ component -->
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="vhfBatchListenerJMSConfig"/>
</bean>
<bean id="activemq2" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="vhfBatchListenerJMSConfig"/>
</bean>
<bean id="activemq3" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="vhfBatchListenerJMSConfig"/>
</bean>
<bean id="activemq4" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="vhfBatchListenerJMSConfig"/>
</bean>
<bean id="activemq5" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="vhfBatchListenerJMSConfig"/>
</bean>
<bean id="activemq6" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="vhfBatchListenerJMSConfig"/>
</bean>
<bean id="activemq7" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="vhfBatchListenerJMSConfig"/>
</bean>
<bean id="activemq8" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="vhfBatchListenerJMSConfig"/>
</bean>
<bean id="activemq9" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="vhfBatchListenerJMSConfig"/>
</bean>
<bean id="activemq10" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="configuration" ref="vhfBatchListenerJMSConfig"/>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq:queue:scp_transacted"/>
<process ref="connectionLog"/>
</route>
<!-- better through put with a additional route/connection once shared pool config matches concurrentConsumers -->
<route>
<from uri="activemq2:queue:scp_transacted"/>
<process ref="connectionLog"/>
</route>
<route>
<from uri="activemq3:queue:scp_transacted"/>
<process ref="connectionLog"/>
</route>
<route>
<from uri="activemq4:queue:scp_transacted"/>
<process ref="connectionLog"/>
</route>
<route>
<from uri="activemq5:queue:scp_transacted"/>
<process ref="connectionLog"/>
</route>
<route>
<from uri="activemq6:queue:scp_transacted"/>
<process ref="connectionLog"/>
</route>
<route>
<from uri="activemq7:queue:scp_transacted"/>
<process ref="connectionLog"/>
</route>
<route>
<from uri="activemq8:queue:scp_transacted"/>
<process ref="connectionLog"/>
</route>
<route>
<from uri="activemq9:queue:scp_transacted"/>
<process ref="connectionLog"/>
</route>
<route>
<from uri="activemq10:queue:scp_transacted"/>
<process ref="connectionLog"/>
</route>
</camelContext>
<bean id="connectionLog" class="org.apache.activemq.camel.TransactedConsumeTest.ConnectionLog"/>
</beans>

View File

@ -51,7 +51,7 @@ public class ActiveMQBrokerNdCamelFeatureTest extends AbstractFeatureTest {
assertBrokerStarted();
withinReason(new Runnable() {
public void run() {
getBundle("org.apache.activemq.activemq-camel");
getBundle("org.apache.camel.camel-jms");
assertTrue("we have camel consumers", executeCommand("activemq:dstat").trim().contains("camel_in"));
}
});

View File

@ -56,7 +56,7 @@ public class ActiveMQBrokerNdExternalCamelFeatureTest extends AbstractFeatureTes
withinReason(new Runnable() {
@Override
public void run() {
getBundle("org.apache.activemq.activemq-camel");
getBundle("org.apache.camel.camel-jms");
}
});

View File

@ -81,7 +81,7 @@
</bean>
<!-- Define the activemq Camel component so we can integrate with the AMQ broker -->
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"
<bean id="activemq" class="org.apache.camel.component.jms.JmsComponent"
depends-on="pooledConnectionFactory">
<property name="connectionFactory" ref="pooledConnectionFactory"/>
<property name="cacheLevel" value="0"/>

View File

@ -34,7 +34,7 @@
<property name="connectionFactory" ref="activemqConnectionFactory"/>
</bean>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"
<bean id="activemq" class="org.apache.camel.component.jms.JmsComponent"
depends-on="pooledConnectionFactory">
<property name="connectionFactory" ref="pooledConnectionFactory"/>
<property name="cacheLevel" value="0"/>

View File

@ -44,7 +44,6 @@
<feature name="activemq-camel" version="${project.version}">
<feature version="${project.version}">activemq-client</feature>
<bundle>mvn:org.apache.activemq/activemq-camel/${project.version}</bundle>
<feature version="${camel-version-range}">camel-jms</feature>
<feature version="${camel-version-range}">camel</feature>
<feature version="${camel-version-range}">camel-spring</feature>

View File

@ -161,7 +161,6 @@
javax.servlet*;resolution:=optional,
com.thoughtworks.xstream*;resolution:=optional,
org.apache.activeio*;resolution:=optional,
org.apache.activemq.camel*;resolution:=optional,
org.apache.camel*;version="${camel-version-range}";resolution:=optional,
org.apache.camel.spring.handler;version="${camel-version-range}";resolution:=optional,
org.apache.camel.spring.xml.handler;version="${camel-version-range}";resolution:=optional,

View File

@ -213,7 +213,6 @@
<includes>
<include>${basedir}/../activemq-client/src/main/java</include>
<include>${basedir}/../activemq-broker/src/main/java</include>
<include>${basedir}/../activemq-camel/src/main/java</include>
<include>${basedir}/../activemq-jdbc-store/src/main/java</include>
<include>${basedir}/../activemq-kahadb-store/src/main/java</include>
<include>${basedir}/../activemq-mqtt/src/main/java</include>

View File

@ -335,10 +335,6 @@
<title>JMS Client support classes for working with BLOBs and JNDI</title>
<packages>org.apache.activemq.blob:org.apache.activemq.jndi</packages>
</group>
<group>
<title>Enterprise Integration Pattern support via Camel</title>
<packages>org.apache.activemq.camel:org.apache.activemq.camel.*</packages>
</group>
<group>
<title>Spring support</title>
<packages>org.apache.activemq.spring:org.apache.activemq.xbean:org.apache.activemq.pool</packages>
@ -834,20 +830,6 @@
<exclude>org/apache/activemq/bugs/TempStoreDataCleanupTest.*</exclude>
<exclude>org/apache/activemq/bugs/VMTransportClosureTest.*</exclude>
<exclude>org/apache/activemq/bugs/amq1095/MessageSelectorTest.*</exclude>
<exclude>org/apache/activemq/camel/AMQ2611Test.*</exclude>
<exclude>org/apache/activemq/camel/CamelDestinationExclusiveConsumerTest.*</exclude>
<exclude>org/apache/activemq/camel/CamelRedeliveryTest.*</exclude>
<exclude>org/apache/activemq/camel/CamelVMTransportRoutingTest.*</exclude>
<exclude>org/apache/activemq/camel/DlqTest.*</exclude>
<exclude>org/apache/activemq/camel/JmsJdbcXATest.*</exclude>
<exclude>org/apache/activemq/camel/SetHeaderTest.*</exclude>
<exclude>org/apache/activemq/camel/TransactedConsumeTest.*</exclude>
<exclude>org/apache/activemq/camel/component/ActiveMQJmsHeaderRouteTest.*</exclude>
<exclude>org/apache/activemq/camel/component/ActiveMQRouteTest.*</exclude>
<exclude>org/apache/activemq/camel/component/AutoExposeQueuesInCamelTest.*</exclude>
<exclude>org/apache/activemq/camel/component/InvokeRequestReplyUsingJmsReplyToHeaderTest.*</exclude>
<exclude>org/apache/activemq/camel/component/JmsSimpleRequestReplyTest.*</exclude>
<exclude>org/apache/activemq/camel/component/JournalRouteTest.*</exclude>
<exclude>org/apache/activemq/command/MessageCompressionTest.*</exclude>
<exclude>org/apache/activemq/config/BrokerXmlConfigFromJNDITest.*</exclude>
<exclude>org/apache/activemq/config/ConfigTest.*</exclude>

View File

@ -37,10 +37,6 @@
<groupId>${project.groupId}</groupId>
<artifactId>activemq-all</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activemq-camel</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>activeio-core</artifactId>

View File

@ -166,7 +166,6 @@
<include>org.apache.camel:camel-core</include>
<include>org.apache.camel:camel-spring</include>
<include>org.apache.camel:camel-jms</include>
<include>org.apache.activemq:activemq-camel</include>
</includes>
<fileMode>0644</fileMode>
<directoryMode>0755</directoryMode>

Some files were not shown because too many files have changed in this diff Show More