use of org.springframework.kafka.annotation.KafkaListener in project eventapis by kloiasoft.
the class SpringKafkaOpListener method listenOperations.
@Transactional(rollbackFor = Exception.class)
@KafkaListener(id = "op-listener", topics = Operation.OPERATION_EVENTS, containerFactory = "operationsKafkaListenerContainerFactory")
void listenOperations(ConsumerRecord<String, Operation> record) {
String key = record.key();
Operation value = record.value();
log.debug("Incoming Message: " + key + " " + value);
userContext.extractUserContext(value.getUserContext());
for (AggregateListener snapshotRecorder : aggregateListeners) {
snapshotRecorder.listenOperations(record);
}
}
use of org.springframework.kafka.annotation.KafkaListener in project eventapis by kloiasoft.
the class ReserveStockEventHandler method execute.
@Override
@KafkaListener(topics = "ReserveStockEvent", containerFactory = "eventsKafkaListenerContainerFactory")
public EventKey execute(ReserveStockEvent dto) throws Exception {
Stock stock = stockQuery.queryEntity(dto.getStockId());
if (stock.getRemainingStock() >= dto.getNumberOfItemsSold()) {
StockReservedEvent stockReservedEvent = new StockReservedEvent();
BeanUtils.copyProperties(dto, stockReservedEvent);
stockReservedEvent.setOrderId(dto.getSender().getEntityId());
try {
return eventRepository.recordAndPublish(stock, stockReservedEvent, entityEvent -> new StockConcurrencyResolver(stockQuery, dto));
} catch (StockNotEnoughException e) {
return recordStockNotEnough(dto, stock);
} catch (Exception e) {
log.error(e.getMessage(), e);
return stock.getEventKey();
}
} else
return recordStockNotEnough(dto, stock);
}
use of org.springframework.kafka.annotation.KafkaListener in project summer by foxsugar.
the class UserServiceMsgConsumer method listen2.
@KafkaListener(id = "centerTopic", topicPattern = "center_topic")
public void listen2(ConsumerRecord<String, String> record) {
ThreadPool.getInstance().executor.execute(() -> {
String key = record.key();
String value = record.value();
KafkaMsgKey msgKey = JsonUtil.readValue(key, KafkaMsgKey.class);
CenterMsgService.dispatch(msgKey, value);
});
}
use of org.springframework.kafka.annotation.KafkaListener in project open-kilda by telstra.
the class KafkaHealthCheckMessageConsumer method receive.
/**
* Receives messages from WorkFlowManager queue.
*
* @param record the message object instance
*/
@KafkaListener(id = "northbound-listener-health-check", topics = Topic.HEALTH_CHECK)
public void receive(final String record) {
try {
logger.trace("message received");
Message message = MAPPER.readValue(record, Message.class);
if (Destination.NORTHBOUND.equals(message.getDestination())) {
logger.debug("message received: {}", record);
InfoMessage info = (InfoMessage) message;
HealthCheckInfoData healthCheck = (HealthCheckInfoData) info.getData();
messages.put(healthCheck.getId(), healthCheck);
} else {
logger.trace("Skip message: {}", message);
}
} catch (IOException exception) {
logger.error("Could not deserialize message: {}", record, exception);
}
}
use of org.springframework.kafka.annotation.KafkaListener in project eventapis by kloiasoft.
the class StockReleasedEventHandler method execute.
@KafkaListener(topics = "StockReleasedEvent", containerFactory = "eventsKafkaListenerContainerFactory")
public EventKey execute(StockReleasedEvent dto) throws EventStoreException, ConcurrentEventException {
Orders order = orderQuery.queryEntity(dto.getOrderId());
if (order.getState() == OrderState.RELEASING_STOCK) {
OrderCancelledEvent orderCancelledEvent = new OrderCancelledEvent();
log.info("Payment is processing : " + dto);
EventKey eventKey = eventRepository.recordAndPublish(order, orderCancelledEvent);
paymentClient.returnPaymentCommand(order.getPaymentId(), new ReturnPaymentCommandDto(order.getId()));
return eventKey;
} else
throw new EventStoreException("Order state is not valid for this Operation: " + dto);
}
Aggregations