![](/img/trans.png)
[英]The generated tests(producer side) failed in Spring Cloud contract and AMQP/RabbitMQ
[英]Spring Cloud Contract with Spring AMQP
所以我一直在嘗試使用Spring Cloud Contract測試RabbitListener。
到目前為止,我發現通過在合同中定義“ triggeredBy”,生成的測試將調用那里提供的方法,因此我們需要提供該方法在TestBase中的實際實現。 另一件事是“ outputMessage”,在這里我們可以驗證方法調用之前是否已經正確地將某些消息主體發送到了某些交換機。
我的問題是,有什么辦法可以從合同中產生輸入消息,而不是觸發自己的自定義方法? 也許類似文檔中的Spring Integration或Spring Cloud Stream示例之類的東西:
Contract.make {
name("Book Success")
label("book_success")
input {
messageFrom 'input.exchange.and.maybe.route'
messageHeaders {
header('contentType': 'application/json')
header('otherMessageHeader': '1')
}
messageBody ([
bookData: someData
])
}
outputMessage {
sentTo 'output.exchange.and.maybe.route'
headers {
header('contentType': 'application/json')
header('otherMessageHeader': '2')
}
body([
bookResult: true
])
}
}
我在他們的示例項目中找不到任何示例來說明如何執行此操作。
使用Spring Cloud Contract來記錄和測試其余api服務后,如果可能的話,我想通過在基於事件的服務的合約文件中定義輸入和預期輸出來保持一致。
沒關系,實際上它已經受支持了。 出於未知原因, “ Stub Runner Spring AMQP”中的文檔沒有像其他先前的示例一樣列出該方案。
這是我的工作方式:
Contract.make {
name("Amqp Contract")
label("amqp_contract")
input {
messageFrom 'my.exchange'
messageHeaders {
header('contentType': 'text/plain')
header('amqp_receivedRoutingKey' : 'my.routing.key')
}
messageBody(file('request.json'))
}
outputMessage {
sentTo 'your.exchange'
headers {
header('contentType': 'text/plain')
header('amqp_receivedRoutingKey' : 'your.routing.key')
}
body(file('response.json'))
}
}
這將創建一個測試,該測試將基於觸發處理程序方法的“ my.exchange”和“ my.routing.key”調用您的偵聽器。 然后它將在RabbitTemplate調用“ your.exchange”上捕獲消息和路由鍵。
verify(this.rabbitTemplate, atLeastOnce()).send(eq(destination), routingKeyCaptor.capture(),
messageCaptor.capture(), any(CorrelationData.class));
然后將聲明消息和路由密鑰。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.