在Spring集成中,人們很少能夠操縱消息。一種方法是調用Bean的內部<int:enricher>
方法會返回一個對象並將其分配給定的名稱,例如:在Spring集成中調用服務激活器vs bean方法
<!-- calls getKey method of IdGenerator bean which returns String with some value -->
<int:enricher input-channel="a.channel" output-channel="b.channel" id="preTranslator">
<int:header name="Key" expression="@IdGenerator.getId(payload)"/>
</int:enricher>
一樣可以在過濾中使用:
int:filter discard-channel="d.channel" input-channel="b.channel" output-channel="c.channel"
expression="@Cache.hasKey(headers.Key) == false"/>
在另一方面,我可以在實現MessageProcessor
接口的類上調用<int:service-activator>
。它將採用原始消息並返回一個帶有新標題字段的副本。這需要我的類的方法始終使用MessageBuilder構建新的消息。
目前我使用第一種方法來簡單的字段豐富和服務激活器來從數據庫/外部服務請求數據。選擇正確方法的正確方法是什麼?