Newsletter – Week 23, 2017

News:

Articles:

Videos:

Newsletter – Week 22, 2017

News:

Articles:

Videos:

Calculate the number of days between two dates

The issues with date and time processing in old versions of Java led many developers to use tricky workarounds or third-party libraries like Joda-Time for that.

Oracle in collaboration with Stephen Colebourne introduced the implementation of JSR 310: Date and Time API in Java SE 1.8.  The new date and time API with dramatically improved safety and functionality.  Nevertheless,  developers still use old approaches for date and time processing even using Java 1.8 for development ignoring all improvements provided there out of the box.

This is one of the many real cases when you have two dates and should calculate the number of days between these dates. The small examples below illustrate how it can be solved in case of using new API provided by Java1.8

Firstly, how it might be implemented using Java 1.7:

and the same implementation using Java 1.8:

For dates with time it can be solved in a similar manner using new API:

If you want to know more about new date and time processing API – here the links to the official documentation:

http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html

https://docs.oracle.com/javase/tutorial/datetime/iso/index.html

Newsletter – Week 21, 2017

News:

Articles:

Videos:

Useful Apache Kafka Console Commands

Parameters used:

Parameter Comment
zookeeper_host the list of Zookeeper nodes in cluster
topic_name the topic name
broker_list the list of Kafka brokers in cluster
replication_factor the replication factor for topic
partition_count the number of partitions for topic

Topic management:

  • create a topic:

bin/kafka-topics.sh –create –zookeeper [zookeeper_list] –replication-factor [replication_factor] –partitions [partition_count] –topic [topic_name]

Example:

>bin/kafka-topics.sh –create –zookeeper zookeeeper_nd1:2181,zookeeper_nd2:2181,zookeeper_nd3:2181 –replication-factor 1  –partitions 3 –topic TestKafkaTopicName

  • view list of topics

bin/kafka-topics.sh –list –zookeeper [zookeeper_list]

Example:

>bin/kafka-topics.sh –list –zookeeper zookeeeper_nd1:2181,zookeeper_nd2:2181,zookeeper_nd3:2181

  • describe a topic

bin/kafka-topics.sh –describe –zookeeper [zookeeper_list] –topic [topic_name]

Example:

>bin/kafka-topics.sh –describe –zookeeper zookeeeper_nd1:2181,zookeeper_nd2:2181,zookeeper_nd3:2181 –topic TestKafkaTopicName

Messaging:

  • produce a message to Kafka

bin/kafka-console-producer.sh –broker-list [broker_list] –topic [topic_name]

Example:

>bin/kafka-console-producer.sh  –broker-list kafka_nd1:6667,kafka_nd2:6667,kafka_nd3:6667 –topic TestKafkaTopicName

Note: you have to be extremely accurate when sending a message to Kafka from console because the message might be in incorrect format that would break the consumer logic.

  • consume all messages from Kafka topic (old ones and new arriving)

bin/kafka-console-consumer.sh –zookeeper [zookeeper_list] –topic [topic_name] –from-beginning

Example:

>bin/kafka-console-consumer.sh –zookeeper zookeeeper_nd1:2181,zookeeper_nd2:2181,zookeeper_nd3:2181 –topic TestKafkaTopicName

  • consume  the messages arriving in Kafka topic

bin/kafka-console-consumer.sh –zookeeper [zookeeper_list] –topic [topic_name] –from-beginning

Example:

>bin/kafka-console-consumer.sh –zookeeper zookeeeper_nd1:2181,zookeeper_nd2:2181,zookeeper_nd3:2181 –topic TestKafkaTopicName

Newsletter – Week 20, 2017

News:

Articles:

Videos:

Newsletter – Week 19, 2017

News:

Articles:

Videos:

Newsletter – Week 18, 2017

News:

Articles:

Videos:

Newsletter – Week 17, 2017

News:

Articles:

Videos: