org.springframework.cloud.stream.messaging.Sink Java Examples

The following examples show how to use org.springframework.cloud.stream.messaging.Sink. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MessageListener.java    From flowing-retail with Apache License 2.0 6 votes vote down vote up
/**
 * Handles incoming OrderPlacedEvents. 
 * 
 *  Using the conditional {@link StreamListener} from 
 * https://github.com/spring-cloud/spring-cloud-stream/blob/master/spring-cloud-stream-core-docs/src/main/asciidoc/spring-cloud-stream-overview.adoc
 * in a way close to what Axion
 *  would do (see e.g. https://dturanski.wordpress.com/2017/03/26/spring-cloud-stream-for-event-driven-architectures/)
 */
@StreamListener(target = Sink.INPUT, 
    condition="(headers['type']?:'')=='OrderPlacedEvent'")
@Transactional
public void orderPlacedReceived(Message<Order> message) throws JsonParseException, JsonMappingException, IOException {
  Order order = message.getData();
  
  System.out.println("New order placed, start flow. " + order);
  
  // persist domain entity
  repository.save(order);    
  
  // and kick of a new flow instance
  camunda.getRuntimeService().createMessageCorrelation(message.getType())
    .processInstanceBusinessKey(message.getTraceid())
    .setVariable("orderId", order.getId())
    .correlateWithResult();
}
 
Example #2
Source File: MessageListener.java    From flowing-retail with Apache License 2.0 6 votes vote down vote up
@StreamListener(target = Sink.INPUT, 
    condition="(headers['type']?:'')=='ShipGoodsCommand'")
@Transactional
public void shipGoodsCommandReceived(String messageJson) throws Exception {
  Message<ShipGoodsCommandPayload> message = objectMapper.readValue(messageJson, new TypeReference<Message<ShipGoodsCommandPayload>>(){});

  String shipmentId = shippingService.createShipment( //
      message.getData().getPickId(), //
      message.getData().getRecipientName(), //
      message.getData().getRecipientAddress(), //
      message.getData().getLogisticsProvider());
      
  messageSender.send( //
      new Message<GoodsShippedEventPayload>( //
          "GoodsShippedEvent", //
          message.getTraceid(), //
          new GoodsShippedEventPayload() //
            .setRefId(message.getData().getRefId())
            .setShipmentId(shipmentId))
      .setCorrelationid(message.getCorrelationid()));
}
 
Example #3
Source File: MessageListener.java    From flowing-retail with Apache License 2.0 6 votes vote down vote up
@StreamListener(target = Sink.INPUT, 
    condition="(headers['type']?:'')=='RetrievePaymentCommand'")
@Transactional
public void retrievePaymentCommandReceived(String messageJson) throws JsonParseException, JsonMappingException, IOException {
  Message<RetrievePaymentCommandPayload> message = objectMapper.readValue(messageJson, new TypeReference<Message<RetrievePaymentCommandPayload>>(){});
  RetrievePaymentCommandPayload retrievePaymentCommand = message.getData();    
  
  System.out.println("Retrieve payment: " + retrievePaymentCommand.getAmount() + " for " + retrievePaymentCommand.getRefId());
  
  messageSender.send( //
      new Message<PaymentReceivedEventPayload>( //
          "PaymentReceivedEvent", //
          message.getTraceid(), //
          new PaymentReceivedEventPayload() //
            .setRefId(retrievePaymentCommand.getRefId()))
      .setCorrelationid(message.getCorrelationid()));

}
 
Example #4
Source File: EventProcessor.java    From service-block-samples with Apache License 2.0 6 votes vote down vote up
@StreamListener(value = Sink.INPUT)
public void handle(Message<ProjectEvent> message) {
    ProjectEvent projectEvent = message.getPayload();
    log.info("Received new event: " + "{ projectId " + projectEvent.getProjectId() + " -> " +
            projectEvent.getType() + " }");

    if (projectEvent.getType() == ProjectEventType.CREATED_EVENT) {
        try {
            commitProcessor.importCommits(projectEvent);
        } catch (IOException e) {
            throw new RuntimeException("Could not import GitHub project", e);
        }
    }

    if (projectEvent.getType() == ProjectEventType.COMMIT_EVENT) {
        // Update query models
        LambdaResponse<Map<String, Object>> response =
                projectQueries.getTightCoupling().apply(projectEvent);
    }
}
 
Example #5
Source File: MessageListener.java    From flowing-retail with Apache License 2.0 6 votes vote down vote up
@StreamListener(target = Sink.INPUT, 
    condition="(headers['type']?:'')=='RetrievePaymentCommand'")
@Transactional
public void retrievePaymentCommandReceived(String messageJson) throws JsonParseException, JsonMappingException, IOException {
  Message<RetrievePaymentCommandPayload> message = objectMapper.readValue(messageJson, new TypeReference<Message<RetrievePaymentCommandPayload>>(){});
  RetrievePaymentCommandPayload retrievePaymentCommand = message.getData();    
  
  System.out.println("Retrieve payment: " + retrievePaymentCommand.getAmount() + " for " + retrievePaymentCommand.getRefId());
  
  camunda.getRuntimeService().createMessageCorrelation(message.getType()) //
    .processInstanceBusinessKey(message.getTraceid())
    .setVariable("amount", retrievePaymentCommand.getAmount()) //
    .setVariable("remainingAmount", retrievePaymentCommand.getAmount()) //
    .setVariable("refId", retrievePaymentCommand.getRefId()) //
    .setVariable("correlationId", message.getCorrelationid()) //
    .correlateWithResult();    
}
 
Example #6
Source File: OrganizationChangeHandler.java    From spring-microservices-in-action with Apache License 2.0 6 votes vote down vote up
/**
 * Log the change event received from the organization service and update 
 * the Redis cache.
 * 
 * @param  orgChange
 *         The organization change event.
 */
@StreamListener(Sink.INPUT)
public void loggerSink(OrganizationChangeModel orgChange) {
	logger.info("Received an event for organization id {}", orgChange.getOrganizationId());
	        
    switch(orgChange.getAction()){
        case "GET":
            logger.debug("Received a GET event from the organization service for organization id {}", orgChange.getOrganizationId());
            break;
        case "SAVE":
            logger.debug("Received a SAVE event from the organization service for organization id {}", orgChange.getOrganizationId());
            break;
        case "UPDATE":
            logger.debug("Received a UPDATE event from the organization service for organization id {}", orgChange.getOrganizationId());
            organizationRedisRepository.deleteOrganization(orgChange.getOrganizationId());
            break;
        case "DELETE":
            logger.debug("Received a DELETE event from the organization service for organization id {}", orgChange.getOrganizationId());
            organizationRedisRepository.deleteOrganization(orgChange.getOrganizationId());
            break;
        default:
            logger.error("Received an UNKNOWN event from the organization service of type {}", orgChange.getType());
            break;
    }
}
 
Example #7
Source File: MessageListener.java    From flowing-retail with Apache License 2.0 6 votes vote down vote up
@StreamListener(target = Sink.INPUT, condition = "(headers['type']?:'')=='OrderPlacedEvent'")
public void orderPlacedReceived(String messageJson) throws JsonParseException, JsonMappingException, IOException {
  // read data
  Message<Order> message = objectMapper.readValue(messageJson, new TypeReference<Message<Order>>() {});
  Order order = message.getData();
  
  // persist domain entity
  // (if we want to do this "transactional" this could be a step in the workflow)
  repository.save(order);

  // prepare data for workflow
  OrderFlowContext context = new OrderFlowContext();
  context.setOrderId(order.getId());
  context.setTraceId(message.getTraceid());

  // and kick of a new flow instance
  System.out.println("New order placed, start flow with " + context);
  zeebe.newCreateInstanceCommand() //
      .bpmnProcessId("order-kafka") //
      .latestVersion() // 
      .variables(context.asMap()) //
      .send().join();
}
 
Example #8
Source File: MessageListener.java    From flowing-retail with Apache License 2.0 6 votes vote down vote up
@StreamListener(target = Sink.INPUT, 
    condition="(headers['type']?:'')=='FetchGoodsCommand'")
@Transactional
public void retrievePaymentCommandReceived(String messageJson) throws JsonParseException, JsonMappingException, IOException {
  Message<FetchGoodsCommandPayload> message = objectMapper.readValue(messageJson, new TypeReference<Message<FetchGoodsCommandPayload>>(){});
  
  FetchGoodsCommandPayload fetchGoodsCommand = message.getData();    
  String pickId = inventoryService.pickItems( // 
      fetchGoodsCommand.getItems(), fetchGoodsCommand.getReason(), fetchGoodsCommand.getRefId());
  
  messageSender.send( //
      new Message<GoodsFetchedEventPayload>( //
          "GoodsFetchedEvent", //
          message.getTraceid(), //
          new GoodsFetchedEventPayload() //
            .setRefId(fetchGoodsCommand.getRefId())
            .setPickId(pickId))
      .setCorrelationid(message.getCorrelationid()));
}
 
Example #9
Source File: MessageListener.java    From flowing-retail with Apache License 2.0 6 votes vote down vote up
@StreamListener(target = Sink.INPUT, 
    condition="(headers['type']?:'')=='PaymentReceivedEvent'")
@Transactional
public void paymentReceived(String messageJson) throws JsonParseException, JsonMappingException, IOException {
  Message<JsonNode> message = objectMapper.readValue(messageJson, new TypeReference<Message<JsonNode>>(){});
  
  ObjectNode payload = (ObjectNode) message.getData();
  Item[] items = objectMapper.treeToValue(payload.get("items"), Item[].class);
  
  String pickId = inventoryService.pickItems( // 
      Arrays.asList(items), "order", payload.get("orderId").asText());
  
  // as in payment - we have to keep the whole order in the payload 
  // as the data flows through this service
  
  payload.put("pickId", pickId);
  
  messageSender.send( //
      new Message<JsonNode>( //
          "GoodsFetchedEvent", //
          message.getTraceid(), //
          payload));
}
 
Example #10
Source File: MessageListener.java    From flowing-retail with Apache License 2.0 5 votes vote down vote up
@StreamListener(target = Sink.INPUT, 
    condition="(headers['type']?:'')=='OrderPlacedEvent'")
@Transactional
public void orderPlaced(String messageJson) throws Exception {
  // Note that we now have to read order data from this message!
  // Bad smell 1 (reading some event instead of dedicated command)
  JsonNode message = objectMapper.readTree(messageJson);
  ObjectNode payload = (ObjectNode) message.get("data");
  
  String orderId = payload.get("orderId").asText();
  if (orderId == null) {
    // We do not yet have an order id - as the responsibility who creates that is unclear 
    // Bad smell 2 (order context missing)
    // But actually not that problematic - as a good practice could be to 
    // generate it in the checkout anyway to improve idempotency
    orderId = UUID.randomUUID().toString();
    payload.put("orderId", orderId);
  }
  // the totalSum needs to be calculated by the checkout in this case - responsibility unclear
  // as this is not done we have to calculate it here - which means we have to learn to much about orders!
  // Bad smell 3 (order context missing)
  long amount = payload.get("items").iterator().next().get("amount").asLong();
  //long amount = payload.get("totalSum").asLong();

  String paymentId = paymentService.createPayment(orderId, amount);    
     
  // Note that we need to pass along the whole order object
  // Maybe with additional data we have
  // Bad smell 4 (data flow passing through - data might grow big and most data is not needed for payment)
  payload.put("paymentId", paymentId);
  
  messageSender.send( //
      new Message<JsonNode>( //
          "PaymentReceivedEvent", //
          message.get("traceid").asText(), //
          message.get("data")));
}
 
