【问题标题】:spring cloud contract - Feign Clientsspring cloud 合约 - Feign Clients
【发布时间】:2017-07-23 03:07:42
【问题描述】:

使用 Spring Cloud 合约来验证我的生产者和消费者之间的合约。在我的消费者控制器中,我正在使用 Feign 客户端调用另一个微服务方法来获取一些数据。但是现在在春季云合同中,对这个微服务进行存根调用是不可能的。

将 Spring Cloud 与 Netflix OSS 结合使用。

Config-service 和 eureka 已启动。现在我在本地的 8090 端口安装了我的生产者。消费者使用 Feign 客户端调用生产者来获取一些数据。现在我收到 500 错误。它显示未找到该 URL。最接近的匹配是 /ping。我相信 Feign 客户端无法模拟,它以某种方式试图与不是来自本地安装的生产者的 eureka 连接。你能帮我看看吗?

任何例子或任何想法都会很棒。

谢谢

【问题讨论】:

    标签: java spring spring-cloud spring-cloud-feign spring-cloud-contract


    【解决方案1】:

    有可能,这是我的 JUnit 测试(ParticipantsService 使用 Feign 客户端)

    @RunWith(SpringRunner.class)
    @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
    @AutoConfigureStubRunner(ids = {"com.ryanjbaxter.spring.cloud:ocr-participants:+:stubs"}, workOffline = true)
    @DirtiesContext
    @ActiveProfiles("test")
    public class OcrRacesApplicationTestsBase {
    
        @Autowired
        protected ParticipantsService participantsService;
    
        private List<Participant> participants = new ArrayList<>();
    
    
        //Hack to work around https://github.com/spring-cloud/spring-cloud-commons/issues/156
        static {
            System.setProperty("eureka.client.enabled", "false");
            System.setProperty("spring.cloud.config.failFast", "false");
        }
    
        @Before
        public void setup() {
            this.participants = new ArrayList<>();
            this.participants.add(new Participant("Ryan", "Baxter", "MA", "S", Arrays.asList("123", "456")));
            this.participants.add(new Participant("Stephanie", "Baxter", "MA", "S", Arrays.asList("456")));
        }
    
        @After
        public void tearDown() {
            this.participants = new ArrayList<>();
        }
    
        @Test
        public void contextLoads() {
            List<Participant> participantList = participantsService.getAllParticipants();
            assertEquals(participants, participantList);
        }
    }
    

    【讨论】:

    • 它没有用。我也试过了。我更新了问题。可以看看吗
    • 你不需要 Eureka 或配置服务器来让合约工作。基于它无法找到匹配的合同这一事实,似乎正在发送的请求与您的合同之间可能存在差异。您能否发布合同和正在发送的请求?
    • 更新:我认为从 Dalston 开始这个问题已经解决了!
    猜你喜欢
    • 1970-01-01
    • 2020-05-18
    • 1970-01-01
    • 2015-08-24
    • 2018-06-14
    • 2015-10-21
    • 2018-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多