org.springframework.cloud.stream.annotation.StreamListener Java Examples

The following examples show how to use org.springframework.cloud.stream.annotation.StreamListener. 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: EventListener.java    From Mastering-Microservices-with-Java-Third-Edition with MIT License 6 votes vote down vote up
@StreamListener(BillingMessageChannels.BOOKING_ORDER_INPUT)
public void consumeBookingOrder(BookingOrder bookingOrder) {
  LOG.info("Received BookingOrder: {}", bookingOrder);
  // TODO: Add logic if booking order is already processed or in process
  long randomId = RANDOM.nextLong();
  if (randomId < 0) {
    LOG.info("\n\n\nGenerate failed billing event for negative randomId for testing\n\n\n");
    billingEventHandler.produceBillingEvent(null, bookingOrder.getName().toString());
  } else {
    String id = String.valueOf(randomId);
    LocalDate nowDate = LocalDate.now();
    LocalTime nowTime = LocalTime.now();
    try {
      Billing billing = new Billing(id, "bill-" + id,
          bookingOrder.getRestaurantId().toString(), bookingOrder.getName().toString(),
          bookingOrder.getTableId().toString(), bookingOrder.getUserId().toString(),
          nowDate, nowTime);
      billingService.add(billing);
      billingEventHandler.produceBillingEvent(billing, bookingOrder.getName().toString());
    } catch (Exception ex) {
      billingEventHandler.produceBillingEvent(null, bookingOrder.getName().toString());
    }
  }
}
 
Example #2
Source File: EventListener.java    From Mastering-Microservices-with-Java-Third-Edition with MIT License 6 votes vote down vote up
@StreamListener(BookingMessageChannels.BILLING_INPUT)
public void consumeBilling(BillingBookingResponse billingResponse) {
  try {
    HeaderName<String> headerName = HeaderName.forName("billingStatus");
    Map<HeaderName<?>, Object> headers = ImmutableMap
        .of(headerName, billingResponse.getStatus().toString());

    MessageStream messageStream = SagaConfig.messageStreamMap.get(billingResponse.getBookingId().toString());
    LOG.info("\n\n\n   Received billing event: {}\n   messageStream: {}\n\n", billingResponse, messageStream);
    messageStream.addMessage(new BillingVO(billingResponse.getBillId().toString(),
            billingResponse.getName().toString(),
            billingResponse.getRestaurantId().toString(), billingResponse.getBookingId().toString(),
            billingResponse.getTableId().toString(), "User", LocalDate.now(), LocalTime.now()),
        headers);
  } catch (Exception ex) {
    ex.printStackTrace();
    LOG.error(ex.getMessage());
  }
}
 
Example #3
Source File: BoardEventNotificationSink.java    From event-store-demo with GNU General Public License v3.0 6 votes vote down vote up
@StreamListener( Sink.INPUT )
public void processNotification( final String json ) {
    log.debug( "processNotification : enter" );

    Tuple event = TupleBuilder.fromString( json );

    Assert.hasText( event.getString( "eventType" ), "eventType not set" );
    Assert.hasText( event.getString( "boardUuid" ), "boardUuid not set" );
    Assert.hasText( event.getString( "occurredOn" ), "occurredOn not set" );

    String eventType = event.getString( "eventType" );
    if( eventType.equals( "BoardInitialized" ) ) {
        log.debug( "processNotification : exit, no board should exist in cache if 'BoardInitialized' event is received" );

        return;
    }

    this.service.uncacheTarget( UUID.fromString( event.getString( "boardUuid" ) ) );

    log.debug( "processNotification : exit" );
}
 
Example #4
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 #5
Source File: InventoryHub.java    From inventory-hub-java-on-azure with MIT License 6 votes vote down vote up
@StreamListener(target=Sink.INPUT)
public void receiveTransaction(String transactionMessage) {

       System.out.println("message is: " + transactionMessage);

       try
       {
           transaction = objectMapper.readValue(
               new String(transactionMessage.getBytes(), "UTF8"), Transaction.class);

           TransactionsController.transactions.addFirst(transaction);

           System.out.println("=== event data ===\n" + transaction.toString());

       } catch (Exception e)
       {
           System.out.println("Processing failed for an event: " + e.toString());
		e.printStackTrace();
       }

   }
 
Example #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #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, 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 #15
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 #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, 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 #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, 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 #18
Source File: KafkaStreamsApp.java    From springboot-kafka-avro with MIT License 5 votes vote down vote up
@StreamListener
@SendTo(USERS_FILTERED)
KStream<String, User> processUsers(@Input(USERS) KStream<String, User> inputStream) {
  return inputStream
      .filter((key, user) -> user.getAge() < 40)
      .mapValues(user -> new User(user.getName().toUpperCase(), user.getAge()))
      .peek((key, user) -> log.info("New entry in filtered stream => Key = " + key + " Value = " + user));
}
 
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, 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 #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, 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 #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, 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 #25
Source File: ConcurrentlyDlqReceiveService.java    From rocketmq-binder-demo with Apache License 2.0 5 votes vote down vote up
@StreamListener(Sink.INPUT)
public void receiveConcurrentlyMsg(String receiveMsg) {
    log.info("invoke: " + count.get());
	if (count.getAndIncrement() <= 5) {
           throw new RuntimeException("Oops: " + receiveMsg);
	}
	else {
		log.info("receiveOrderlyMsg: " + receiveMsg);
	}
}
 
Example #26
Source File: SendToService.java    From rocketmq-binder-demo with Apache License 2.0 5 votes vote down vote up
/**
    * @SendTo is useful with @StreamListener
    */

@StreamListener(Sink.INPUT)
@SendTo(SendToApplication.TEMP_INPUT)
public String receive(String receiveMsg) {
	System.out.println("receive: " + receiveMsg);
	return "handle by SendTo(" + receiveMsg + ")";
}
 
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: OrderlyReceiveService.java    From rocketmq-binder-demo with Apache License 2.0 5 votes vote down vote up
@StreamListener(Sink.INPUT)
public void receiveOrderlyMsg(String receiveMsg) {
	if (count.getAndIncrement() <= 5) {
           throw new RuntimeException("Oops: " + receiveMsg);
	}
	else {
		log.info("receiveOrderlyMsg: " + receiveMsg);
	}
}
 
Example #30
Source File: DefaultStatisticService.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 5 votes vote down vote up
@Override
@StreamListener(Processor.INPUT)
@Output(Processor.OUTPUT)
public Flux<UsersStatisticVM> updateStatistic(Flux<MessageResponse> messagesFlux) {
    return messagesFlux.map(MessageMapper::toDomainUnit)
                       .transform(messageRepository::saveAll)
                       .retryBackoff(Long.MAX_VALUE, Duration.ofMillis(500))
                       .onBackpressureLatest()
                       .concatMap(e -> this.doGetUserStatistic(), 1)
                       .onErrorContinue((t, e) -> {});
}