Example #11
Source File: CommentService.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
@StreamListener(Sink.INPUT)
public void broadcast(Comment comment) {
	if (webSocketCommentSink != null) {
		log.info("Publishing " + comment.toString() +
			" to websocket...");
		webSocketCommentSink.next(comment);
	}
}
 
Example #12
Source File: KafkaListenerConfiguration.java    From reactive-spring-online-training with Apache License 2.0 5 votes vote down vote up
@StreamListener
public void process(@Input(Sink.INPUT) Flux<String> names) {
		names
			.map(Author::new)
			.flatMap(this.repository::save)
			.subscribe(saved -> System.out.println("saved " + saved.toString() + '.'));
}
 
Example #13
Source File: MessageListener.java    From flowing-retail with Apache License 2.0 5 votes vote down vote up
@StreamListener(target = Sink.INPUT, condition = "(headers['type']?:'')=='PaymentReceivedEvent'")
@Transactional
public void paymentReceived(String messageJson) throws Exception {
  Message<PaymentReceivedEventPayload> message = objectMapper.readValue(messageJson, new TypeReference<Message<PaymentReceivedEventPayload>>() {});

  PaymentReceivedEventPayload event = message.getData(); // TODO: Read something from it? 

  zeebe.newPublishMessageCommand() //
    .messageName(message.getType())
    .correlationKey(message.getCorrelationid())
    .variables(Collections.singletonMap("paymentInfo", "YeahWeCouldAddSomething"))
    .send().join();
  
  System.out.println("Correlated " + message );
}
 
Example #14
Source File: MessageProcessor.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void process(Event<Integer, Recommendation> event) {

    LOG.info("Process message created at {}...", event.getEventCreatedAt());

    switch (event.getEventType()) {

    case CREATE:
        Recommendation recommendation = event.getData();
        LOG.info("Create recommendation with ID: {}/{}", recommendation.getProductId(), recommendation.getRecommendationId());
        recommendationService.createRecommendation(recommendation);
        break;

    case DELETE:
        int productId = event.getKey();
        LOG.info("Delete recommendations with ProductID: {}", productId);
        recommendationService.deleteRecommendations(productId);
        break;

    default:
        String errorMessage = "Incorrect event type: " + event.getEventType() + ", expected a CREATE or DELETE event";
        LOG.warn(errorMessage);
        throw new EventProcessingException(errorMessage);
    }

    LOG.info("Message processing done!");
}
 
Example #15
Source File: MessageSinkToOptimizeIngestListener.java    From flowing-retail with Apache License 2.0 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void messageReceived(String messageJson) throws Exception { 

  // Build array with exactly this one event
  ArrayNode messageArray = objectMapper.createArrayNode();    
  messageArray.add(objectMapper.readTree(messageJson));
  
  // and send it over to Optimize
  sendCloudEventsToOptimize(messageArray.toString());
  
  // An optimization could be to collect events and send them as batch
  // if you have high loads
}
 
Example #16
Source File: MessageProcessor.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void process(Event<Integer, Review> event) {

    LOG.info("Process message created at {}...", event.getEventCreatedAt());

    switch (event.getEventType()) {

    case CREATE:
        Review review = event.getData();
        LOG.info("Create review with ID: {}/{}", review.getProductId(), review.getReviewId());
        reviewService.createReview(review);
        break;

    case DELETE:
        int productId = event.getKey();
        LOG.info("Delete reviews with ProductID: {}", productId);
        reviewService.deleteReviews(productId);
        break;

    default:
        String errorMessage = "Incorrect event type: " + event.getEventType() + ", expected a CREATE or DELETE event";
        LOG.warn(errorMessage);
        throw new EventProcessingException(errorMessage);
    }

    LOG.info("Message processing done!");
}
 
