简体   繁体   English

Java:非RESTful API的消费者驱动合同

[英]Java: Consumer-Driven Contracts for non-RESTful APIs

I would like to implement consumer-driven contracts in my Spring Boot micro-services. 我想在我的Spring Boot微服务中实现消费者驱动的合同。

However, not all services are RESTful. 但是,并非所有服务都是RESTful的。 Some of them use proprietary communication protocols. 其中一些使用专有的通信协议。 Some of them do not have Java API implemented by me. 其中一些没有我实现的Java API。 For all these service, I have written a "java client" library, which I include in the consumers as a dependency, and that way I aid integration. 对于所有这些服务,我已经编写了一个“ java客户端”库,该库作为依赖项包含在使用者中,这样我就可以帮助集成。

Could you please tell me if there exists an extension to Spring Cloud Contract, or an alternative Java implementation of Consumer-Driven Contracts which have stub and tests generation for POJO classes or Spring Boot services out of the contract, the same way this is done for the RESTful APIs? 您能否告诉我,是否存在对Spring Cloud Contract的扩展,或者是否有消费者驱动的Contract的Java替代实现,它具有从合同中测试POJO类或Spring Boot服务的存根并测试生成情况,因此RESTful API?

What you can do is call the API via a proxy and generate stubs of it. 您可以做的是通过代理调用API并生成其存根。 You can check out an example of such a flow here https://github.com/marcingrzejszczak/the-legacy-app/tree/master/stubs_with_proxy/ 您可以在此处查看此类流程的示例https://github.com/marcingrzejszczak/the-legacy-app/tree/master/stubs_with_proxy/

With such an approach, your communication with the service you don't own will be recorded and can be later reused as a stub. 通过这种方法,您与您不拥有的服务的通信将被记录下来,以后可以作为存根再次使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM