Created
July 25, 2021 15:44
-
-
Save dunithd/de5835cff9f11ab777a09016f0f24b3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.edu.samples; | |
import com.edu.samples.messagelog.MessageLog; | |
import com.edu.samples.serde.OrderEvent; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import javax.enterprise.context.ApplicationScoped; | |
import javax.inject.Inject; | |
import javax.transaction.Transactional; | |
@ApplicationScoped | |
public class OrderEventHandler { | |
private static final Logger LOGGER = LoggerFactory.getLogger(OrderEventHandler.class); | |
@Inject | |
MessageLog log; | |
@Transactional | |
public void onOrderEvent(OrderEvent event) { | |
String eventId = event.getEventId(); | |
if (log.alreadyProcessed(eventId)) { | |
LOGGER.info("Event with eventID {} was already retrieved, ignoring it", eventId); | |
return; | |
} | |
LOGGER.info("Received 'Order' event -- orderId: {}, customerId: '{}', status: '{}'", | |
event.getPayload().getId(), | |
event.getPayload().getCustomerId(), | |
event.getPayload().getStatus() | |
); | |
log.processed(eventId); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment