Skip to content

Commit

Permalink
[resolves wildfly-extras#1852] Add support for component zookeeper-ma…
Browse files Browse the repository at this point in the history
…ster
  • Loading branch information
tdiesler committed Oct 26, 2017
1 parent e592be4 commit cfb558e
Show file tree
Hide file tree
Showing 22 changed files with 1,077 additions and 35 deletions.
2 changes: 1 addition & 1 deletion catalog/src/main/resources/component.roadmap
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ xslt
yammer
zendesk
zookeeper
zookeeper-master

[planned]
atmos #1984
Expand Down Expand Up @@ -263,7 +264,6 @@ stomp #2033
tika #1850
twilio #2130
websocket #1479
zookeeper-master #1852

[undecided]
elasticsearch5-rest
Expand Down
5 changes: 5 additions & 0 deletions docs/guide/components/camel-zookeeper-master.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### camel-zookeeper-master

The https://github.com/apache/camel/blob/camel-{camel-version}/components/camel-zookeeper-master/src/main/docs/zookeeper-master-component.adoc[zookeeper-master,window=_blank] component provides a way to ensure only a single consumer in a cluster consumes from a given endpoint; with automatic failover if that JVM dies.
This can be very useful if you need to consume from some legacy back end which either doesn’t support concurrent consumption or due to commercial or stability reasons you can only have a single connection at any point in time.
2 changes: 2 additions & 0 deletions docs/guide/components/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ include::camel-zipkin.adoc[]

include::camel-zookeeper.adoc[]

include::camel-zookeeper-master.adoc[]

### Adding Components

Adding support for additional Camel Components is easy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
<module name="org.apache.camel.component.zipfile" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.zipkin" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.zookeeper" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.zookeeper.master" export="true" services="export" optional="true" />

<module name="org.wildfly.camel.extras" export="true" services="export" optional="true" />
</dependencies>
Expand Down
15 changes: 15 additions & 0 deletions feature/modules/etc/smartics/camel-modules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3023,4 +3023,19 @@
</dependencies>
</module>

<module name="org.apache.camel.component.zookeeper.master">
<include artifact="org.apache.camel:camel-zookeeper-master" />
<apply-to-dependencies skip="true">
<include module="org.apache.camel.apt" />
<include module="org.springframework.boot" />
</apply-to-dependencies>
<dependencies>
<module name="com.google.guava"/>
<module name="org.slf4j"/>
</dependencies>
<exports>
<exclude path="org/apache/camel/component/zookeepermaster/group/internal**" />
</exports>
</module>

</modules>
4 changes: 4 additions & 0 deletions feature/modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,10 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-zookeeper</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-zookeeper-master</artifactId>
</dependency>
<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-ldap-codec-standalone</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@
<module name="org.apache.camel.component.zipfile" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.zipkin" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.zookeeper" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.zookeeper.master" export="true" services="export" optional="true" />

<module name="org.wildfly.camel.extras" export="true" services="export" optional="true" />
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.apache.camel.component.zookeeper.master">
<resources>
<artifact name="${org.apache.camel:camel-zookeeper-master}" />
</resources>
<dependencies>
<module name="com.google.guava" />
<module name="org.slf4j" />
<module name="com.fasterxml.jackson.core.jackson-annotations" />
<module name="com.fasterxml.jackson.core.jackson-core" />
<module name="com.fasterxml.jackson.core.jackson-databind" />
<module name="io.netty" slot="3.10" />
<module name="javax.xml.bind.api" />
<module name="org.apache.camel.core" />
<module name="org.apache.curator" />
<module name="org.apache.zookeeper" />
</dependencies>
<exports>
<exclude path="org/apache/camel/component/zookeepermaster/group/internal**" />
</exports>
</module>
8 changes: 8 additions & 0 deletions itests/camel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-zookeeper-master</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.gravia</groupId>
<artifactId>gravia-resource</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**
* 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.wildfly.camel.test.plain.zookeepermaster;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;

/**
* Spring {@link FactoryBean} to make using {@link CuratorFramework} easier to setup
* in Spring XML files also.
*/
public class CuratorFactoryBean implements FactoryBean<CuratorFramework>, DisposableBean {

private static final transient Logger LOG = LoggerFactory.getLogger(CuratorFactoryBean.class);

private String connectString = "localhost:2181";
private int timeout = 30000;
private CuratorFramework curator;

public String getConnectString() {
return connectString;
}

public void setConnectString(String connectString) {
this.connectString = connectString;
}

public int getTimeout() {
return timeout;
}

public void setTimeout(int timeout) {
this.timeout = timeout;
}

// FactoryBean interface
//-------------------------------------------------------------------------
public CuratorFramework getObject() throws Exception {
LOG.debug("Connecting to ZooKeeper on " + connectString);

CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
.connectString(connectString)
.retryPolicy(new ExponentialBackoffRetry(5, 10))
.connectionTimeoutMs(getTimeout());

this.curator = builder.build();
LOG.debug("Starting curator " + curator);
curator.start();
return curator;
}

public Class<?> getObjectType() {
return CuratorFramework.class;
}

public boolean isSingleton() {
return true;
}

public void destroy() throws Exception {
if (curator != null) {
// Note we cannot use zkClient.close()
// since you cannot currently close a client which is not connected
curator.close();
curator = null;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* 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.wildfly.camel.test.plain.zookeepermaster;

import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.apache.camel.CamelContext;
import org.apache.camel.ServiceStatus;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Assert;
import org.junit.Test;

public class MasterQuartz2EndpointTest {

@Test
public void testEndpoint() throws Exception {

URL resourceUrl = getClass().getClassLoader().getResource("MasterQuartz2EndpointTest-context.xml");
CamelContext camelctx = SpringCamelContextFactory.createSingleCamelContext(resourceUrl, null);
Assert.assertEquals(ServiceStatus.Stopped, camelctx.getStatus());

MockEndpoint mockResult = camelctx.getEndpoint("mock:results", MockEndpoint.class);
mockResult.expectedMinimumMessageCount(2);

camelctx.start();
try {
MockEndpoint.assertIsSatisfied(5, TimeUnit.SECONDS, mockResult);
} finally {
camelctx.stop();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* #%L
* Wildfly Camel :: Subsystem
* %%
* Copyright (C) 2013 - 2017 RedHat
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package org.wildfly.camel.test.plain.zookeepermaster;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.concurrent.Callable;

/**
* A utility class to run arbitrary code via a {@link Proxy} instance.
*/
public class ProxyUtils {

private ProxyUtils() {
// Hide ctor
}

/**
* Runs a {@link Callable} within a {@link Proxy} instance. See the following issues for information
* around its primary use case.
*
* https://issues.jboss.org/browse/ENTESB-7117
* https://github.com/wildfly-extras/wildfly-camel/issues/1919
*
* @param callable A callable instance to invoke within a {@link Proxy} instance
* @param classLoader The ClassLoader used to create the {@link Proxy} instance
* @throws Exception
*/
public static void invokeProxied(final Callable<?> callable, final ClassLoader classLoader) throws Exception {
Callable<?> callableProxy = (Callable) Proxy.newProxyInstance(classLoader, new Class<?>[] { Callable.class }, new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
callable.call();
return null;
}
});
callableProxy.call();
}
}
Loading

0 comments on commit cfb558e

Please sign in to comment.