我正在编写一个用于学习目的的弹簧反应式应用程序,它以1秒的间隔生成响应,现在我可以使用curl
查看终端中收到的响应,但我无法使用客户端访问它我写的。
在运行客户端代码时,我在调试模式中遇到了很多错误。
错误很大,我已将其粘贴到此link。
以下是主要客户代码:
WebClient webClient = WebClient.create("http://localhost:8080");
while (true) {
Mono<Custom> customResponseMono = webClient.get().uri("/test").accept(MediaType.APPLICATION_STREAM_JSON).retrieve().bodyToMono(Custom.class);
equityResponseMono.subscribe(customized -> {
System.out.println(customized.toString());
});
}
我不确定在这个中我错过了什么或做错了什么。
更新-1 我现在可以用一些奇怪的格式看到答案。
任何人都可以解释一下这是什么?
+-------------------------------------------------+
| 0 1 2 3 4 5 6 7 8 9 a b c d e f |
+--------+-------------------------------------------------+----------------+
|00000000| 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d |HTTP/1.1 200 OK.|
|00000010| 0a 74 72 61 6e 73 66 65 72 2d 65 6e 63 6f 64 69 |.transfer-encodi|
|00000020| 6e 67 3a 20 63 68 75 6e 6b 65 64 0d 0a 43 6f 6e |ng: chunked..Con|
|00000030| 74 65 6e 74 2d 54 79 70 65 3a 20 61 70 70 6c 69 |tent-Type: appli|
|00000040| 63 61 74 69 6f 6e 2f 73 74 72 65 61 6d 2b 6a 73 |cation/stream+js|
|00000050| 6f 6e 3b 63 68 61 72 73 65 74 3d 55 54 46 2d 38 |on;charset=UTF-8|
|00000060| 0d 0a 0d 0a 33 30 0d 0a 7b 22 65 71 75 69 74 79 |....30..{"custom|
|00000070| 49 64 22 3a 38 37 2c 22 65 71 75 69 74 79 50 72 |Id":87,"customPr|
|00000080| 69 63 65 22 3a 38 37 2e 34 31 32 38 30 39 34 33 |ice":87.41280943|
|00000090| 35 33 31 39 38 34 7d 0a 0d 0a 33 31 0d 0a 7b 22 |531984}...31..{"|
|000000a0| 65 71 75 69 74 79 49 64 22 3a 34 33 2c 22 65 71 |customId":43,"cu|
|000000b0| 75 69 74 79 50 72 69 63 65 22 3a 32 33 30 2e 39 |stomPrice":230.9|
|000000c0| 36 35 30 39 38 32 31 34 36 37 34 35 35 7d 0a 0d |6509821467455}..|
|000000d0| 0a 33 31 0d 0a 7b 22 65 71 75 69 74 79 49 64 22 |.31..{"customId"|
|000000e0| 3a 31 31 2c 22 65 71 75 69 74 79 50 72 69 63 65 |:11,"customPrice|
|000000f0| 22 3a 31 32 31 2e 32 36 35 31 32 35 34 30 38 34 |":121.2651254084|
|00000100| 39 30 38 33 7d 0a 0d 0a 32 66 0d 0a 7b 22 65 71 |9083}...2f..{"cu|
|00000110| 75 69 74 79 49 64 22 3a 35 39 2c 22 65 71 75 69 |tomId":59,"custo|
|00000120| 74 79 50 72 69 63 65 22 3a 35 32 2e 33 38 32 32 |mPrice":52.13822|
|00000130| 35 32 39 37 31 35 30 36 34 7d 0a 0d 0a 33 31 0d |529715064}...31.|
|00000140| 0a 7b 22 65 71 75 69 74 79 49 64 22 3a 32 30 2c |.{"customId":20,|
|00000150| 22 65 71 75 69 74 79 50 72 69 63 65 22 3a 32 34 |"customPrice":24|
|00000160| 38 2e 33 39 30 38 30 32 36 35 37 30 31 32 31 33 |8.39080265701213|
|00000170| 7d 0a 0d 0a 33 31 0d 0a 7b 22 65 71 75 69 74 79 |}...31..{"custom|
|00000180| 49 64 22 3a 31 32 2c 22 65 71 75 69 74 79 50 72 |Id":12,"customPr|
|00000190| 69 63 65 22 3a 32 34 30 2e 34 31 38 38 35 34 35 |ice":240.4188545|
|000001a0| 37 37 32 39 39 30 32 7d 0a 0d 0a 33 31 0d 0a 7b |7729902}...31..{|
|000001b0| 22 65 71 75 69 74 79 49 64 22 3a 39 38 2c 22 65 |"customId":98,"c|
|000001c0| 71 75 69 74 79 50 72 69 63 65 22 3a 32 30 37 2e |ustomPrice":207.|
|000001d0| 35 35 39 31 36 35 32 36 36 34 38 37 35 33 7d 0a |55916526648753}.|
|000001e0| 0d 0a 33 30 0d 0a 7b 22 65 71 75 69 74 79 49 64 |..30..{"customId|
|000001f0| 22 3a 34 30 2c 22 65 71 75 69 74 79 50 72 69 63 |":40,"customPric|
|00000200| 65 22 3a 31 30 37 2e 36 33 37 33 34 30 34 35 37 |e":107.637340457|
|00000210| 37 39 36 36 7d 0a 0d 0a 33 30 0d 0a 7b 22 65 71 |7966}...30..{"cu|
|00000220| 75 69 74 79 49 64 22 3a 37 34 2c 22 65 71 75 69 |stomId":74,"cust|
|00000230| 74 79 50 72 69 63 65 22 3a 31 39 34 2e 34 39 33 |omPrice":194.493|
|00000240| 34 31 36 33 35 32 30 30 31 38 7d 0a 0d 0a 33 31 |4163520018}...31|
|00000250| 0d 0a 7b 22 65 71 75 69 74 79 49 64 22 3a 33 39 |..{"customId":39|
|00000260| 2c 22 65 71 75 69 74 79 50 72 69 63 65 22 3a 31 |,"customPrice":1|
|00000270| 37 36 2e 39 35 33 34 32 36 34 30 39 35 36 34 31 |76.9534264095641|
|00000280| 34 7d 0a 0d 0a 33 31 0d 0a 7b 22 65 71 75 69 74 |4}...31..{"custo|
|00000290| 79 49 64 22 3a 39 31 2c 22 65 71 75 69 74 79 50 |mId":91,"customP|
|000002a0| 72 69 63 65 22 3a 30 2e 36 31 31 37 34 35 30 39 |rice":0.61174509|
|000002b0| 32 33 38 35 35 34 30 35 7d 0a 0d 0a 33 30 0d 0a |23855405}...30..|
|000002c0| 7b 22 65 71 75 69 74 79 49 64 22 3a 32 30 2c 22 |{"customId":20,"|
|000002d0| 65 71 75 69 74 79 50 72 69 63 65 22 3a 31 38 33 |customPrice":183|
|000002e0| 2e 30 37 32 30 32 37 38 30 35 31 33 37 37 7d 0a |.0720278051377}.|
|000002f0| 0d 0a 33 30 0d 0a 7b 22 65 71 75 69 74 79 49 64 |..30..{"customId|
|00000300| 22 3a 32 39 2c 22 65 71 75 69 74 79 50 72 69 63 |":29,"customPric|
|00000310| 65 22 3a 39 33 2e 33 37 38 34 39 38 32 32 30 33 |e":93.3784982203|
|00000320| 31 38 32 34 7d 0a 0d 0a 33 31 0d 0a 7b 22 65 71 |1824}...31..{"cu|
|00000330| 75 69 74 79 49 64 22 3a 39 38 2c 22 65 71 75 69 |stomId":98,"cust|
|00000340| 74 79 50 72 69 63 65 22 3a 31 31 38 2e 33 36 33 |omPrice":118.363|
|00000350| 33 37 38 36 37 39 39 31 31 37 33 7d 0a 0d 0a 33 |37867991173}...3|
|00000360| 31 0d 0a 7b 22 65 71 75 69 74 79 49 64 22 3a 38 |1..{"customId":8|
|00000370| 37 2c 22 65 71 75 69 74 79 50 72 69 63 65 22 3a |7,"customPrice":|
|00000380| 31 33 37 2e 35 38 37 34 38 35 30 39 30 39 30 32 |137.587485090902|
|00000390| 35 36 7d 0a 0d 0a 33 31 0d 0a 7b 22 65 71 75 69 |56}...31..{"cust|
|000003a0| 74 79 49 64 22 3a 39 32 2c 22 65 71 75 69 74 79 |omId":92,"custom|
|000003b0| 50 72 69 63 65 22 3a 32 32 32 2e 30 37 30 34 31 |Price":222.07041|
|000003c0| 36 37 34 35 36 35 38 39 32 7d 0a 0d 0a 33 31 0d |674565892}...31.|
|000003d0| 0a 7b 22 65 71 75 69 74 79 49 64 22 3a 38 33 2c |.{"customId":83,|
|000003e0| 22 65 71 75 69 74 79 50 72 69 63 65 22 3a 32 31 |"customPrice":21|
|000003f0| 31 2e 37 32 31 36 37 30 32 33 38 34 35 33 39 32 |1.72167023845392|
+--------+-------------------------------------------------+----------------+
我将代码更改为以下内容:
WebClient webClient = WebClient.create("http://localhost:8080");
while (true) {
Flux<Custom> customResponseMono = webClient.get().uri("/test").accept(MediaType.APPLICATION_STREAM_JSON).retrieve().bodyToFlux(Custom.class);
equityResponseMono.subscribe(customized -> {
System.out.println(customized.getCustomId());
});
}
但它是以上述方式打印输出。我这样做了吗?