Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java cURL POST命令没有响应_Java_Docker_Apache Kafka_Cqrs_Event Sourcing - Fatal编程技术网

Java cURL POST命令没有响应

Java cURL POST命令没有响应,java,docker,apache-kafka,cqrs,event-sourcing,Java,Docker,Apache Kafka,Cqrs,Event Sourcing,我正在学习事件来源和CQR,并在Youtube上找到了一个不错的视频系列。该系列具有中给出的代码存储库。它使用3个模块(barista、orders和beans)在分布式环境中相互对话,以管理客户的咖啡订单。运行指令如下所示: public void storeBeans(final String beanOrigin, final int amount) { LOGGER.log(Level.INFO, "Bean origin = " + beanOrigin +

我正在学习
事件来源和CQR
,并在Youtube上找到了一个不错的视频系列。该系列具有中给出的代码存储库。它使用3个模块(
barista
orders
beans
)在分布式环境中相互对话,以管理客户的咖啡订单。运行指令如下所示:

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


        LOGGER.log(Level.INFO, "Bean origin = " + beanOrigin +
                " " + ", Amount = " + amount);
        eventProducer.publish(new BeansStored(beanOrigin, amount));
    }
  • 启动Apache Kafka代理,例如使用Docker compose:。 将卡夫卡播发的主机名配置到相应的IP 地址

  • 使用
    bootstrap.servers=:9092
    配置每个
    kafka.properties
    文件

  • 构建并运行各个实例。在每个
    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
    
    $ curl http://localhost:8002/beans/resources/beans -i -XPOST \
          -H 'content-type: application/json' \
          -d '{"beanOrigin": "Colombia", "amount": 10}'
    
    然后,我试着用命令发布一个bean

    $ 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
    
    $ curl http://localhost:8002/beans/resources/beans -i -XPOST \
          -H 'content-type: application/json' \
          -d '{"beanOrigin": "Colombia", "amount": 10}'
    
    在这一点上,终端被挂起并且不产生响应。我查看各个模块,看到带有执行指令的
    Dockerfile
    build run local.sh
    。例如,下面提供了
    bean
    模块的
    Dockerfile

    $ cat Dockerfile 
    
      FROM sdaschner/wildfly:javaee8-kafka-b1
    
      COPY build/libs/beans.war $DEPLOYMENT_DIR
    
    提供了
    bean/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)

    我的怀疑是因为我可能需要更多的配置,而我错过了,所以邮政司令部被绞死了。例如,我没有配置前面提到的
    $DEPLOYMENT\u DIR
    JBOSS\u HOME
    JAVA\u 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\u daschner.scalable\u coffee\u shop.beans.boundary.BeanCommandService
    似乎正确地获取了信息,并调用了类
    com.sebastian\u daschner.scalable\u coffee\u 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));
    
    我假设它与卡夫卡有关,下面的代码不会执行:

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

    正如我所指出的,现在是否有人可以帮助找出问题所在?

    如果不亲自下载Github代码,很难判断问题出在哪里。。。可能是卡夫卡,也可能是网络服务器。我建议添加更多日志语句,或者在这些Java进程中启用远程调试,以发现问题您真正需要调用
    producer.beginTransaction()
    producer.commitTransaction()吗
    ??@cricket\u 007我更新了这个问题,为调查提供了更好的信息。但是如果你甚至还没有开始看到
    数组。toString(events)
    记录器,那么问题听起来好像不是卡夫卡明白,但你需要事务吗?(这是卡夫卡的一项新功能)你不能单独发送和确认每条消息吗?