Example #17
Source File: MessageProcessor.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void process(Event<Integer, Recommendation> event) {

    LOG.info("Process message created at {}...", event.getEventCreatedAt());

    switch (event.getEventType()) {

    case CREATE:
        Recommendation recommendation = event.getData();
        LOG.info("Create recommendation with ID: {}/{}", recommendation.getProductId(), recommendation.getRecommendationId());
        recommendationService.createRecommendation(recommendation);
        break;

    case DELETE:
        int productId = event.getKey();
        LOG.info("Delete recommendations with ProductID: {}", productId);
        recommendationService.deleteRecommendations(productId);
        break;

    default:
        String errorMessage = "Incorrect event type: " + event.getEventType() + ", expected a CREATE or DELETE event";
        LOG.warn(errorMessage);
        throw new EventProcessingException(errorMessage);
    }

    LOG.info("Message processing done!");
}
 
Example #18
Source File: MessageProcessor.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void process(Event<Integer, Product> event) {

    LOG.info("Process message created at {}...", event.getEventCreatedAt());

    switch (event.getEventType()) {

    case CREATE:
        Product product = event.getData();
        LOG.info("Create product with ID: {}", product.getProductId());
        productService.createProduct(product);
        break;

    case DELETE:
        int productId = event.getKey();
        LOG.info("Delete recommendations with ProductID: {}", productId);
        productService.deleteProduct(productId);
        break;

    default:
        String errorMessage = "Incorrect event type: " + event.getEventType() + ", expected a CREATE or DELETE event";
        LOG.warn(errorMessage);
        throw new EventProcessingException(errorMessage);
    }

    LOG.info("Message processing done!");
}
 
Example #19
Source File: MessageProcessor.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void process(Event<Integer, Review> event) {

    LOG.info("Process message created at {}...", event.getEventCreatedAt());

    switch (event.getEventType()) {

    case CREATE:
        Review review = event.getData();
        LOG.info("Create review with ID: {}/{}", review.getProductId(), review.getReviewId());
        reviewService.createReview(review);
        break;

    case DELETE:
        int productId = event.getKey();
        LOG.info("Delete reviews with ProductID: {}", productId);
        reviewService.deleteReviews(productId);
        break;

    default:
        String errorMessage = "Incorrect event type: " + event.getEventType() + ", expected a CREATE or DELETE event";
        LOG.warn(errorMessage);
        throw new EventProcessingException(errorMessage);
    }

    LOG.info("Message processing done!");
}
 
Example #20
Source File: MessageProcessor.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void process(Event<Integer, Recommendation> event) {

    LOG.info("Process message created at {}...", event.getEventCreatedAt());

    switch (event.getEventType()) {

    case CREATE:
        Recommendation recommendation = event.getData();
        LOG.info("Create recommendation with ID: {}/{}", recommendation.getProductId(), recommendation.getRecommendationId());
        recommendationService.createRecommendation(recommendation);
        break;

    case DELETE:
        int productId = event.getKey();
        LOG.info("Delete recommendations with ProductID: {}", productId);
        recommendationService.deleteRecommendations(productId);
        break;

    default:
        String errorMessage = "Incorrect event type: " + event.getEventType() + ", expected a CREATE or DELETE event";
        LOG.warn(errorMessage);
        throw new EventProcessingException(errorMessage);
    }

    LOG.info("Message processing done!");
}
 
Example #21
Source File: MessageProcessor.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void process(Event<Integer, Product> event) {

    LOG.info("Process message created at {}...", event.getEventCreatedAt());

    switch (event.getEventType()) {

    case CREATE:
        Product product = event.getData();
        LOG.info("Create product with ID: {}", product.getProductId());
        productService.createProduct(product);
        break;

    case DELETE:
        int productId = event.getKey();
        LOG.info("Delete recommendations with ProductID: {}", productId);
        productService.deleteProduct(productId);
        break;

    default:
        String errorMessage = "Incorrect event type: " + event.getEventType() + ", expected a CREATE or DELETE event";
        LOG.warn(errorMessage);
        throw new EventProcessingException(errorMessage);
    }

    LOG.info("Message processing done!");
}
 
Example #22
Source File: MessageProcessor.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void process(Event<Integer, Recommendation> event) {

    LOG.info("Process message created at {}...", event.getEventCreatedAt());

    switch (event.getEventType()) {

    case CREATE:
        Recommendation recommendation = event.getData();
        LOG.info("Create recommendation with ID: {}/{}", recommendation.getProductId(), recommendation.getRecommendationId());
        recommendationService.createRecommendation(recommendation);
        break;

    case DELETE:
        int productId = event.getKey();
        LOG.info("Delete recommendations with ProductID: {}", productId);
        recommendationService.deleteRecommendations(productId);
        break;

    default:
        String errorMessage = "Incorrect event type: " + event.getEventType() + ", expected a CREATE or DELETE event";
        LOG.warn(errorMessage);
        throw new EventProcessingException(errorMessage);
    }

    LOG.info("Message processing done!");
}
 
Example #23
Source File: MessageProcessor.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void process(Event<Integer, Product> event) {

    LOG.info("Process message created at {}...", event.getEventCreatedAt());

    switch (event.getEventType()) {

    case CREATE:
        Product product = event.getData();
        LOG.info("Create product with ID: {}", product.getProductId());
        productService.createProduct(product);
        break;

    case DELETE:
        int productId = event.getKey();
        LOG.info("Delete recommendations with ProductID: {}", productId);
        productService.deleteProduct(productId);
        break;

    default:
        String errorMessage = "Incorrect event type: " + event.getEventType() + ", expected a CREATE or DELETE event";
        LOG.warn(errorMessage);
        throw new EventProcessingException(errorMessage);
    }

    LOG.info("Message processing done!");
}
 
Example #24
Source File: MessageProcessor.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void process(Event<Integer, Review> event) {

    LOG.info("Process message created at {}...", event.getEventCreatedAt());

    switch (event.getEventType()) {

    case CREATE:
        Review review = event.getData();
        LOG.info("Create review with ID: {}/{}", review.getProductId(), review.getReviewId());
        reviewService.createReview(review);
        break;

    case DELETE:
        int productId = event.getKey();
        LOG.info("Delete reviews with ProductID: {}", productId);
        reviewService.deleteReviews(productId);
        break;

    default:
        String errorMessage = "Incorrect event type: " + event.getEventType() + ", expected a CREATE or DELETE event";
        LOG.warn(errorMessage);
        throw new EventProcessingException(errorMessage);
    }

    LOG.info("Message processing done!");
}
 
Example #25
Source File: MessageProcessor.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void process(Event<Integer, Recommendation> event) {

    LOG.info("Process message created at {}...", event.getEventCreatedAt());

    switch (event.getEventType()) {

    case CREATE:
        Recommendation recommendation = event.getData();
        LOG.info("Create recommendation with ID: {}/{}", recommendation.getProductId(), recommendation.getRecommendationId());
        recommendationService.createRecommendation(recommendation);
        break;

    case DELETE:
        int productId = event.getKey();
        LOG.info("Delete recommendations with ProductID: {}", productId);
        recommendationService.deleteRecommendations(productId);
        break;

    default:
        String errorMessage = "Incorrect event type: " + event.getEventType() + ", expected a CREATE or DELETE event";
        LOG.warn(errorMessage);
        throw new EventProcessingException(errorMessage);
    }

    LOG.info("Message processing done!");
}
 
