20 Aralık 2022 Salı

SpringCloud Stream @StreamListener Anotasyonu - Kullanmayın

Örnek
application.yaml şöyle olsun
spring:
  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest
  cloud:
    stream:
      bindings:
        orderSubmissionInput:
          destination: orderSubmitted.exchange
          group: inventory        
        movementEventInput:
          destination: movementEvent.exchange
          group: inventory
Şöyle yaparız
public interface MessageChannels {
  static final String ORDER_SUBMISSION_INPUT = "orderSubmissionInput";
  static final String MOVEMENT_EVENT_INPUT = "movementEventInput";

  @Input(ORDER_SUBMISSION_INPUT)
  SubscribableChannel orderSubmissionChannel();

  @Input(MOVEMENT_EVENT_INPUT)
  SubscribableChannel movementEventChannel();
}

@Slf4j
@Component
public class OrderListener {
  @StreamListener(MessageChannels.ORDER_SUBMISSION_INPUT)
  public void handleSubmittedOrder(Order order) {
    log.info("Order received - {}", order.toString());
  }
}


@Slf4j
@Component
public class MovementEventListener {
  @StreamListener(MessageChannels.MOVEMENT_EVENT_INPUT)
  public void handleMovementEvent(MovementEvent event) {
    log.info("Movement event received - {}", event.toString());
  }
}

Hiç yorum yok:

Yorum Gönder