GithubHelp home page GithubHelp logo

order-service's Introduction

Order microservice

This exercise is about to showcase a reactive microservice ecosystem with Kafka distributed event streaming platform.
Using JDK 17 with Spring framework components (Core, Boot, Web, MVC, Cloud, WebFlux, Actuator, Data JPA).
For the JPA based implementations I use H2 in memory DB but later I plan to replace it with Redis to access data reactively as well.
REST API is created with Spring WebFlux, which is a fully non-blocking web stack - it can do more work with fewer resources - and supports back pressure.
At the moment only the server side is implemented in a reactive way but later I will do the same for the client side with the help of WebClient.

See more about reactive programming: https://reactivemanifesto.org/

Until this moment we have an order-service which exposes below REST interfaces and it's going to consume the order-details-service (https://github.com/szintia/order-details-service) in order to validate the order.

API Endpoints

Methods Urls Actions

POST        /order          create a new order in case it's valid
GET         /orders         retrieve all orders

Technical details:

Local port is set to 8081

After running the application, you can find

Setting up Kafka on Windows

  1. Download Kafka (includes Zookeeper): https://www.apache.org/dyn/closer.cgi?path=/kafka/

  2. After extracting, start Zookeeper service via zookeeper-server-start.bat command. For local development 1 node will be sufficient.

    D:\kafka\kafka_2.13-3.6.1>.\bin\windows\zookeeper-server-start.bat .\config\zookeeper.properties By default it listens to port 2181.

        [2023-12-14 16:15:31,174] INFO clientPortAddress is 0.0.0.0:2181 (org.apache.zookeeper.server.quorum.QuorumPeerConfig)
  3. Start Kafka via kafka-server-start.bat command in a new cmd:

    D:\kafka\kafka_2.13-3.6.1>.\bin\windows\kafka-server-start.bat .\config\server.properties

    It's connected to Zookeeper:

   [2023-12-14 16:17:38,748] INFO Connecting to zookeeper on localhost:2181 (kafka.server.KafkaServer)

   [2023-12-14 16:17:40,014] INFO Registered broker 0 at path /brokers/ids/0 with addresses: PLAINTEXT://3B1811282:9092, czxid (broker epoch): 25 (kafka.zk.KafkaZkClient)

Default port is 9092. In the command prompt we can see all the configurations.

  1. Let's create a topic, open a new cmd and use the kafka-topics.bat command:

    D:\kafka\kafka_2.13-3.6.1>.\bin\windows\kafka-topics.bat --create --topic orders --bootstrap-server localhost:9092

    Created topic orders.
  2. To get some info about the partition, replication, use kafka-topics.bat command with --describe:

    D:\kafka\kafka_2.13-3.6.1>.\bin\windows\kafka-topics.bat --describe --topic orders --bootstrap-server localhost:9092

    Topic: orders   TopicId: F2JeuSm2Rw2qquuGL7RWgg PartitionCount: 1       ReplicationFactor: 1    Configs:
    Topic: orders   Partition: 0    Leader: 0       Replicas: 0     Isr: 0
  3. Testing Producer via kafka-console-producer.bat command

    D:\kafka\kafka_2.13-3.6.1>.\bin\windows\kafka-console-producer.bat --topic orders --bootstrap-server localhost:9092 After that we can add some events.

   >Testing producer with an event
  1. Testing Consumer side, let's see what we have:

    D:\kafka\kafka_2.13-3.6.1>.\bin\windows\kafka-console-consumer.bat --topic orders --from-beginning --bootstrap-server localhost:9092

   Testing producer with an event

More info can be found on the following Apache Kafka site: https://kafka.apache.org/quickstart#quickstart_send

Sending message to Kafka topic

After the setup of Kafka we can now send messages to the topic called "orders" via Swagger UI - POST HTTP method.

image

Building and verifying Dockerfile

To create our own Docker image, the executable artifact from the order service, we need to

  1. build the Dockerfile (committed to the project) with a tag 1.0 and with a name "my-app":
    docker build -t my-app:1.0 .
    Image is built:
    image image

  2. verify our order service starts successfully
    docker run -d -p 8081:8081 my-app:1.0 -> run Docker image = so basically to run our app in a Docker container with port binding, I set the app to listen to port 8081 on host, same as the container's port.
    docker ps -> list running containers
    image
    Swagger UI is now available on port 8081: image

So until now we are able to run our order service in a Docker container but we will need also Kafka with Zookeeper. This will result in a multi-container application --> Let's use Docker Compose to define the services I need.
TO BE CONTINUED.

order-service's People

Contributors

szintia avatar

Watchers

 avatar

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.