Сообщения

Masking info before logging in Slf4G

  package az.kapitalbank.integration.asanfinance.logging; import com.fasterxml.jackson.core.JsonStreamContext; import net.logstash.logback.mask.ValueMasker; import org.apache.commons.lang3.StringUtils; import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CustomLogFieldMasker implements ValueMasker { private Pattern messagePattern ; private Pattern panPattern ; public void setMessageProperty (String messageProperty) { this . messagePattern = buildPattern(messageProperty); } public void setPanProperty (String panProperty) { this . panPattern = buildPattern(panProperty); } private Pattern buildPattern (String pattern) { return StringUtils. isEmpty (pattern) ? null : Pattern. compile (pattern, Pattern. MULTILINE ); } @Override public Object mask (JsonStreamContext context, Object value) { if (Objects. isNull (value)) { return null ; } if ...

Strategy Design Pattern

package org.example; public interface Strategy { void actionCommand (); } package org.example; public class AggressiveStrategy implements Strategy { @Override public void actionCommand () { System. out .println( "Aggressive strategy. Find and kill opponent." ); } } package org.example; public class DefensiveStrategy implements Strategy { @Override public void actionCommand () { System. out .println( "Defensive strategy. Protect self and teammates." ); } } package org.example; public class Player { Strategy strategy ; String type ; public Player (String type) { this . type = type; } public void setStrategy (Strategy strategy) { this . strategy = strategy; } public void action () { System. out .println( "Player: " + this . type ); strategy .actionCommand(); } }   Another example: package org.example.example2; public interface PaymentStrategy { void...

Kafka

Изображение
 1. Create topic. Go to bin folder in kafka: kafka-topics.sh --create --topic test --bootstrap-server localhost:19092 --replication-factor 1 --partitions 1 2. Describe topic. Get information about topic: kafka-topics.sh --describe --topic test --bootstrap-server localhost:19092 3. Produce message: kafka-console-producer.sh --topic test --bootstrap-server localhost:19092 4. Consume message: kafka-console-consumer.sh --topic test --bootstrap-server localhost:19092 --from-beginning *  Keep in mind that the number of  partitions for a topic can only be increased, never decreased. *  KafkaProducer has two types of errors. Retriable errors are those that can be resolved by sending the message again. For example, a connection error can be resolved because the connection may get reestablished. A “no leader” error can be resolved when a new leader is elected for the partition. KafkaProducer can be configured to retry those errors automatically, so the application code will ...