SpringCloud Binder SPI

2023-11-27 11:30 更新

Binder SPI由許多接口,現(xiàn)成的實用程序類和發(fā)現(xiàn)策略組成,這些策略提供了用于連接到外部中間件的可插拔機制。

SPI的關鍵是Binder接口,這是將輸入和輸出連接到外部中間件的策略。以下清單顯示了Binder接口的定義:

public interface Binder<T, C extends ConsumerProperties, P extends ProducerProperties> {
    Binding<T> bindConsumer(String name, String group, T inboundBindTarget, C consumerProperties);

    Binding<T> bindProducer(String name, T outboundBindTarget, P producerProperties);
}

該接口已參數(shù)化,提供了許多擴展點:

  • 輸入和輸出綁定目標。從1.0版開始,僅支持MessageChannel,但將來打算將其用作擴展點。
  • 擴展的使用者和生產(chǎn)者屬性,允許特定的Binder實現(xiàn)添加可以以類型安全的方式支持的補充屬性。

典型的活頁夾實現(xiàn)包括以下內(nèi)容:

  • 實現(xiàn)Binder接口的類;
  • 一個Spring @Configuration類,它創(chuàng)建類型為Binder的bean和中間件連接基礎結(jié)構(gòu)。
  • 在類路徑上找到一個META-INF/spring.binders文件,其中包含一個或多個綁定程序定義,如以下示例所示:

    kafka:\
    org.springframework.cloud.stream.binder.kafka.config.KafkaBinderConfiguration
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號