Example #26
Source File: MessageProcessor.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void process(Event<Integer, Product> event) {

    LOG.info("Process message created at {}...", event.getEventCreatedAt());

    switch (event.getEventType()) {

    case CREATE:
        Product product = event.getData();
        LOG.info("Create product with ID: {}", product.getProductId());
        productService.createProduct(product);
        break;

    case DELETE:
        int productId = event.getKey();
        LOG.info("Delete recommendations with ProductID: {}", productId);
        productService.deleteProduct(productId);
        break;

    default:
        String errorMessage = "Incorrect event type: " + event.getEventType() + ", expected a CREATE or DELETE event";
        LOG.warn(errorMessage);
        throw new EventProcessingException(errorMessage);
    }

    LOG.info("Message processing done!");
}
 
Example #27
Source File: MessageProcessor.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void process(Event<Integer, Review> event) {

    LOG.info("Process message created at {}...", event.getEventCreatedAt());

    switch (event.getEventType()) {

    case CREATE:
        Review review = event.getData();
        LOG.info("Create review with ID: {}/{}", review.getProductId(), review.getReviewId());
        reviewService.createReview(review);
        break;

    case DELETE:
        int productId = event.getKey();
        LOG.info("Delete reviews with ProductID: {}", productId);
        reviewService.deleteReviews(productId);
        break;

    default:
        String errorMessage = "Incorrect event type: " + event.getEventType() + ", expected a CREATE or DELETE event";
        LOG.warn(errorMessage);
        throw new EventProcessingException(errorMessage);
    }

    LOG.info("Message processing done!");
}
 
Example #28
Source File: MessageProcessor.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void process(Event<Integer, Recommendation> event) {

    LOG.info("Process message created at {}...", event.getEventCreatedAt());

    switch (event.getEventType()) {

    case CREATE:
        Recommendation recommendation = event.getData();
        LOG.info("Create recommendation with ID: {}/{}", recommendation.getProductId(), recommendation.getRecommendationId());
        recommendationService.createRecommendation(recommendation);
        break;

    case DELETE:
        int productId = event.getKey();
        LOG.info("Delete recommendations with ProductID: {}", productId);
        recommendationService.deleteRecommendations(productId);
        break;

    default:
        String errorMessage = "Incorrect event type: " + event.getEventType() + ", expected a CREATE or DELETE event";
        LOG.warn(errorMessage);
        throw new EventProcessingException(errorMessage);
    }

    LOG.info("Message processing done!");
}
 
Example #29
Source File: MessageProcessor.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void process(Event<Integer, Review> event) {

    LOG.info("Process message created at {}...", event.getEventCreatedAt());

    switch (event.getEventType()) {

    case CREATE:
        Review review = event.getData();
        LOG.info("Create review with ID: {}/{}", review.getProductId(), review.getReviewId());
        reviewService.createReview(review);
        break;

    case DELETE:
        int productId = event.getKey();
        LOG.info("Delete reviews with ProductID: {}", productId);
        reviewService.deleteReviews(productId);
        break;

    default:
        String errorMessage = "Incorrect event type: " + event.getEventType() + ", expected a CREATE or DELETE event";
        LOG.warn(errorMessage);
        throw new EventProcessingException(errorMessage);
    }

    LOG.info("Message processing done!");
}
 
Example #30
Source File: MessageProcessor.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 5 votes vote down vote up
@StreamListener(target = Sink.INPUT)
public void process(Event<Integer, Product> event) {

    LOG.info("Process message created at {}...", event.getEventCreatedAt());

    switch (event.getEventType()) {

    case CREATE:
        Product product = event.getData();
        LOG.info("Create product with ID: {}", product.getProductId());
        productService.createProduct(product);
        break;

    case DELETE:
        int productId = event.getKey();
        LOG.info("Delete recommendations with ProductID: {}", productId);
        productService.deleteProduct(productId);
        break;

    default:
        String errorMessage = "Incorrect event type: " + event.getEventType() + ", expected a CREATE or DELETE event";
        LOG.warn(errorMessage);
        throw new EventProcessingException(errorMessage);
    }

    LOG.info("Message processing done!");
}