W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
我們想使用在“服務(wù)器端(nodejs)”步驟中創(chuàng)建的存根。假設(shè)我們要在端口9876
上運行存根。NodeJS代碼在這里可用:
$ git clone https://github.com/spring-cloud-samples/spring-cloud-contract-nodejs
$ cd bookstore
讓我們使用存根運行Stub Runner引導(dǎo)應(yīng)用程序。
# Provide the Spring Cloud Contract Docker version $ SC_CONTRACT_DOCKER_VERSION="..." # The IP at which the app is running and Docker container can reach it $ APP_IP="192.168.0.100" # Spring Cloud Contract Stub Runner properties $ STUBRUNNER_PORT="8083" # Stub coordinates 'groupId:artifactId:version:classifier:port' $ STUBRUNNER_IDS="com.example:bookstore:0.0.1.RELEASE:stubs:9876" $ STUBRUNNER_REPOSITORY_ROOT="http://${APP_IP}:8081/artifactory/libs-release-local" # Run the docker with Stub Runner Boot $ docker run --rm -e "STUBRUNNER_IDS=${STUBRUNNER_IDS}" -e "STUBRUNNER_REPOSITORY_ROOT=${STUBRUNNER_REPOSITORY_ROOT}" -e "STUBRUNNER_STUBS_MODE=REMOTE" -p "${STUBRUNNER_PORT}:${STUBRUNNER_PORT}" -p "9876:9876" springcloud/spring-cloud-contract-stub-runner:"${SC_CONTRACT_DOCKER_VERSION}"
這是怎么回事
9876
上下載了坐標為com.example:bookstore:0.0.1.RELEASE:stubs
的存根http://192.168.0.100:8081/artifactory/libs-release-local
8083
上運行9876
上運行在服務(wù)器端,我們構(gòu)建了一個有狀態(tài)的存根。讓我們使用curl聲明存根已正確設(shè)置。
# let's execute the first request (no response is returned) $ curl -H "Content-Type:application/json" -X POST --data '{ "title" : "Title", "genre" : "Genre", "description" : "Description", "author" : "Author", "publisher" : "Publisher", "pages" : 100, "image_url" : "https://d213dhlpdb53mu.cloudfront.net/assets/pivotal-square-logo-41418bd391196c3022f3cd9f3959b3f6d7764c47873d858583384e759c7db435.svg", "buy_url" : "https://pivotal.io" }' http://localhost:9876/api/books # Now time for the second request $ curl -X GET http://localhost:9876/api/books # You will receive contents of the JSON
如果要使用在主機上本地構(gòu)建的存根,則應(yīng)傳遞環(huán)境變量-e STUBRUNNER_STUBS_MODE=LOCAL
并安裝本地m2的卷-v "${HOME}/.m2/:/root/.m2:ro"
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: