06-paralleltask-service

command
v0.0.0-...-e665a74 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2023 License: MIT Imports: 18 Imported by: 0

README

ParallelTask Service

  1. Slide ParallelTask Service

  2. Open directory

cd /root/automation-technology/chapter02-microservices/2.2-microservices-types/06-paralleltask-service
  1. Start kafka and zookeeper
docker compose up -d
  1. Wait until container is ready
docker ps
docker ps --format '{{.Image}}\t{{.Status}}\t{{.Ports}}'
CONTAINER ID   IMAGE                             COMMAND                  CREATED         STATUS         PORTS                                                           NAMES
77543ea5c2cf   3dsinteractive/kafka:2.0-custom   "/app-entrypoint.sh …"   4 minutes ago   Up 4 minutes   9092/tcp, 0.0.0.0:9094->9094/tcp, :::9094->9094/tcp             05-asynctask-service-kafka-1
151990488a46   3dsinteractive/zookeeper:3.0      "/app-entrypoint.sh …"   4 minutes ago   Up 4 minutes   2888/tcp, 0.0.0.0:2181->2181/tcp, :::2181->2181/tcp, 3888/tcp   05-asynctask-service-zookeeper-1
ffb869159a3b   3dsinteractive/redis:4.0          "/app-entrypoint.sh …"   4 minutes ago   Up 4 minutes   0.0.0.0:6379->6379/tcp, :::6379->6379/tcp                       05-asynctask-service-redis-1
  1. Run command to init project
go mod init automationworkshop/main
go mod tidy
  1. Run command to build project
go build .
  1. Run program
./main
  1. Run command
curl -X POST "localhost:8080/citizen/batch?task_id=email_a&worker_count=5" -d '{"input1":"value1"}'
{"task_id":"email_a"}
  1. Run command
curl -X GET "localhost:8080/citizen/batch?task_id=email_a"

The response can be formatted with jq

apt install -y jq
curl -X GET "localhost:8080/citizen/batch?task_id=email_a" | jq
{
  "status": "complete",
  "workers": [
    {
      "code": 200,
      "error": "",
      "response": {
        "result": "123"
      },
      "status": "complete",
      "worker_id": "ptask-email_a-4751997750760398084"
    },
    {
      "code": 200,
      "error": "",
      "response": {
        "result": "123"
      },
      "status": "complete",
      "worker_id": "ptask-email_a-7504504064263669287"
    },
    {
      "code": 200,
      "error": "",
      "response": {
        "result": "123"
      },
      "status": "complete",
      "worker_id": "ptask-email_a-1976235410884491574"
    },
    {
      "code": 200,
      "error": "",
      "response": {
        "result": "123"
      },
      "status": "complete",
      "worker_id": "ptask-email_a-3510942875414458836"
    },
    {
      "code": 200,
      "error": "",
      "response": {
        "result": "123"
      },
      "status": "complete",
      "worker_id": "ptask-email_a-2933568871211445515"
    }
  ]
}
  1. Run command to cleanup
docker compose down

Documentation

Overview

Create and maintain by Chaiyapong Lapliengtrakul (chaiyapong@3dsinteractive.com), All right reserved (2021 - Present)

Create and maintain by Chaiyapong Lapliengtrakul (chaiyapong@3dsinteractive.com), All right reserved (2021 - Present)

Create and maintain by Chaiyapong Lapliengtrakul (chaiyapong@3dsinteractive.com), All right reserved (2021 - Present)

Create and maintain by Chaiyapong Lapliengtrakul (chaiyapong@3dsinteractive.com), All right reserved (2021 - Present)

Create and maintain by Chaiyapong Lapliengtrakul (chaiyapong@3dsinteractive.com), All right reserved (2021 - Present)

Create and maintain by Chaiyapong Lapliengtrakul (chaiyapong@3dsinteractive.com), All right reserved (2021 - Present)

Create and maintain by Chaiyapong Lapliengtrakul (chaiyapong@3dsinteractive.com), All right reserved (2021 - Present)

Create and maintain by Chaiyapong Lapliengtrakul (chaiyapong@3dsinteractive.com), All right reserved (2021 - Present)

Create and maintain by Chaiyapong Lapliengtrakul (chaiyapong@3dsinteractive.com), All right reserved (2021 - Present)

Create and maintain by Chaiyapong Lapliengtrakul (chaiyapong@3dsinteractive.com), All right reserved (2021 - Present)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL