forked from wildfly-extras/wildfly-camel
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[resolves wildfly-extras#1852] Add support for component zookeeper-ma…
…ster
- Loading branch information
Showing
22 changed files
with
1,077 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...es/modules/system/layers/fuse/org/apache/camel/component/zookeeper/master/main/module.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
.../camel/src/test/java/org/wildfly/camel/test/plain/zookeepermaster/CuratorFactoryBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...src/test/java/org/wildfly/camel/test/plain/zookeepermaster/MasterQuartz2EndpointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
itests/camel/src/test/java/org/wildfly/camel/test/plain/zookeepermaster/ProxyUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.