use of com.github.wenqiglantz.service.customerservice.data.event.CustomerWasCreated in project customer-service by wenqiglantz.
the class CustomerServiceImpl method saveCustomer.
@Override
public CustomerInfo saveCustomer(CustomerInfo customerInfo) throws Exception {
customerInfo.setCustomerId(Strings.isBlank(customerInfo.getCustomerId()) ? UUID.randomUUID().toString() : customerInfo.getCustomerId());
Customer customer = Customer.builder().customerId(customerInfo.getCustomerId()).firstName(customerInfo.getFirstName()).lastName(customerInfo.getLastName()).build();
customerRepository.save(customer);
CustomerWasCreated customerWasCreated = CustomerWasCreated.builder().customerId(customerInfo.getCustomerId()).firstName(customerInfo.getFirstName()).lastName(customerInfo.getLastName()).status(CustomerStatus.CREATED).build();
log.info("publish event {} ", customerWasCreated);
// initialize dapr client in try-with-resource block to properly close the client at the end
try (DaprClient client = new DaprClientBuilder().build()) {
client.publishEvent(PUBSUB_NAME, TOPIC_ORDER_SERVICE, customerWasCreated, singletonMap(Metadata.TTL_IN_SECONDS, MESSAGE_TTL_IN_SECONDS)).block();
}
return customerInfo;
}
use of com.github.wenqiglantz.service.customerservice.data.event.CustomerWasCreated in project customer-service by wenqiglantz.
the class CustomerEventsPublishPactVerificationTest method publishCustomerWasCreated.
@PactVerifyProvider("valid CustomerWasCreated from provider")
public String publishCustomerWasCreated() throws Exception {
CustomerInfo customerInfo = CustomerInfo.builder().customerId("595eed0c-eff5-4278-90ad-b952f18dbee8").firstName("test").lastName("last").build();
CustomerWasCreated event = CustomerWasCreated.builder().customerId("595eed0c-eff5-4278-90ad-b952f18dbee8").firstName("test").lastName("last").status(CustomerStatus.CREATED).build();
context.checking(new Expectations() {
{
oneOf(customerService).saveCustomer(customerInfo);
}
});
customerService.saveCustomer(customerInfo);
String eventString = objectMapper.writeValueAsString(event);
return eventString;
}
Aggregations