我正在使用stumby4j来制止某些服务端点。我目前正在为那些非常重且不那么复杂的人嘲笑,但我想在其余的端点上致电真实的服务。
类似的东西:
/heavy-call-1 => stub service
/heavy-call-2 => stub service
/lightweight-call-1 => real service
/lightweight-call-2 => real service
有什么方法可以通过此工具来实现此目标,还是应该考虑使用其他工具?
您实际上可以使Stubby调用真实服务并首次记录响应,因此下一个请求将使用此记录的响应。您可以做到这一点的方法是在yaml文件中指定undbed响应正文中的URL:
- request:
url: /1.1/direct_messages.json
query:
since_id: 240136858829479935
count: 1
response:
headers:
content-type: application/json
body: https://api.twitter.com/1.1/direct_messages.json?since_id=240136858829479935&count=1
您可以在Stubby Github文档中找到更多信息:https://stubby4j.com/#key-features和https://stubby4j.com/docs/docs/http_endpoint_configuration_chconfiguration_howto.html#record-uncord-uncord-and-replayp pl>
希望这会有所帮助!
您是否正在使用webpack?如果是这样,您可以匹配不同的域。例如:
const config = merge(common, {
devtool: 'inline-source-map',
mode: 'development',
devServer: {
historyApiFallback: true,
port: 3000,
hot: true,
proxy: [
{ path: '/heavy-all-1 ', target: 'http://localhost:8882' }, //stubby
],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'),
}),
],
});
和未描述前缀的URL不会固定。