Git Product home page Git Product logo

art-kargopolov-cqrs-saga-axon-microservices's People

Contributors

artshishkin avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

art-kargopolov-cqrs-saga-axon-microservices's Issues

119. Assignment

  1. Create a new Spring Boot Project
    • Call this new project "UsersService".
  2. Dependencies
    • spring-boot-starter-web
    • axon-spring-boot-starter
    • core (a project with shared classes we have created)
  3. Create PaymentDetails class
    • In the Core project, create a new PaymentDetails class with the following fields.
    private final String name;
    private final String cardNumber;
    private final int validUntilMonth;
    private final int validUntilYear;
    private final String cvv;
    
    • Annotate this class with @DaTa and @builder Lombok annotations and place this class into core.model package.
  4. Create User object
    • In the Core project, create a new User class with the following fields.
    private final String firstName;
    private final String lastName;
    private final String userId;
    private final PaymentDetails paymentDetails;
    
    • Annotate this class with @DaTa and @builder Lombok annotations and place this class into core.model package.
  5. Create FetchUserPaymentDetailsQuery
    • In the Core project, create a FetchUserPaymentDetailsQuery class with a single instance property for userId and place this class into a core.query package.
    private String userId;
    
  6. Create UserEventsHandler
    • In the UsersService project, create a new UserEventsHandler class annotated with @component annotation. In this class create a single method annotated with @QueryHandler. Make this method accept FetchUserPaymentDetailsQuery as a method argument and return an instance of a User object with hard-coded details. For example,
    PaymentDetails paymentDetails = PaymentDetails.builder()
        .cardNumber("123Card")
        .cvv("123")
        .name("SERGEY KARGOPOLOV")
        .validUntilMonth(12)
        .validUntilYear(2030)
        .build();
    
    User userRest = User.builder()
        .firstName("Sergey")
        .lastName("Kargopolov")
        .userId(query.getUserId())
        .paymentDetails(paymentDetails)
        .build();
    

125. PaymentsMicroservice - Assignment

  1. Create a new Spring Boot Project
    • Create a new Spring Boot project using either Spring Initializer Tool or using your Development environment.
    • Call this new project "PaymentsService".
  2. Dependencies
    • spring-boot-starter-web
    • axon-spring-boot-starter
    • Lombok
    • spring-boot-starter-data-jpa
    • h2
  3. PaymentAggregate class
    • Create a new class called PaymentAggregate, make it handle the ProcessPaymentCommand, and publish the PaymentProcessedEvent.
    • The PaymentProcessedEvent class will have the following fields:
    private final String orderId;
    private final String paymentId;
    
    • The PaymentAggregate class should also have an @EventSourcingHandler method that sets values for all fields in the PaymentAggregate.
    • Note: Place the PaymentProcessedEvent into a shared core project.
  4. Validate the ProcessPaymentCommand
    • In the PaymentAggregate class, add a little code to validate the ProcessPaymentCommand. If one of the required fields contains an invalid value, then throw an IllegalArumentException.
  5. Create PaymentEventsHandler class
    • Create a new @Component class called PaymentEventsHandler.
    • Create a new JPA Repository called PaymentsRepository and inject it into PaymentEventsHandler using constructor-based dependency injection.
    • The PaymentEventsHandler class should have one @EventHandler method that handles the PaymentProcessedEvent and persists payment details into the "read" database.
    • To persist payment details into the database, create a new JPA Entity class called PaymentEntity. Annotate the PaymentEntity class with:
    @Entity
    @Table(name = "payments")
    
    • and make the PaymentEntity class have the following fields:
    @Id
    private String paymentId;
    @Column
    public String orderId;
    
  6. Database
    • Since each Microservice should store data in its own database, configure Payments Microservice to work with a new database called "payments".

Fix ProductAggregateErrorHandlingTest.createProduct_errorInProductAggregate

Error:  Failures: 
Error:    ProductAggregateErrorHandlingTest.createProduct_errorInProductAggregate:45 
Multiple Failures (1 failure)
-- failure 1 --
Expecting actual:
  2022-07-28T18:53:20.959867 (java.time.LocalDateTime)
to have same year, month, day, hour, minute and second as:
  2022-07-28T18:53:21.013301 (java.time.LocalDateTime)
but had not.

Section 15: Assignment. Orders Microservice

  1. Create a new Spring Boot Project

    • Create a new Spring Boot project using either Spring Initializer Tool(https://start.spring.io) or using your Development environment.
    • Call this new project "OrdersService"
  2. Dependencies

    • Add the following dependencies to your OrdersService Spring Boot project.
      • spring-boot-starter-web
      • Eureka (spring-cloud-starter-netflix-eureka-client)
      • Google Guava
      • spring-boot-starter-validation
      • axon-spring-boot-starter
      • Lombok
      • spring-boot-starter-data-jpa
      • h2
  3. Create OrdersCommandController

    • Create a new OrdersCommandController class with a request mapping "/orders" and one method that accepts the HTTP POST request.
    • The method that accepts the HTTP Post request, should accept the following JSON payload as a request body.
    {
        "productId":"f241af45-4854-43f4-95bc-ab54da338a29",
        "quantity":1,
        "addressId":"afbb5881-a872-4d13-993c-faeb8350eea5"
    }
    
    • This controller class should use the CommandGateway and publish the CreateOrderCommand.
    • The CreateOrderCommand should have the following fields.
    public final String orderId;
    private final String userId;
    private final String productId;
    private final int quantity;
    private final String addressId;
    private final OrderStatus orderStatus;
    
    • Where:
      • orderId - is a randomly generated value. For example, UUID.randomUUID().toString()
      • userId - is a static hard-coded value: 27b95829-4f3f-4ddf-8983-151ba010e35b. At this moment there is no user registration, authentication, and authorization implemented, so we will hard code the value of userId for now.
      • orderStatus - is an Enum with the following content:
      public enum OrderStatus {
        CREATED, APPROVED, REJECTED
      }
      
  4. OrderAggregate class

    • Create a new class called OrderAggregate and make it handle the CreateOrderCommand and publish the OrderCreatedEvent.
    • The OrderCreatedEvent class should have the following fields:
    private String orderId;
    private String productId;
    private String userId;
    private int quantity;
    private String addressId;
    private OrderStatus orderStatus;
    
    • The OrderAggregate class should also have an @EventSourcingHandler method that sets values for all fields in the OrderAggregate.
  5. Create OrderEventsHandler class

    • Create a new @component class called OrderEventsHandler.
    • Create a new JPA Repository called OrdersRepository and inject it into OrderEventsHandler using constructor-based dependency injection.
    • The OrderEventHandler class should have one @eventhandler method that handles the OrderCreatedEvent and persists order details into the "read" database.
    • To persist order details into the database, create a new JPA Entity class called OrderEntity. Annotate the OrderEntity class with:
    @Entity
    @Table(name = "orders")
    
    • and make the OrderEntity class have the following fields:
    @Id
    @Column(unique = true)
    public String orderId;
    private String productId;
    private String userId;
    private int quantity;
    private String addressId;
    @Enumerated(EnumType.STRING)
    private OrderStatus orderStatus;
    
  6. Register with Eureka

    • Make OrdersService microservice register with Eureka as a Client.
  7. Database

    • Since each Microservice should store data in its own database, configure this Microservice to work with a new database called "orders".
  8. Run and make it work

    • Run your OrdersService microservice and make it work. Send a request with the following JSON and make sure it gets successfully stored in the read database. Since you have annotated the OrderEntity class with @table(name = "orders"), the database table name will be "orders".
    {
      "productId":"f241af45-4854-43f4-95bc-ab54da338a29",
      "quantity":1,
      "addressId":"afbb5881-a872-4d13-993c-faeb8350eea5"
    }
    
  9. Verify results

    • Check the Event Store in the Axon server and make sure that the OrderCreatedEvent gets persisted,
    • Using the /h2-console connect to the Orders database and make sure that the order details are stored there as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.