Merge branch 'eugenp:master' into master
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>akka-modules</artifactId>
|
||||
<name>akka-modules</name>
|
||||
<packaging>pom</packaging>
|
||||
<name>akka-modules</name>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
|
||||
@@ -12,4 +12,6 @@
|
||||
- [Count the Number of Unique Digits in an Integer using Java](https://www.baeldung.com/java-int-count-unique-digits)
|
||||
- [Generate Juggler Sequence in Java](https://www.baeldung.com/java-generate-juggler-sequence)
|
||||
- [Finding the Parent of a Node in a Binary Search Tree with Java](https://www.baeldung.com/java-find-parent-node-binary-search-tree)
|
||||
- [Check if a Number Is a Happy Number in Java](https://www.baeldung.com/java-happy-sad-number-test)
|
||||
- [Find the Largest Number Possible After Removing k Digits of a Number](https://www.baeldung.com/java-find-largest-number-remove-k-digits)
|
||||
- More articles: [[<-- prev]](/algorithms-miscellaneous-6)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>algorithms-miscellaneous-8</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>algorithms-miscellaneous-8</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>algorithms-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
</project>
|
||||
+19
-6
@@ -24,17 +24,17 @@ public class VigenereCipherUnitTest {
|
||||
@Test
|
||||
void encodeArticleTitle() {
|
||||
VigenereCipher cipher = new VigenereCipher();
|
||||
String output = cipher.encode("VEGENERE CIPHER IN JAVA", "BAELDUNG");
|
||||
String output = cipher.encode("VIGENERE CIPHER IN JAVA", "BAELDUNG");
|
||||
|
||||
Assertions.assertEquals("XFLQRZFL EJUTIM WU LBAM", output);
|
||||
Assertions.assertEquals("XJLQRZFL EJUTIM WU LBAM", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
void encodeArticleTitleMoreCharacters() {
|
||||
VigenereCipher cipher = new VigenereCipher("ABCDEFGHIJKLMNOPQRSTUVWXYZ ");
|
||||
String output = cipher.encode("VEGENERE CIPHER IN JAVA", "BAELDUNG");
|
||||
String output = cipher.encode("VIGENERE CIPHER IN JAVA", "BAELDUNG");
|
||||
|
||||
Assertions.assertEquals("XFLQRZELBDNALZEGKOEVEPO", output);
|
||||
Assertions.assertEquals("XJLQRZELBDNALZEGKOEVEPO", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,8 +56,21 @@ public class VigenereCipherUnitTest {
|
||||
@Test
|
||||
void decodeArticleTitleMoreCharacters() {
|
||||
VigenereCipher cipher = new VigenereCipher("ABCDEFGHIJKLMNOPQRSTUVWXYZ ");
|
||||
String output = cipher.decode("XFLQRZELBDNALZEGKOEVEPO", "BAELDUNG");
|
||||
String output = cipher.decode("XJLQRZELBDNALZEGKOEVEPO", "BAELDUNG");
|
||||
|
||||
Assertions.assertEquals("VEGENERE CIPHER IN JAVA", output);
|
||||
Assertions.assertEquals("VIGENERE CIPHER IN JAVA", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
void encodeDecodeBaeldung() {
|
||||
VigenereCipher cipher = new VigenereCipher();
|
||||
|
||||
String input = "BAELDUNG";
|
||||
String key = "HELLO";
|
||||
|
||||
String encoded = cipher.encode(input, key);
|
||||
String decoded = cipher.decode(encoded, key);
|
||||
|
||||
Assertions.assertEquals(input, decoded);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@
|
||||
<module>algorithms-miscellaneous-5</module>
|
||||
<module>algorithms-miscellaneous-6</module>
|
||||
<module>algorithms-miscellaneous-7</module>
|
||||
<module>algorithms-miscellaneous-8</module>
|
||||
<module>algorithms-searching</module>
|
||||
<module>algorithms-sorting</module>
|
||||
<module>algorithms-sorting-2</module>
|
||||
@@ -34,4 +35,4 @@
|
||||
<tradukisto.version>1.0.1</tradukisto.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cxf-spring</artifactId>
|
||||
<name>cxf-spring</name>
|
||||
<packaging>war</packaging>
|
||||
<name>cxf-spring</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -5,8 +5,9 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>apache-cxf-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>apache-cxf-modules</name>
|
||||
<packaging>pom</packaging>
|
||||
<name>apache-cxf-modules</name>
|
||||
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>sse-jaxrs</artifactId>
|
||||
<name>sse-jaxrs</name>
|
||||
<packaging>pom</packaging>
|
||||
<name>sse-jaxrs</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>sse-jaxrs-server</artifactId>
|
||||
<name>sse-jaxrs-server</name>
|
||||
<packaging>war</packaging>
|
||||
<name>sse-jaxrs-server</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>apache-httpclient4</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<name>apache-httpclient4</name>
|
||||
<packaging>war</packaging>
|
||||
<name>apache-httpclient4</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
@@ -193,7 +193,6 @@
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
## Apache Kafka
|
||||
|
||||
This module contains articles about Apache Kafka.
|
||||
|
||||
##### Building the project
|
||||
You can build the project from the command line using: *mvn clean install*, or in an IDE.
|
||||
|
||||
### Relevant Articles:
|
||||
- [Commit Offsets in Kafka](https://www.baeldung.com/kafka-commit-offsets)
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>apache-kafka-3</artifactId>
|
||||
<name>apache-kafka-3</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.kafka</groupId>
|
||||
<artifactId>kafka-clients</artifactId>
|
||||
<version>${kafka.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.databind.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<kafka.version>3.6.1</kafka.version>
|
||||
<jackson.databind.version>2.15.2</jackson.databind.version>
|
||||
</properties>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>integration-jdk9-and-above</id>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.kafka.commitoffset;
|
||||
|
||||
import com.baeldung.kafka.commitoffset.config.KafkaConfigProperties;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
|
||||
public class AsyncCommit {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
KafkaConsumer<Long, String> consumer = new KafkaConsumer<>(KafkaConfigProperties.getProperties());
|
||||
consumer.subscribe(KafkaConfigProperties.getTopic());
|
||||
ConsumerRecords<Long, String> messages = consumer.poll(Duration.ofSeconds(10));
|
||||
for (ConsumerRecord<Long, String> message : messages) {
|
||||
// processed message
|
||||
consumer.commitAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.baeldung.kafka.commitoffset;
|
||||
|
||||
import com.baeldung.kafka.commitoffset.config.KafkaConfigProperties;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
|
||||
public class AutomaticCommit {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Properties properties = KafkaConfigProperties.getProperties();
|
||||
properties.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "true");
|
||||
KafkaConsumer<Long, String> consumer = new KafkaConsumer<>(properties);
|
||||
consumer.subscribe(KafkaConfigProperties.getTopic());
|
||||
ConsumerRecords<Long, String> messages = consumer.poll(Duration.ofSeconds(10));
|
||||
for (ConsumerRecord<Long, String> message : messages) {
|
||||
// processed message
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.kafka.commitoffset;
|
||||
|
||||
import com.baeldung.kafka.commitoffset.config.KafkaConfigProperties;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
import org.apache.kafka.clients.consumer.OffsetAndMetadata;
|
||||
import org.apache.kafka.common.TopicPartition;
|
||||
|
||||
public class SpecificOffsetCommit {
|
||||
public static void main(String[] args) {
|
||||
|
||||
KafkaConsumer<Long, String> consumer = new KafkaConsumer<>(KafkaConfigProperties.getProperties());
|
||||
consumer.subscribe(KafkaConfigProperties.getTopic());
|
||||
Map<TopicPartition, OffsetAndMetadata> currentOffsets = new HashMap<>();
|
||||
int messageProcessed = 0;
|
||||
while (true) {
|
||||
ConsumerRecords<Long, String> messages = consumer.poll(Duration.ofSeconds(10));
|
||||
for (ConsumerRecord<Long, String> message : messages) {
|
||||
// processed message
|
||||
messageProcessed++;
|
||||
currentOffsets.put(new TopicPartition(message.topic(), message.partition()), new OffsetAndMetadata(message.offset() + 1));
|
||||
if (messageProcessed % 50 == 0) {
|
||||
consumer.commitSync(currentOffsets);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.kafka.commitoffset;
|
||||
|
||||
import com.baeldung.kafka.commitoffset.config.KafkaConfigProperties;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecords;
|
||||
import org.apache.kafka.clients.consumer.KafkaConsumer;
|
||||
|
||||
public class SyncCommit {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
KafkaConsumer<Long, String> consumer = new KafkaConsumer<>(KafkaConfigProperties.getProperties());
|
||||
consumer.subscribe(KafkaConfigProperties.getTopic());
|
||||
ConsumerRecords<Long, String> messages = consumer.poll(Duration.ofSeconds(10));
|
||||
for (ConsumerRecord<Long, String> message : messages) {
|
||||
// processed message
|
||||
consumer.commitSync();
|
||||
}
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.baeldung.kafka.commitoffset.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.kafka.clients.consumer.ConsumerConfig;
|
||||
import org.apache.kafka.common.serialization.StringDeserializer;
|
||||
|
||||
/**
|
||||
* @author amitkumar
|
||||
*/
|
||||
public class KafkaConfigProperties {
|
||||
public static final String MY_TOPIC = "my-topic";
|
||||
|
||||
public static Properties getProperties() {
|
||||
|
||||
Properties props = new Properties();
|
||||
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false");
|
||||
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
|
||||
props.put(ConsumerConfig.GROUP_ID_CONFIG, "MyFirstConsumer");
|
||||
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
|
||||
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
|
||||
return props;
|
||||
}
|
||||
|
||||
public static ArrayList<String> getTopic() {
|
||||
ArrayList<String> topics = new ArrayList<>();
|
||||
topics.add(MY_TOPIC);
|
||||
return topics;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
||||
@@ -24,14 +24,12 @@
|
||||
<artifactId>camel-core</artifactId>
|
||||
<version>${camel.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-test-junit5</artifactId>
|
||||
<version>${camel.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-main</artifactId>
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>apache-spark</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>apache-spark</name>
|
||||
<packaging>jar</packaging>
|
||||
<name>apache-spark</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>apache-thrift</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>apache-thrift</name>
|
||||
<packaging>pom</packaging>
|
||||
<name>apache-thrift</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>apache-velocity</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<name>apache-velocity</name>
|
||||
<packaging>war</packaging>
|
||||
<name>apache-velocity</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>aws-dynamodb</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>aws-dynamodb</name>
|
||||
<packaging>jar</packaging>
|
||||
<name>aws-dynamodb</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>lambda-function</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>lambda-function</name>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>aws-lambda-modules</artifactId>
|
||||
<name>aws-lambda-modules</name>
|
||||
<packaging>pom</packaging>
|
||||
<name>aws-lambda-modules</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>ShippingFunction</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>ShippingFunction</name>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>helloworld</groupId>
|
||||
<artifactId>ToDoFunction</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>ToDoFunction</name>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>aws-miscellaneous</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>aws-miscellaneous</name>
|
||||
<packaging>jar</packaging>
|
||||
<name>aws-miscellaneous</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>aws-s3</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>aws-s3</name>
|
||||
<packaging>jar</packaging>
|
||||
<name>aws-s3</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
@@ -26,7 +26,6 @@
|
||||
<version>${aws.java.sdk.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
@@ -56,7 +55,6 @@
|
||||
<version>${com.adobe.testing.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user