use of com.kloia.eventapis.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(AbstractMessageListenerContainer.AckMode.RECORD);
return factory;
}
use of com.kloia.eventapis.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 com.kloia.eventapis.kafka.PublishedEventWrapper in project eventapis by kloiasoft.
the class EventListenConfiguration method startEvents.
private void startEvents() {
Map<String, Object> consumerProperties = eventApisConfiguration.getEventBus().buildConsumerProperties();
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));
messageListenerContainer = new ConcurrentMessageListenerContainer<>(consumerFactory, containerProperties);
messageListenerContainer.setBeanName("emon-events");
messageListenerContainer.start();
}
Aggregations