用于烟雾测试的SpringCloudStubRunner引导应用程序和云流(kafka)

mtb9vblg  于 2021-06-07  发布在  Kafka
关注(0)|答案(1)|浏览(423)

在微服务架构中,我有三个服务。第一种方法使用spring云流在kafka队列中创建消息。在这个服务中,我使用springcloudcontract生成一个契约。第二个服务是springcloudstubrunner引导服务,它读取第一个服务的契约并将它们公开给第三个服务。第三个服务使用endpont/triiggers/{label}对存根运行器服务进行冒烟测试。我知道,当我调用/triggers/{label}时,服务存根运行程序应该将服务契约中创建的消息发送到kafka队列,但决不会将其发送到队列。如何让存根运行器服务将契约消息发送到kafka队列?。谢谢
代码:
服务1
合同:

org.springframework.cloud.contract.spec.Contract.make {

    description 'Register event: Customer registered'

    label 'CustomerRegistered'

    input {
        // the contract will be triggered by a method
        triggeredBy('registerEvent()')
    }
    // output message of the contract
    outputMessage {
        // destination to which the output message will be sent
        sentTo 'ClassCustomerEvent'
        // the body of the output message
        body('''{"id":1,"eventType":"CustomerRegistered","entity": {"clientId":1,"clientName":"David, Suarez, Pascual","classCalendarId":1,"classCalendarName":"Aula 1 - Aerobic","classCalendarDayId":7}}''')
    headers {
        header('contentType', applicationJson())
    }
}

}
服务2:
应用程序.yml:

spring:
  cloud:
    stream:
      kafka:
        binder:
          brokers: localhost
          zkNodes: localhost
      default-binder: kafka

stubrunner:
  cloud:
    stubbed:
      discovery:
        enabled: false

stubrunner:
  stubsMode: LOCAL
  ids:
    - com.elipcero.classcustomerschool:classcustomer-school:1.0.0:stubs:8762

主要内容:

@SpringBootApplication
@EnableStubRunnerServer
@EnableBinding
@AutoConfigureStubRunner
public class ClassCustomerStubrunnerSchoolApplication {

    public static void main(String[] args) {

SpringApplication.run(ClassCustomerStubrunnerSchoolApplication.class, args);
}
}

服务3
烟雾试验:

@Test
public void should_calculate_client_total_by_classrooom_and_set_class_by_client() {

    mongoOperations.dropCollection("CustomerClass");
    mongoOperations.dropCollection("ClassCustomerDayTotal");

    String url = this.stubRunnerUrl + "/triggers/CustomerRegistered";

    log.info("Mongo collections deletes");
    log.info("Url stub runner boot: " + url);

    ResponseEntity<Map> response = this.restTemplate.postForEntity(url, "", Map.class);
    then(response.getStatusCode().is2xxSuccessful()).isTrue();

    log.info("Triggered customer event");

    await().until( () ->
         customerClassRepository
                 .findById(1)
                 .map((c) -> c.getClasses().isEmpty())
                 .orElse(false)
    );
 }

Flume:

@Service
@EnableBinding(ClassCustomerConsumer.class)
@RequiredArgsConstructor
public class ClassCustomerEvent {

    public static final String CONST_EVENT_CUSTOMER_REGISTERED = "CustomerRegistered";
    public static final String CONST_EVENT_CUSTOMER_UNREGISTERED = "CustomerUnregistered";

    @NonNull private ClassCustomerTotalView classCustomerTotalView;
    @NonNull private CustomerClassView customerClassView;

    @StreamListener(ClassCustomerConsumer.INPUT)
    public void ConsumeClassCustomerEvent(EventMessage<ClassCustomer> eventMessage) {
        classCustomerTotalView.calculate(eventMessage);
        customerClassView.selectOrUnSelected(eventMessage);
    }
}
l7wslrjt

l7wslrjt1#

在master中修复了spring-cloud-contract-v2.1.0.m2之后的下一个版本
问题参考:https://github.com/spring-cloud/spring-cloud-contract/pull/805

相关问题