nstream.adapter.nats.NatsConsumerConfLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nstream-adapter-nats Show documentation
Show all versions of nstream-adapter-nats Show documentation
Templates for consuming from and producing to NATS with Swim
//package nstream.adapter.nats;
//
//import io.nats.client.api.AckPolicy;
//import io.nats.client.api.ConsumerConfiguration;
//import io.nats.client.api.DeliverPolicy;
//import io.nats.client.api.ReplayPolicy;
//import java.time.Duration;
//import java.time.ZonedDateTime;
//import java.util.HashMap;
//import java.util.Map;
//import java.util.Properties;
//import java.util.Set;
//import java.util.SortedMap;
//import java.util.regex.Pattern;
//import static swim.util.Severity.warning;
//
//public final class NatsConsumerConfLoader {
//
// // TODO: Check and keep only Pull based options
// private static final Map> KNOWN_FIELDS = Map.ofEntries(
// Map.entry("deliverPolicy", DeliverPolicy.class),
// Map.entry("startSequence", Long.TYPE),
// Map.entry("startTime", ZonedDateTime.class),
// Map.entry("ackPolicy", AckPolicy.class),
// Map.entry("ackWait", Long.TYPE),
// Map.entry("maxAckPending", Long.TYPE),
// Map.entry("replayPolicy", ReplayPolicy.class),
// Map.entry("maxDeliver", Long.TYPE),
// Map.entry("filterSubject", String.class),
// Map.entry("rateLimit", Long.TYPE),
// Map.entry("sampleFrequency", String.class),
// Map.entry("idleHeartbeat", Long.TYPE),
// Map.entry("flowControl", Long.TYPE)
// );
//
// private NatsConsumerConfLoader() {
// }
//
// private static void updateMap(String name, String value, Map result) {
// if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) {
// result.put(name, Boolean.parseBoolean(value));
// warning("[WARN] NatsConsumerConfLoader treated unknown property " + name + " as boolean");
// } else {
// try {
// result.put(name, Long.parseLong(value));
// warning("[WARN] NatsConsumerConfLoader treated unknown property " + name + " as long");
// } catch (Exception e1) {
// result.put(name, value);
// warning("[WARN] NatsConsumerConfLoader treated unknown property " + name + " as String");
// }
// }
// }
//
// public static ConsumerConfiguration toLoadableConf(Properties properties) {
//
// final ConsumerConfiguration.Builder ccBuilder = ConsumerConfiguration.builder();
//
// final Map result = new HashMap<>(properties.size());
// properties.forEach((k, v) -> {
// final String name = k.toString();
// final String value = v.toString();
// if (KNOWN_FIELDS.containsKey(name)) {
// updateMap(name, value, KNOWN_FIELDS.get(name), result);
// } else {
// updateMap(name, value, result);
// }
// });
//
// // Dynamically apply configuration values
// result.forEach((key, value) -> {
// switch (key) {
// case "deliverPolicy":
// ccBuilder.deliverPolicy((DeliverPolicy) value);
// break;
// case "ackPolicy":
// ccBuilder.ackPolicy((AckPolicy) value);
// break;
// case "replayPolicy":
// ccBuilder.replayPolicy((ReplayPolicy) value);
// break;
// case "startSequence":
// ccBuilder.startSequence((Long) value);
// break;
// case "startTime":
// ccBuilder.startTime(((ZonedDateTime) value));
// break;
// case "ackWait":
// ccBuilder.ackWait(Duration.ofMillis((Long) value));
// break;
// case "idleHeartbeat":
// ccBuilder.idleHeartbeat(Duration.ofMillis((Long) value));
// break;
// case "maxAckPending":
// ccBuilder.maxAckPending(((Long) value).intValue()); // Note the conversion to int
// break;
// case "maxDeliver":
// ccBuilder.maxDeliver(((Long) value).intValue());
// break;
// case "filterSubject":
// ccBuilder.filterSubject((String) value);
// break;
// case "rateLimit":
// ccBuilder.rateLimit((Long) value);
// break;
// case "sampleFrequency":
// ccBuilder.sampleFrequency((String) value);
// break;
// case "flowControl":
// ccBuilder.flowControl(Duration.ofMillis((Long) value));
// break;
// }
// });
//
// return ccBuilder.build();
// }
//
// private static void updateMap(String name, String value, Class> knownClass,
// Map result) {
// if (knownClass == String.class) {
// result.put(name, value);
// } else if (knownClass == Integer.TYPE) {
// result.put(name, Integer.parseInt(value));
// } else if (knownClass == Long.TYPE) {
// result.put(name, Long.parseLong(value));
// } else if (knownClass == Boolean.TYPE) {
// result.put(name, Boolean.parseBoolean(value));
// } else if (knownClass == Set.class) {
// if (value != null && !value.isEmpty()) {
// result.put(name, Set.of(value.split(",")));
// }
// } else if (knownClass == Pattern.class) {
// result.put(name, Pattern.compile(value));
// } else if (knownClass == SortedMap.class) {
// throw new UnsupportedOperationException("not yet implemented");
// } else { // FIXME
// throw new UnsupportedOperationException("not yet implemented");
// }
// }
//}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy