curl post命令没有响应

0tdrvxhp  于 2021-06-07  发布在  Kafka
关注(0)|答案(0)|浏览(433)

我在学习 Event Sourcing and CQRS 在youtube上找到一个不错的视频系列。该系列在github中提供了一个代码存储库。它使用3个模块( barista , orders ,和 beans )为管理客户的咖啡订单,在分销网络中互相沟通。运行指令如下所示:,
启动apache kafka brokers,例如使用docker compose:https://github.com/wurstmeister/kafka-docker. 配置 KAFKA_ADVERTISED_HOST_NAME 到相应的ip地址。
配置每个 kafka.properties 文件 bootstrap.servers=<your-IP>:9092 .
构建并运行各个示例。在每个 orders/ , beans/ 以及 barista/ 目录,执行 build-run-local.sh . 这将构建gradle项目,构建docker映像并启动给定服务的新示例。
我无缝地遵循这些步骤。在我构建并运行各个示例之后,我执行命令,

$ curl http://localhost:8002/beans/resources/beans -i

    HTTP/1.1 200 OK
    Connection: keep-alive
    Content-Type: application/json
    Content-Length: 2
    Date: Tue, 08 Jan 2019 13:16:12 GMT

然后,我试着用命令发布一个bean,

$ curl http://localhost:8002/beans/resources/beans -i -XPOST \
      -H 'content-type: application/json' \
      -d '{"beanOrigin": "Colombia", "amount": 10}'

在这一点上,终端被挂起并且没有产生响应。我查看各个模块并看到 Dockerfile 以及 build-run-local.sh 执行指令。例如 Dockerfile 对于 beans 模块如下所示,

$ cat Dockerfile 

  FROM sdaschner/wildfly:javaee8-kafka-b1

  COPY build/libs/beans.war $DEPLOYMENT_DIR

这个 beans/build-run-local.sh 提供,

$ cat build-run-local.sh 

# !/bin/bash

cd ${0%/*}
set -eu

gradle build
docker build --rm -t scalable-coffee-shop-beans:1 .
docker run --rm --name beans -p 8002:8080 scalable-coffee-shop-beans:1

当我运行文件时,我得到输出(初始LNE),

$ ./build-run-local.sh 

BUILD SUCCESSFUL in 0s
5 actionable tasks: 5 up-to-date
Sending build context to Docker daemon  310.3kB

Step 1/2 : FROM sdaschner/wildfly:javaee8-kafka-b1
 ---> 7a638cd4a3c8

Step 2/2 : COPY build/libs/beans.war $DEPLOYMENT_DIR
 ---> Using cache
 ---> ef4901bbea66
Successfully built ef4901bbea66
Successfully tagged scalable-coffee-shop-beans:1
=========================================================================

  JBoss Bootstrap Environment

  JBOSS_HOME: /opt/jboss/wildfly

  JAVA: /usr/lib/jvm/java/bin/java

  JAVA_OPTS:  -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true

我的怀疑是因为我可能需要更多的配置而被挂掉了。例如,我没有配置 $DEPLOYMENT_DIR , JBOSS_HOME 或者 JAVA_OPTS 前面提到过。
我承认我在这方面的经验有限(或很少) Docker . 但是,我发现这个命令执行 Docker 文件,


# get 2 instructions from the `Dockerfile` and excutes them.

$ docker build --rm -t scalable-coffee-shop-beans:1 .

Sending build context to Docker daemon  310.3kB
Step 1/2 : FROM sdaschner/wildfly:javaee8-kafka-b1
 ---> 7a638cd4a3c8

Step 2/2 : COPY build/libs/beans.war $DEPLOYMENT_DIR
 ---> Using cache
 ---> ef4901bbea66
Successfully built ef4901bbea66
Successfully tagged scalable-coffee-shop-beans:1

有人能帮我正确运行这个应用程序吗?
更新:
我按照评论中的建议,把日志信息放进去。我得到的是:

03:26:12,271 INFO  [com.sebastian_daschner.scalable_coffee_shop.beans.boundary.BeansResource] (default task-1) Bean origin = Colombia , Amount = 10

03:26:12,273 INFO  [com.sebastian_daschner.scalable_coffee_shop.beans.boundary.BeanCommandService] (default task-1) Bean origin = Colombia , Amount = 1

所以看起来 com.sebastian_daschner.scalable_coffee_shop.beans.boundary.BeanCommandService 是否正确获取信息并调用类的方法 com.sebastian_daschner.scalable_coffee_shop.events.control.EventProducer 具体如下:,

public void storeBeans(final String beanOrigin, final int amount) {

        LOGGER.log(Level.INFO, "Bean origin = " + beanOrigin +
                " " + ", Amount = " + amount);
        eventProducer.publish(new BeansStored(beanOrigin, amount));
    }

内部 EventProducer ,它称为 publish 方法如下:,

public void publish(CoffeeEvent... events) {
        try {

            LOGGER.log(Level.INFO, "Events = " + Arrays.toString(events));

            producer.beginTransaction();
            send(events);
            producer.commitTransaction();
        } catch (ProducerFencedException e) {

            LOGGER.log(Level.SEVERE, e.toString(), e);
            producer.close();
        } catch (KafkaException e) {

            LOGGER.log(Level.SEVERE, e.toString(), e);
            producer.abortTransaction();
        }
    }

在这一点上,我没有从代码中得到任何日志,

LOGGER.log(Level.INFO, "Events = " + Arrays.toString(events));

我假设它与Kafka有关,下面的代码不会执行:

producer.beginTransaction();
     send(events);
     producer.commitTransaction();

正如我所指出的,现在有人能帮忙找出问题所在吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题