I am working on Kafka Streams. I am facing the below issues:
Details about what I have done so far:
I created below topics, stream and tables:
./kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic bptcus
./kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic address-elasticsearch-sink
Created tables and stream for the above created topics.
CREATE table CUSTOMER_SRC (customerId VARCHAR,name VARCHAR, age VARCHAR, address VARCHAR) WITH (KAFKA_TOPIC='bptcus', VALUE_FORMAT='JSON', KEY='customerId');
CREATE stream ADDRESS_SRC (addressId VARCHAR, city VARCHAR, state VARCHAR) WITH (KAFKA_TOPIC='address-elasticsearch-sink', VALUE_FORMAT='JSON');
I am able to see the data as below:
select * from customer_src;
1528743137610 | Parent-1528743137047 | Ron | 31 | [{"addressId":"1","city":"Fremont","state":"CA"},{"addressId":"2","city":"Dallas","state":"TX"}]
select * from address_src;
1528743413826 | Parent-1528743137047 | 1 | Detroit | MI
Created another stream by joining the table and stream created above.
CREATE stream CUST_ADDR_SRC as select c.name , c.age , c.address, a.rowkey, a.addressId , a.city , a.state from ADDRESS_SRC a left join CUSTOMER_SRC c on c.rowkey=a.rowkey;
I am able to see the data in the CUST_ADDR_SRC stream as below:
select * from cust_addr_src;
1528743413826 | Parent-1528743137047 | Ron | 31 | [{"addressId":"1","city":"Fremont","state":"CA"},{"addressId":"2","city":"Dallas","state":"TX"}] | Parent-1528743137047 | 1 | Detroit | MI
My Questions:
- Now I want to replace the addressId 1(Fremont) by the addressId 1(Detroit). How can I do that?
- I also tried to print the stream input out to console as mentioned in the ticket
Print Kafka Stream Input out to console?
Here is my code:
Properties config = new Properties();
config.put(StreamsConfig.APPLICATION_ID_CONFIG, "cusadd-application");
config.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "10.1.61.125:9092");
config.put(StreamsConfig.ZOOKEEPER_CONNECT_CONFIG, "10.1.61.125:2181");
config.put(StreamsConfig.KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
config.put(StreamsConfig.VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass());
KStreamBuilder builder = new KStreamBuilder();
KStream<String, String> source = builder.stream("cust_addr_src");
source.foreach(new ForeachAction<String, String>() {
public void apply(String key, String value) {
System.out.println("Stream key values are: " + key + ": " + value);
}
});
I don't see the output.
Only, I can see the below output:
12:04:42.145 [StreamThread-1] DEBUG org.apache.kafka.clients.consumer.internals.Fetcher - Resetting offset for partition cust_addr_src-0 to latest offset. 12:04:42.145 [StreamThread-1] DEBUG org.apache.kafka.clients.NetworkClient - Initiating connection to node 0 at hsharma-mbp15.local:9092. 12:04:42.145 [StreamThread-1] DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name node-0.bytes-sent 12:04:42.145 [StreamThread-1] DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name node-0.bytes-received 12:04:42.145 [StreamThread-1] DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name node-0.latency 12:04:42.145 [StreamThread-1] DEBUG org.apache.kafka.clients.NetworkClient - Completed connection to node 0 12:04:42.145 [StreamThread-1] DEBUG org.apache.kafka.clients.consumer.internals.Fetcher - Fetched offset 0 for partition cust_addr_src-0 12:04:42.676 [StreamThread-1] DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name topic.cust_addr_src.bytes-fetched 12:04:42.680 [StreamThread-1] DEBUG org.apache.kafka.common.metrics.Metrics - Added sensor with name topic.cust_addr_src.records-fetched 12:04:45.150 [StreamThread-1] DEBUG org.apache.kafka.clients.consumer.internals.AbstractCoordinator - Received successful heartbeat response for group cusadd-application.
Thanks in advance.