use of io.splitet.core.kafka.PublishedEventWrapper in project eventapis by kloiasoft.
the class EventListenConfiguration method messageListenerContainer.
@Bean(name = "messageListenerContainer")
public ConcurrentMessageListenerContainer<String, PublishedEventWrapper> messageListenerContainer() {
Map<String, Object> consumerProperties = eventApisConfiguration.getEventBus().buildConsumerProperties();
consumerProperties.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
consumerProperties.put(ConsumerConfig.METADATA_MAX_AGE_CONFIG, 3000);
DefaultKafkaConsumerFactory<String, PublishedEventWrapper> consumerFactory = new DefaultKafkaConsumerFactory<>(consumerProperties, new StringDeserializer(), new JsonDeserializer<>(PublishedEventWrapper.class));
ContainerProperties containerProperties = new ContainerProperties(Pattern.compile(eventTopicRegexStr));
containerProperties.setMessageListener(new MultipleEventMessageListener(eventMessageListeners));
containerProperties.setAckMode(ContainerProperties.AckMode.BATCH);
ConcurrentMessageListenerContainer<String, PublishedEventWrapper> messageListenerContainer = new ConcurrentMessageListenerContainer<>(consumerFactory, containerProperties);
messageListenerContainer.setConcurrency(eventApisConfiguration.getEventBus().getConsumer().getEventConcurrency());
messageListenerContainer.setBeanName("emon-events");
return messageListenerContainer;
}
use of io.splitet.core.kafka.PublishedEventWrapper in project eventapis by kloiasoft.
the class EventMessageConverter method extractAndConvertValue.
@Override
public Object extractAndConvertValue(ConsumerRecord<?, ?> record, Type type) {
Object value = record.value();
if (value instanceof PublishedEventWrapper) {
PublishedEventWrapper eventWrapper = (PublishedEventWrapper) value;
Context context = eventWrapper.getContext();
context.setCommandContext(record.topic());
operationContext.switchContext(context);
userContext.extractUserContext(eventWrapper.getUserContext());
try {
return objectMapper.readValue(eventWrapper.getEvent(), TypeFactory.rawClass(type));
} catch (IOException e) {
operationRepository.failOperation(operationContext.getCommandContext(), event -> event.setEventState(EventState.TXN_FAILED));
throw new SerializationException(e);
}
} else
return super.extractAndConvertValue(record, type);
}
use of io.splitet.core.kafka.PublishedEventWrapper in project eventapis by kloiasoft.
the class EventApisFactory method kafkaConsumerFactory.
@Bean
public ConsumerFactory<String, PublishedEventWrapper> kafkaConsumerFactory() {
KafkaProperties properties = eventApisConfiguration.getEventBus().clone();
properties.getConsumer().setEnableAutoCommit(false);
return new DefaultKafkaConsumerFactory<>(properties.buildConsumerProperties(), new StringDeserializer(), new JsonDeserializer<>(PublishedEventWrapper.class, objectMapper));
}
use of io.splitet.core.kafka.PublishedEventWrapper in project eventapis by kloiasoft.
the class EventApisFactory method eventsKafkaListenerContainerFactory.
@Bean({ "eventsKafkaListenerContainerFactory", "kafkaListenerContainerFactory" })
public ConcurrentKafkaListenerContainerFactory<String, PublishedEventWrapper> eventsKafkaListenerContainerFactory(EventMessageConverter eventMessageConverter, ConsumerFactory<String, PublishedEventWrapper> consumerFactory) {
ConcurrentKafkaListenerContainerFactory<String, PublishedEventWrapper> factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory);
factory.setConcurrency(eventApisConfiguration.getEventBus().getConsumer().getEventConcurrency());
factory.setMessageConverter(eventMessageConverter);
factory.getContainerProperties().setPollTimeout(3000);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(eventApisConfiguration.getEventBus().getConsumer().getEventSchedulerPoolSize());
scheduler.setBeanName("EventsFactory-Scheduler");
scheduler.initialize();
factory.getContainerProperties().setScheduler(scheduler);
factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.RECORD);
return factory;
}
Aggregations