Spring Boot - Flux and RequestBody

  • Controller
  • @RestController
    public class RequestBodyController {

        @PostMapping("/requestBodyFlux")
        public Mono<Void> postFlux(@RequestBody Flux<String> ids) {
            return ids.map(id -> {
                String s = "id:" + id;
                System.out.println(s);
                return s;
            }).then();
        }

    }

  • Client
  • isaac@isaac-PC MINGW64 ~/workspace_github
    $ curl -s -v -H 'Content-Type:application/json' -X POST -d '["a","b","c"]'  http://localhost:8080/requestBodyFlux
    *   Trying ::1...
    * TCP_NODELAY set
    * Connected to localhost (::1) port 8080 (#0)
    > POST /requestBodyFlux HTTP/1.1
    > Host: localhost:8080
    > User-Agent: curl/7.60.0
    > Accept: */*
    > Content-Type:application/json
    > Content-Length: 13
    >
    } [13 bytes data]
    * upload completely sent off: 13 out of 13 bytes
    < HTTP/1.1 200 OK
    < content-length: 0
    <
    * Connection #0 to host localhost left intact

  • Server
  • C:\Users\isaac\workspace_github\spring-boot-study>gradle bootRun
    Starting a Gradle Daemon, 4 busy Daemons could not be reused, use --status for details

    > Task :bootRun

      .   ____          _            __ _ _
    /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
    ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
    \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
      '  |____| .__|_| |_|_| |_\__, | / / / /
    =========|_|==============|___/=/_/_/_/
    :: Spring Boot ::        (v2.2.7.RELEASE)

    2020-05-17 01:51:11.297  INFO 4060 --- [  restartedMain] com.example.demo.DemoApplication         : Starting DemoApplication on isaac-PC with PID 4060 (C:\Users\isaac\workspace_github\spring-boot-study\build\classes\java\main started by isaac in C:\Users\
    isaac\workspace_github\spring-boot-study)
    2020-05-17 01:51:11.300  INFO 4060 --- [  restartedMain] com.example.demo.DemoApplication         : No active profile set, falling back to default profiles: default
    2020-05-17 01:51:11.364  INFO 4060 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
    2020-05-17 01:51:11.364  INFO 4060 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
    2020-05-17 01:51:14.302  INFO 4060 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
    2020-05-17 01:51:14.634  INFO 4060 --- [  restartedMain] o.s.b.web.embedded.netty.NettyWebServer  : Netty started on port(s): 8080
    2020-05-17 01:51:14.638  INFO 4060 --- [  restartedMain] com.example.demo.DemoApplication         : Started DemoApplication in 3.781 seconds (JVM running for 4.585)
    id:["a","b","c"]


沒有留言:

張貼留言

別名演算法 Alias Method

 題目 每個伺服器支援不同的 TPM (transaction per minute) 當 request 來的時候, 系統需要馬上根據 TPM 的能力隨機找到一個適合的 server. 雖然稱為 "隨機", 但還是需要有 TPM 作為權重. 解法 別名演算法...