Java Code Examples for org.springframework.cloud.stream.messaging.Sink#INPUT

The following examples show how to use org.springframework.cloud.stream.messaging.Sink#INPUT . 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
/**
 * Very generic listener for simplicity. It takes all events and checks, if a 
 * flow instance is interested. If yes, they are correlated, 
 * otherwise they are just discarded.
 *  
 * It might make more sense to handle each and every message type individually.
 */
@StreamListener(target = Sink.INPUT, 
    condition="(headers['type']?:'').endsWith('Event')")
@Transactional
public void messageReceived(String messageJson) throws Exception {
  Message<JsonNode> message = objectMapper.readValue( //
      messageJson, //
      new TypeReference<Message<JsonNode>>() {});
  
  long correlatingInstances = camunda.getRuntimeService().createExecutionQuery() //
    .messageEventSubscriptionName(message.getType()) //
    .processInstanceBusinessKey(message.getTraceid()) //
    .count();
  
  if (correlatingInstances==1) {
    System.out.println("Correlating " + message + " to waiting flow instance");
    
    camunda.getRuntimeService().createMessageCorrelation(message.getType())
      .processInstanceBusinessKey(message.getTraceid())
      .setVariable(//
          "PAYLOAD_" + message.getType(), // 
          SpinValues.jsonValue(message.getData().toString()).create())//
      .correlateWithResult();
  } 
  
}
 
Example 2
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 3
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']?:'')=='GoodsShippedEvent'")
@Transactional
public void goodsShippedReceived(String messageJson) throws Exception {
  Message<GoodsShippedEventPayload> message = objectMapper.readValue(messageJson, new TypeReference<Message<GoodsShippedEventPayload>>() {});

  String shipmentId = message.getData().getShipmentId();     

  zeebe.newPublishMessageCommand() //
      .messageName(message.getType()) //
      .correlationKey(message.getCorrelationid()) //
      .variables(Collections.singletonMap("shipmentId", shipmentId)) //
      .send().join();

  System.out.println("Correlated " + message );
}
 
Example 4
Source File: ConcurrentlyBrokerRetryReceiveService.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("receiveConcurrentlyMsg: " + receiveMsg);
	}
}
 
Example 5
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 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, 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 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, 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 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, 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 9
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 10
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 11
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 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, 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 13
Source File: ReservationServiceApplication.java    From training with Apache License 2.0 5 votes vote down vote up
@StreamListener
public void incomingMessages(@Input(Sink.INPUT) Flux<String> rnPublisher) {
	rnPublisher
			.map(rn -> new Reservation(null, rn))
			.flatMap(this.rr::save)
			.subscribe(r -> System.out.println("received and saved " + r.getId() + " with " + r.getReservationName() + "."));
}
 
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, 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 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, 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 16
Source File: ErrorConsumeService.java    From rocketmq-binder-demo with Apache License 2.0 4 votes vote down vote up
/**
 * Sink.INPUT DirectChannel using RoundRobin LoadBalancingStrategy So 1st msg handle
 * by `test-topic.test-group1.errors` MessageChannel 2nd msg handle by LoggingHandler
 * 3rd msg handle by `test-topic.test-group1.errors` MessageChannel
 */

@StreamListener(Sink.INPUT)
public void receive(String receiveMsg) {
	throw new RuntimeException("Oops");
}
 
Example 17
Source File: DataConsumer.java    From spring-cloud with Apache License 2.0 4 votes vote down vote up
@StreamListener(Sink.INPUT)
public void loggerSink(SinkTimeInfo sinkTimeInfo) {
    System.out.println("TimeInfo Received: " + sinkTimeInfo.toString());
}
 
Example 18
Source File: StreamListenerReceiveService.java    From rocketmq-binder-demo with Apache License 2.0 4 votes vote down vote up
@StreamListener(Sink.INPUT)
public void receiveByStreamListener2(String receiveMsg) {
	System.out.println("receiveByStreamListener2: " + receiveMsg);
}
 
Example 19
Source File: SinkApplication.java    From rocketmq-binder-demo with Apache License 2.0 4 votes vote down vote up
@StreamListener(Sink.INPUT)
public void loggerSink(String date) {
    logger.info("Received: " + date);
}
 
Example 20
Source File: FleetLocationUpdaterSink.java    From Real-Time-Taxi-Dispatch-Simulator with MIT License 3 votes vote down vote up
@ServiceActivator(inputChannel = Sink.INPUT)
public void updateLocationaddServiceLocations(String input) throws Exception {

	CurrentPosition payload = this.objectMapper.readValue(input, CurrentPosition.class);

	this.template.convertAndSend("/topic/vehicles", payload);
}