SpringCloud Stub Runner Camel例子
2023-12-12 17:45 更新
让我们假设我们有以下Maven存储库,其中包含用于camelService
应用程序的已部署存根。
└── .m2 └── repository └── io └── codearte └── accurest └── stubs └── camelService ├── 0.0.1-SNAPSHOT │ ├── camelService-0.0.1-SNAPSHOT.pom │ ├── camelService-0.0.1-SNAPSHOT-stubs.jar │ └── maven-metadata-local.xml └── maven-metadata-local.xml
存根包含以下结构:
├── META-INF │ └── MANIFEST.MF └── repository ├── accurest │ ├── bookDeleted.groovy │ ├── bookReturned1.groovy │ └── bookReturned2.groovy └── mappings
让我们考虑以下合同(用1编号):
Contract.make { label 'return_book_1' input { triggeredBy('bookReturnedTriggered()') } outputMessage { sentTo('jms:output') body('''{ "bookName" : "foo" }''') headers { header('BOOK-NAME', 'foo') } } }
和数字2
Contract.make { label 'return_book_2' input { messageFrom('jms:input') messageBody([ bookName: 'foo' ]) messageHeaders { header('sample', 'header') } } outputMessage { sentTo('jms:output') body([ bookName: 'foo' ]) headers { header('BOOK-NAME', 'foo') } } }
为了通过return_book_1
标签触发消息,我们将使用StubTigger
接口,如下所示
stubFinder.trigger('return_book_1')
接下来,我们要收听发送到jms:output
的消息的输出
Exchange receivedMessage = consumerTemplate.receive('jms:output', 5000)
并且收到的消息将通过以下断言
receivedMessage != null assertThatBodyContainsBookNameFoo(receivedMessage.in.body) receivedMessage.in.headers.get('BOOK-NAME') == 'foo'
由于已为您设置了路由,仅向jms:output
目标发送一条消息就足够了。
producerTemplate. sendBodyAndHeaders('jms:input', new BookReturned('foo'), [sample: 'header'])
接下来,我们要监听发送到jms:output
的消息的输出
Exchange receivedMessage = consumerTemplate.receive('jms:output', 5000)
并且收到的消息将通过以下断言
receivedMessage != null assertThatBodyContainsBookNameFoo(receivedMessage.in.body) receivedMessage.in.headers.get('BOOK-NAME') == 'foo'
以上内容是否对您有帮助:
更多建议: