我在ApacheIgnite中有一个分布式数据库和一个ApacheKafka流服务,它将数据流传输到ignite集群。Kafka拖缆的工作原理如下
创建ignite节点以查找群集
在集群中启动kafka streamer singleton作为服务
关闭ignite节点
ignite集群处于事务模式,但是我不确定这是保证acid还是只启用acid。这个流媒体服务点燃可以被认为是酸?
以下是Kafka拖缆的代码:
public class IgniteKafkaStreamerService implements Service {
private static final long serialVersionUID = 1L;
@IgniteInstanceResource
private Ignite ignite;
private KafkaStreamer<String, JSONObject> kafkaStreamer = new KafkaStreamer<>();
private IgniteLogger logger;
public static void main(String[] args) throws InterruptedException {
TcpDiscoverySpi spi = new TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
// Set Multicast group.
//ipFinder.setMulticastGroup("228.10.10.157");
// Set initial IP addresses.
// Note that you can optionally specify a port or a port range.
ipFinder.setAddresses(Arrays.asList("127.0.0.1:47500..47509"));
spi.setIpFinder(ipFinder);
IgniteConfiguration cfg = new IgniteConfiguration();
// Override default discovery SPI.
cfg.setDiscoverySpi(spi);
Ignite ignite = Ignition.getOrStart(cfg);
// Deploy data streamer service on the server nodes.
ClusterGroup forServers = ignite.cluster().forServers();
IgniteKafkaStreamerService streamer = new IgniteKafkaStreamerService();
ignite.services(forServers).deployClusterSingleton("KafkaService", streamer);
ignite.close();
}
@Override
public void init(ServiceContext ctx) {
logger = ignite.log();
IgniteDataStreamer<String, JSONObject> stmr = ignite.dataStreamer("my_cache");
stmr.allowOverwrite(true);
stmr.autoFlushFrequency(1000);
List<String> topics = new ArrayList<>();
topics.add(0,"IoTData");
kafkaStreamer.setIgnite(ignite);
kafkaStreamer.setStreamer(stmr);
kafkaStreamer.setThreads(4);
kafkaStreamer.setTopic(topics);
Properties props = new Properties();
props.put(StreamsConfig.APPLICATION_ID_CONFIG, "NiFi-consumer");
props.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "192.168.1.242:9092");
props.put("key.deserializer", StringDeserializer.class.getName());
props.put("value.deserializer", StringDeserializer.class.getName());
props.put("group.id", "hello");
kafkaStreamer.setConsumerConfig(props);
kafkaStreamer.setSingleTupleExtractor(msg -> {
JSONObject jsonObj = new JSONObject(msg.value().toString());
String key = jsonObj.getString("id") + "," + new Date(msg.timestamp());
JSONObject value = jsonObj.accumulate("date", new Date(msg.timestamp()));
return new AbstractMap.SimpleEntry<>(key, value);
});
}
@Override
public void execute(ServiceContext ctx) {
kafkaStreamer.start();
logger.info("KafkaStreamer started.");
}
@Override
public void cancel(ServiceContext ctx) {
kafkaStreamer.stop();
logger.info("KafkaStreamer stopped.");
}
}
1条答案
按热度按时间nkhmeac61#
KafkaStreamer
使用IgniteDataStreamer
在引擎盖下面。IgniteDataStreamer
本质上不是事务性的,因此没有任何事务性保证。