-
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.
Merge pull request #6 from factorhouse/update-to-factorhouse
update-to-factorhouse
- Loading branch information
Showing
17 changed files
with
189 additions
and
58 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
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
2 changes: 1 addition & 1 deletion
2
src/clojure/io/operatr/kpow/serdes.clj → src/clojure/io/factorhouse/kpow/serdes.clj
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,117 @@ | ||
package io.factorhouse.kpow; | ||
|
||
import clojure.java.api.Clojure; | ||
import clojure.lang.IFn; | ||
import org.apache.kafka.clients.producer.KafkaProducer; | ||
import org.apache.kafka.common.serialization.Serializer; | ||
import org.apache.kafka.streams.KafkaStreams; | ||
import org.apache.kafka.streams.Topology; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Properties; | ||
|
||
public class StreamsRegistry implements AutoCloseable { | ||
|
||
public static class StreamsAgent { | ||
private final String _id; | ||
|
||
StreamsAgent(String id) { | ||
_id = id; | ||
} | ||
|
||
public String getId() { | ||
return _id; | ||
} | ||
} | ||
|
||
private final Object agent; | ||
|
||
public static Properties filterProperties(Properties props) { | ||
ArrayList<String> allowedKeys = new ArrayList<>(); | ||
allowedKeys.add("ssl.enabled.protocols"); | ||
allowedKeys.add("sasl.client.callback.handler.class"); | ||
allowedKeys.add("ssl.endpoint.identification.algorithm"); | ||
allowedKeys.add("ssl.provider"); | ||
allowedKeys.add("ssl.truststore.location"); | ||
allowedKeys.add("ssl.keystore.key"); | ||
allowedKeys.add("ssl.key.password"); | ||
allowedKeys.add("ssl.protocol"); | ||
allowedKeys.add("ssl.keystore.password"); | ||
allowedKeys.add("sasl.login.class"); | ||
allowedKeys.add("ssl.trustmanager.algorithm"); | ||
allowedKeys.add("ssl.keystore.location"); | ||
allowedKeys.add("sasl.login.callback.handler.class"); | ||
allowedKeys.add("ssl.truststore.certificates"); | ||
allowedKeys.add("ssl.cipher.suites"); | ||
allowedKeys.add("ssl.truststore.password"); | ||
allowedKeys.add("ssl.keymanager.algorithm"); | ||
allowedKeys.add("ssl.keystore.type"); | ||
allowedKeys.add("ssl.secure.random.implementation"); | ||
allowedKeys.add("ssl.truststore.type"); | ||
allowedKeys.add("sasl.jaas.config"); | ||
allowedKeys.add("ssl.keystore.certificate.chain"); | ||
allowedKeys.add("sasl.mechanism"); | ||
allowedKeys.add("sasl.oauthbearer.jwks.endpoint.url"); | ||
allowedKeys.add("sasl.oauthbearer.token.endpoint.url"); | ||
allowedKeys.add("sasl.kerberos.service.name"); | ||
allowedKeys.add("security.protocol"); | ||
allowedKeys.add("bootstrap.servers"); | ||
|
||
Properties nextProps = new Properties(); | ||
for (String key : allowedKeys) { | ||
if (props.containsKey(key)) { | ||
nextProps.setProperty(key, String.valueOf(props.get(key))); | ||
} | ||
} | ||
|
||
String compressionType = props.getProperty("compression.type", "gzip"); | ||
nextProps.setProperty("compression.type", compressionType); | ||
|
||
String idempotence = props.getProperty("enable.idempotence", "false"); | ||
nextProps.setProperty("enable.idempotence", idempotence); | ||
|
||
return nextProps; | ||
} | ||
|
||
public StreamsRegistry(Properties props) { | ||
IFn require = Clojure.var("clojure.core", "require"); | ||
require.invoke(Clojure.read("io.factorhouse.kpow.agent")); | ||
IFn agentFn = Clojure.var("io.factorhouse.kpow.agent", "init-registry"); | ||
require.invoke(Clojure.read("io.factorhouse.kpow.serdes")); | ||
IFn serdesFn = Clojure.var("io.factorhouse.kpow.serdes", "transit-json-serializer"); | ||
Serializer keySerializer = (Serializer) serdesFn.invoke(); | ||
Serializer valSerializer = (Serializer) serdesFn.invoke(); | ||
Properties producerProps = filterProperties(props); | ||
KafkaProducer producer = new KafkaProducer<>(producerProps, keySerializer, valSerializer); | ||
agent = agentFn.invoke(producer); | ||
} | ||
|
||
public StreamsAgent register(KafkaStreams streams, Topology topology) { | ||
IFn require = Clojure.var("clojure.core", "require"); | ||
require.invoke(Clojure.read("io.factorhouse.kpow.agent")); | ||
IFn registerFn = Clojure.var("io.factorhouse.kpow.agent", "register"); | ||
String id = (String) registerFn.invoke(agent, streams, topology); | ||
if (id != null) { | ||
return new StreamsAgent(id); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
public void unregister(StreamsAgent streamsAgent) { | ||
if (streamsAgent != null) { | ||
IFn require = Clojure.var("clojure.core", "require"); | ||
require.invoke(Clojure.read("io.factorhouse.kpow.agent")); | ||
IFn unregisterFn = Clojure.var("io.factorhouse.kpow.agent", "unregister"); | ||
unregisterFn.invoke(agent, streamsAgent.getId()); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
IFn require = Clojure.var("clojure.core", "require"); | ||
require.invoke(Clojure.read("io.factorhouse.kpow.agent")); | ||
IFn closeFn = Clojure.var("io.factorhouse.kpow.agent", "close-registry"); | ||
closeFn.invoke(agent); | ||
} | ||
} |
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
Oops, something went wrong.