title: Spring Cloud Stub Runner Boot Application and Cloud Stream (Kafka) for Smoke Test
body: <p>In a microservice architecture I have three services. The first one creates a message in a kafka queue with spring cloud stream. In this service I use spring cloud contract to generate a contract. The second service is a spring cloud stub runner boot service that reads the contracts of the first service and exposes them to the third service. The third service does smoke test against the stub runner service using the endpont /triiggers/{label}. I understand that when I call to /triggers/{label} the service stub runner should send the message created in the service contract to the kafka queue, but never it send it to the queue. How can I do the stub runner service send the message of the contract to the kafka queue?.
  Thanks</p>
  
  <p>Code:</p>
  
  <p><strong>Service 1</strong></p>
  
  <p>Contract:</p>
  
  <pre><code>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())
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Service 2:</strong></p>
  
  <p>application.yml:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Main:</p>
  
  <pre><code>@SpringBootApplication
  @EnableStubRunnerServer
  @EnableBinding
  @AutoConfigureStubRunner
  public class ClassCustomerStubrunnerSchoolApplication {
  
      public static void main(String[] args) {
  
  SpringApplication.run(ClassCustomerStubrunnerSchoolApplication.class, args);
  }
  }
  </code></pre>
  
  <p><strong>Service 3</strong></p>
  
  <p>SmokeTest:</p>
  
  <pre><code>@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&lt;Map&gt; response = this.restTemplate.postForEntity(url, "", Map.class);
      then(response.getStatusCode().is2xxSuccessful()).isTrue();
  
      log.info("Triggered customer event");
  
      await().until( () -&gt;
           customerClassRepository
                   .findById(1)
                   .map((c) -&gt; c.getClasses().isEmpty())
                   .orElse(false)
      );
   }
  </code></pre>
  
  <p>Sink:</p>
  
  <pre><code>@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&lt;ClassCustomer&gt; eventMessage) {
          classCustomerTotalView.calculate(eventMessage);
          customerClassView.selectOrUnSelected(eventMessage);
      }
  }
  </code></pre>