SpringCloud 異步支持

2023-12-13 11:41 更新

如果您在服務(wù)器端使用異步通信(您的控制器返回Callable,DeferredResult,依此類推),那么在合同中,您必須在{10中提供一個(gè)async()方法/} 部分。以下代碼顯示了一個(gè)示例:

Groovy DSL。 

org.springframework.cloud.contract.spec.Contract.make {
    request {
        method GET()
        url '/get'
    }
    response {
        status OK()
        body 'Passed'
        async()
    }
}

YAML。 

response:
    async: true

您還可以使用fixedDelayMilliseconds方法/屬性來向存根添加延遲。

Groovy DSL。 

org.springframework.cloud.contract.spec.Contract.make {
    request {
        method GET()
        url '/get'
    }
    response {
        status 200
        body 'Passed'
        fixedDelayMilliseconds 1000
    }
}

YAML。 

response:
    fixedDelayMilliseconds: 1000

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號