Skip to content

Instantly share code, notes, and snippets.

@harishb2k
Last active October 6, 2022 12:58
Show Gist options
  • Select an option

  • Save harishb2k/a8241f13e13c116e1b4d0525bc1290ab to your computer and use it in GitHub Desktop.

Select an option

Save harishb2k/a8241f13e13c116e1b4d0525bc1290ab to your computer and use it in GitHub Desktop.

Revisions

  1. harishb2k revised this gist Oct 6, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Messaging_Properties-Kafka_String_Boot_Integration.md
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ messaging.producers.updateUserEvent.brokers: localhost:9092
    messaging.producers.updateUserEvent.sync: true
    messaging.producers.updateUserEvent.enableCircuitBreakerOnError: true
    messaging.producers.updateUserEvent.request-timeout-ms: 100
    messaging.producers.updateUserEvent.ack: 1
    messaging.producers.updateUserEvent.ack: all
    messaging.producers.updateUserEvent.circuit-breaker-stay_in_open_state_on_error-ms: 10000
    ```

  2. harishb2k revised this gist Sep 22, 2022. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions Messaging_Properties-Kafka_String_Boot_Integration.md
    Original file line number Diff line number Diff line change
    @@ -6,11 +6,14 @@ messaging.producers.updateUserEvent.topic: topic_123
    messaging.producers.updateUserEvent.brokers: localhost:9092
    messaging.producers.updateUserEvent.sync: true
    messaging.producers.updateUserEvent.enableCircuitBreakerOnError: true
    messaging.producers.updateUserEvent.request_timeout_ms: 100
    messaging.producers.updateUserEvent.request-timeout-ms: 100
    messaging.producers.updateUserEvent.ack: 1
    messaging.producers.updateUserEvent.circuit-breaker.stay_in_open_state_on_error.ms: 10000
    messaging.producers.updateUserEvent.circuit-breaker-stay_in_open_state_on_error-ms: 10000
    ```

    Note you can use other kafka properties e.g. linger.ms or batch.size. Since this is a property file use "-" instead of "." for
    kafka properties e.g. Kafka property is "request.timeout.ms" but in config you must have "request-timeout-ms"

    What is ```enableCircuitBreakerOnError``` setting?
    Suppose you have some error in your kafka setup. Setting ```enableCircuitBreakerOnError=true``` will open a circuit (circuit breaker) and will ensure your service does not fail.
    Please note - when circuit is open, messages are dropped to ensure application resiliency(standard circiut breaker approch)
  3. harishb2k revised this gist Sep 22, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Messaging_Properties-Kafka_String_Boot_Integration.md
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ messaging.producers.updateUserEvent.topic: topic_123
    messaging.producers.updateUserEvent.brokers: localhost:9092
    messaging.producers.updateUserEvent.sync: true
    messaging.producers.updateUserEvent.enableCircuitBreakerOnError: true
    messaging.producers.updateUserEvent.request.timeout.ms: 100
    messaging.producers.updateUserEvent.request_timeout_ms: 100
    messaging.producers.updateUserEvent.ack: 1
    messaging.producers.updateUserEvent.circuit-breaker.stay_in_open_state_on_error.ms: 10000
    ```
  4. harishb2k revised this gist Jul 8, 2022. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion Messaging_Properties-Kafka_String_Boot_Integration.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    ```
    # Messaging to send events to update user event
    # Update the Kafka and topic name for your own setup
    messaging.producers.updateUserEvent.enabled: true
    messaging.producers.updateUserEvent.topic: topic_123
    messaging.producers.updateUserEvent.brokers: localhost:9092
    @@ -8,4 +9,10 @@ messaging.producers.updateUserEvent.enableCircuitBreakerOnError: true
    messaging.producers.updateUserEvent.request.timeout.ms: 100
    messaging.producers.updateUserEvent.ack: 1
    messaging.producers.updateUserEvent.circuit-breaker.stay_in_open_state_on_error.ms: 10000
    ```
    ```

    What is ```enableCircuitBreakerOnError``` setting?
    Suppose you have some error in your kafka setup. Setting ```enableCircuitBreakerOnError=true``` will open a circuit (circuit breaker) and will ensure your service does not fail.
    Please note - when circuit is open, messages are dropped to ensure application resiliency(standard circiut breaker approch)

    Use ```circuit-breaker.stay_in_open_state_on_error.ms``` to specify how long circuit will remain open, before retrying.
  5. harishb2k renamed this gist Jul 8, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. harishb2k revised this gist Jul 8, 2022. 1 changed file with 44 additions and 0 deletions.
    44 changes: 44 additions & 0 deletions MessagingConfigurationBeanFactory.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    ```java
    import io.gitbub.devlibx.easy.helper.metrics.IMetrics;
    import io.gitbub.devlibx.easy.helper.string.StringHelper;
    import io.github.devlibx.easy.messaging.config.MessagingConfigs;
    import io.github.devlibx.easy.messaging.consumer.IConsumerService;
    import io.github.devlibx.easy.messaging.kafka.consumer.KafkaBasedConsumerService;
    import io.github.devlibx.easy.messaging.kafka.producer.KafkaBasedProducerService;
    import io.github.devlibx.easy.messaging.producer.IProducerService;
    import io.github.devlibx.easy.messaging.service.IMessagingFactory;
    import io.github.devlibx.easy.messaging.service.MessageFactory;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.stereotype.Service;

    import java.util.HashMap;
    import java.util.Map;

    @Configuration
    public class MessagingConfigurationBeanFactory {

    @Bean
    public StringHelper stringHelper() {
    return new StringHelper();
    }

    @Bean
    public IMetrics metrics() {
    return new IMetrics.NoOpMetrics();
    }

    @Bean
    @Autowired
    public IMessagingFactory messagingFactory(MessagingConfigs messagingConfigs, StringHelper stringHelper, IMetrics metrics) {
    Map<String, IProducerService> producerServiceMap = new HashMap<>();
    producerServiceMap.put("KAFKA", new KafkaBasedProducerService(stringHelper, metrics));
    Map<String, IConsumerService> consumerServiceMap = new HashMap<>();
    consumerServiceMap.put("KAFKA", new KafkaBasedConsumerService(metrics));
    IMessagingFactory messagingFactory = new MessageFactory(producerServiceMap, consumerServiceMap, messagingConfigs);
    messagingFactory.initialize();
    return messagingFactory;
    }
    }
    ```
  7. harishb2k revised this gist Jul 8, 2022. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions MessagingConfigs.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    ```java
    import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
    import lombok.Getter;
    import lombok.NoArgsConstructor;
    import lombok.Setter;
    import org.springframework.boot.context.properties.ConfigurationProperties;
    import org.springframework.context.annotation.Configuration;

    @Getter
    @Setter
    @NoArgsConstructor
    @JsonIgnoreProperties(ignoreUnknown = true)
    @Configuration
    @ConfigurationProperties(prefix = "messaging")
    public class MessagingConfigs extends io.github.devlibx.easy.messaging.config.MessagingConfigs {
    }
    ```
  8. harishb2k created this gist Jul 8, 2022.
    11 changes: 11 additions & 0 deletions Messaging_Properties-Kafka_String_Boot_Integration.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    ```
    # Messaging to send events to update user event
    messaging.producers.updateUserEvent.enabled: true
    messaging.producers.updateUserEvent.topic: topic_123
    messaging.producers.updateUserEvent.brokers: localhost:9092
    messaging.producers.updateUserEvent.sync: true
    messaging.producers.updateUserEvent.enableCircuitBreakerOnError: true
    messaging.producers.updateUserEvent.request.timeout.ms: 100
    messaging.producers.updateUserEvent.ack: 1
    messaging.producers.updateUserEvent.circuit-breaker.stay_in_open_state_on_error.ms: 10000
    ```