Class KafkaChannelDefinitionProcessor

java.lang.Object
org.flowable.eventregistry.spring.kafka.KafkaChannelDefinitionProcessor
All Implemented Interfaces:
EventListener, org.flowable.eventregistry.api.ChannelModelProcessor, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.DisposableBean, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>

public class KafkaChannelDefinitionProcessor extends Object implements org.springframework.beans.factory.BeanFactoryAware, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>, org.springframework.beans.factory.DisposableBean, org.flowable.eventregistry.api.ChannelModelProcessor
A ChannelModelProcessor which is responsible for configuring Kafka Event registry integration. This class is not meant to be extended.
Author:
Filip Hrisafov
  • Field Details

    • CHANNEL_ID_PREFIX

      public static final String CHANNEL_ID_PREFIX
      See Also:
    • DEFAULT_PARTITION_FOR_MANUAL_ASSIGNMENT

      protected static final int DEFAULT_PARTITION_FOR_MANUAL_ASSIGNMENT
      See Also:
    • logger

      protected final org.slf4j.Logger logger
    • kafkaOperations

      protected org.springframework.kafka.core.KafkaOperations<Object,Object> kafkaOperations
    • kafkaAdminOperations

      protected org.springframework.kafka.core.KafkaAdminOperations kafkaAdminOperations
    • endpointRegistry

      protected org.springframework.kafka.config.KafkaListenerEndpointRegistry endpointRegistry
    • containerFactoryBeanName

      protected String containerFactoryBeanName
    • containerFactory

      protected org.springframework.kafka.config.KafkaListenerContainerFactory<?> containerFactory
    • retryTopicTaskScheduler

      protected org.springframework.scheduling.TaskScheduler retryTopicTaskScheduler
    • retryTopicThreadPoolTaskScheduler

      protected org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler retryTopicThreadPoolTaskScheduler
    • beanFactory

      protected org.springframework.beans.factory.BeanFactory beanFactory
    • applicationContext

      protected org.springframework.context.ApplicationContext applicationContext
    • contextRefreshed

      protected boolean contextRefreshed
    • objectMapper

      protected com.fasterxml.jackson.databind.ObjectMapper objectMapper
    • resolver

      protected org.springframework.beans.factory.config.BeanExpressionResolver resolver
    • embeddedValueResolver

      protected org.springframework.util.StringValueResolver embeddedValueResolver
    • expressionContext

      protected org.springframework.beans.factory.config.BeanExpressionContext expressionContext
    • retryEndpointsByMainEndpointId

      protected Map<String,Collection<String>> retryEndpointsByMainEndpointId
  • Constructor Details

    • KafkaChannelDefinitionProcessor

      public KafkaChannelDefinitionProcessor(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
  • Method Details

    • canProcess

      public boolean canProcess(org.flowable.eventregistry.model.ChannelModel channelModel)
      Specified by:
      canProcess in interface org.flowable.eventregistry.api.ChannelModelProcessor
    • canProcessIfChannelModelAlreadyRegistered

      public boolean canProcessIfChannelModelAlreadyRegistered(org.flowable.eventregistry.model.ChannelModel channelModel)
      Specified by:
      canProcessIfChannelModelAlreadyRegistered in interface org.flowable.eventregistry.api.ChannelModelProcessor
    • registerChannelModel

      public void registerChannelModel(org.flowable.eventregistry.model.ChannelModel channelModel, String tenantId, org.flowable.eventregistry.api.EventRegistry eventRegistry, org.flowable.eventregistry.api.EventRepositoryService eventRepositoryService, boolean fallbackToDefaultTenant)
      Specified by:
      registerChannelModel in interface org.flowable.eventregistry.api.ChannelModelProcessor
    • createKafkaListenerEndpoint

      protected org.springframework.kafka.config.KafkaListenerEndpoint createKafkaListenerEndpoint(org.flowable.eventregistry.model.KafkaInboundChannelModel channelModel, String tenantId, org.flowable.eventregistry.api.EventRegistry eventRegistry)
    • processAndRegisterEndpoints

      protected void processAndRegisterEndpoints(org.flowable.eventregistry.model.KafkaInboundChannelModel channelModel, String tenantId, org.flowable.eventregistry.api.EventRegistry eventRegistry)
    • createEndpointConfigurations

      protected Collection<KafkaChannelDefinitionProcessor.Configuration> createEndpointConfigurations(org.flowable.eventregistry.model.KafkaInboundChannelModel channelModel, String tenantId, org.flowable.eventregistry.api.EventRegistry eventRegistry, org.springframework.kafka.config.KafkaListenerEndpoint mainEndpoint, org.springframework.kafka.config.KafkaListenerContainerFactory<?> containerFactory)
    • getTopicPartitions

      protected static Collection<org.springframework.kafka.support.TopicPartitionOffset> getTopicPartitions(org.springframework.kafka.retrytopic.DestinationTopic.Properties properties, org.springframework.kafka.support.Suffixer suffixer, org.springframework.kafka.support.TopicPartitionOffset[] topicPartitionOffsets)
    • getTPOForRetryTopics

      protected static org.springframework.kafka.support.TopicPartitionOffset getTPOForRetryTopics(org.springframework.kafka.retrytopic.DestinationTopic.Properties properties, org.springframework.kafka.support.Suffixer suffixer, org.springframework.kafka.support.TopicPartitionOffset tpo)
    • getTPOForMainTopic

      protected static org.springframework.kafka.support.TopicPartitionOffset getTPOForMainTopic(org.springframework.kafka.support.Suffixer suffixer, org.springframework.kafka.support.TopicPartitionOffset tpo)
    • getTopicCreationFunction

      protected Consumer<Collection<String>> getTopicCreationFunction(KafkaChannelDefinitionProcessor.ResolvedRetryConfiguration retryConfiguration)
    • createNewTopics

      protected void createNewTopics(Collection<String> topics, int numPartitions, short replicationFactor)
    • createListenerContainerFactoryConfigurer

      protected org.springframework.kafka.retrytopic.ListenerContainerFactoryConfigurer createListenerContainerFactoryConfigurer(KafkaChannelDefinitionProcessor.ResolvedRetryConfiguration retryConfiguration, org.springframework.util.backoff.BackOff backOff, org.springframework.kafka.retrytopic.DefaultDestinationTopicResolver topicResolver)
    • configurePartitionPausingFactory

      protected void configurePartitionPausingFactory(org.springframework.kafka.listener.ContainerPartitionPausingBackOffManagerFactory factory)
    • getOrCreateRetryTopicTaskScheduler

      protected org.springframework.scheduling.TaskScheduler getOrCreateRetryTopicTaskScheduler()
    • decorateFactory

      protected org.springframework.kafka.config.KafkaListenerContainerFactory<?> decorateFactory(org.springframework.kafka.retrytopic.DestinationTopic.Properties destinationTopicProperties, org.springframework.kafka.retrytopic.ListenerContainerFactoryConfigurer factoryConfigurer, org.springframework.kafka.retrytopic.RetryTopicConfiguration retryTopicConfiguration)
    • processOutboundDefinition

      protected void processOutboundDefinition(org.flowable.eventregistry.model.KafkaOutboundChannelModel channelModel)
    • resolveExpressionAsInteger

      protected Integer resolveExpressionAsInteger(String value, String attribute)
    • resolveExpressionAsInteger

      protected Integer resolveExpressionAsInteger(String value, String attribute, Integer defaultValue)
    • resolveExpressionAsLong

      protected Long resolveExpressionAsLong(String value, String attribute)
    • resolveExpressionAsDouble

      protected Double resolveExpressionAsDouble(String value, String attribute)
    • resolveExpressionAsBoolean

      protected Boolean resolveExpressionAsBoolean(String value, String attribute)
    • resolveExpressionAsBoolean

      protected Boolean resolveExpressionAsBoolean(String value, String attribute, Boolean defaultValue)
    • resolveExpressionAsString

      protected String resolveExpressionAsString(String value, String attribute)
    • resolveTopics

      protected Collection<String> resolveTopics(org.flowable.eventregistry.model.KafkaInboundChannelModel channelDefinition)
    • resolveTopics

      protected void resolveTopics(Object resolvedValue, List<String> result, org.flowable.eventregistry.model.KafkaInboundChannelModel channelDefinition)
    • resolvePattern

      protected Pattern resolvePattern(org.flowable.eventregistry.model.KafkaInboundChannelModel channelModel)
    • resolveTopicPartitions

      protected Collection<org.springframework.kafka.support.TopicPartitionOffset> resolveTopicPartitions(org.flowable.eventregistry.model.KafkaInboundChannelModel channelModel)
    • resolvePartitionAsInteger

      protected void resolvePartitionAsInteger(String topic, Object resolvedValue, List<org.springframework.kafka.support.TopicPartitionOffset> result)
    • parsePartitions

      protected Stream<Integer> parsePartitions(String partsString)
      Parse a list of partitions into a List. Example: "0-5,10-15". This parsing is the same as it is done in the Spring KafkaListenerAnnotationBeanPostProcessor.
      Parameters:
      partsString - the comma-delimited list of partitions/ranges.
      Returns:
      the stream of partition numbers, sorted and de-duplicated.
    • resolveKafkaPartitionProvider

      protected KafkaPartitionProvider resolveKafkaPartitionProvider(org.flowable.eventregistry.model.KafkaOutboundChannelModel channelModel)
    • resolveExpression

      protected <T> T resolveExpression(String expression, Class<T> type)
    • resolveExpression

      protected Object resolveExpression(String value)
    • createMessageListener

      protected org.springframework.kafka.listener.GenericMessageListener<org.apache.kafka.clients.consumer.ConsumerRecord<Object,Object>> createMessageListener(org.flowable.eventregistry.api.EventRegistry eventRegistry, org.flowable.eventregistry.model.InboundChannelModel inboundChannelModel)
    • unregisterChannelModel

      public void unregisterChannelModel(org.flowable.eventregistry.model.ChannelModel channelModel, String tenantId, org.flowable.eventregistry.api.EventRepositoryService eventRepositoryService)
      Specified by:
      unregisterChannelModel in interface org.flowable.eventregistry.api.ChannelModelProcessor
    • unregisterEndpoint

      protected void unregisterEndpoint(String endpointId, org.flowable.eventregistry.model.ChannelModel channelModel, String tenantId)
    • registerEndpoint

      protected void registerEndpoint(org.springframework.kafka.config.KafkaListenerEndpoint endpoint, org.springframework.kafka.config.KafkaListenerContainerFactory<?> factory)
      Register a new KafkaListenerEndpoint alongside the KafkaListenerContainerFactory to use to create the underlying container.

      The factory may be null if the default factory has to be used for that endpoint.

    • resolveContainerFactory

      protected org.springframework.kafka.config.KafkaListenerContainerFactory<?> resolveContainerFactory(org.springframework.kafka.config.KafkaListenerEndpoint endpoint, org.springframework.kafka.config.KafkaListenerContainerFactory<?> containerFactory)
    • getEndpointId

      protected String getEndpointId(org.flowable.eventregistry.model.ChannelModel channelModel, String tenantId)
    • getEndpointGroupId

      protected String getEndpointGroupId(org.flowable.eventregistry.model.KafkaInboundChannelModel channelDefinition, String id)
    • resolve

      protected String resolve(String value)
    • resolveProperties

      protected Properties resolveProperties(List<org.flowable.eventregistry.model.KafkaInboundChannelModel.CustomProperty> consumerProperties)
    • setBeanFactory

      public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) throws org.springframework.beans.BeansException
      Specified by:
      setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
      Throws:
      org.springframework.beans.BeansException
    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • onApplicationEvent

      public void onApplicationEvent(org.springframework.context.event.ContextRefreshedEvent event)
      Specified by:
      onApplicationEvent in interface org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
    • destroy

      public void destroy() throws Exception
      Specified by:
      destroy in interface org.springframework.beans.factory.DisposableBean
      Throws:
      Exception
    • getKafkaOperations

      public org.springframework.kafka.core.KafkaOperations<Object,Object> getKafkaOperations()
    • setKafkaOperations

      public void setKafkaOperations(org.springframework.kafka.core.KafkaOperations<Object,Object> kafkaOperations)
    • getKafkaAdminOperations

      public org.springframework.kafka.core.KafkaAdminOperations getKafkaAdminOperations()
    • setKafkaAdminOperations

      public void setKafkaAdminOperations(org.springframework.kafka.core.KafkaAdminOperations kafkaAdminOperations)
    • getEndpointRegistry

      public org.springframework.kafka.config.KafkaListenerEndpointRegistry getEndpointRegistry()
    • setEndpointRegistry

      public void setEndpointRegistry(org.springframework.kafka.config.KafkaListenerEndpointRegistry endpointRegistry)
    • getContainerFactoryBeanName

      public String getContainerFactoryBeanName()
    • setContainerFactoryBeanName

      public void setContainerFactoryBeanName(String containerFactoryBeanName)
    • getContainerFactory

      public org.springframework.kafka.config.KafkaListenerContainerFactory<?> getContainerFactory()
    • setContainerFactory

      public void setContainerFactory(org.springframework.kafka.config.KafkaListenerContainerFactory<?> containerFactory)
    • getRetryTopicTaskScheduler

      public org.springframework.scheduling.TaskScheduler getRetryTopicTaskScheduler()
    • setRetryTopicTaskScheduler

      public void setRetryTopicTaskScheduler(org.springframework.scheduling.TaskScheduler retryTopicTaskScheduler)
    • createRetryTopicConfiguration

      protected org.springframework.kafka.retrytopic.RetryTopicConfiguration createRetryTopicConfiguration(KafkaChannelDefinitionProcessor.ResolvedRetryConfiguration retryConfiguration)
    • resolveRetryConfiguration

      protected KafkaChannelDefinitionProcessor.ResolvedRetryConfiguration resolveRetryConfiguration(org.flowable.eventregistry.model.KafkaInboundChannelModel channelModel)
    • createNonBlockingBackOffPolicy

      protected org.springframework.retry.backoff.SleepingBackOffPolicy<?> createNonBlockingBackOffPolicy(org.flowable.eventregistry.model.KafkaInboundChannelModel.NonBlockingRetryBackOff backOff)