簡體   English   中英

如何創建 REST API 然后 REST API 會將對象/字符串放入 ActiveMQ

[英]how to create an REST API then the REST API will put object/string to ActiveMQ

我正在嘗試實現 spring-boot 駱駝。 我應該創建一個 REST API,然后 REST API 會將對象/字符串放入 ActiveMQ。 我已經做好了 :

 rest("/test/").description("Teste REST Service")
        .id("api-route")
        .post("/bean")
        .consumes(MediaType.APPLICATION_JSON_VALUE)
        .produces(MediaType.APPLICATION_JSON_VALUE)
        .bindingMode(RestBindingMode.auto)
        .type(User.class)
        .enableCORS(true)
        .to("seda:next");

        from("seda:next")
        .routeId("direct-route")
        .tracing()
        .log(">>> ${body.id}")
        .log(">>> ${body.name}")
        .transform().simple("Hello ${in.body.name}")
        .to("activemq:queue:foo")
      //  .to("direct:remoteService1")
        ; 

錯誤日志 ================================================ ========:

2019-12-05 19:51:19.750  INFO 23436 --- [ActiveMQ Task-1] o.a.a.t.failover.FailoverTransport       : Successfully connected to tcp://localhost:61616
2019-12-05 19:51:19.775  INFO 23436 --- [ActiveMQ Task-1] o.a.a.t.failover.FailoverTransport       : Successfully connected to tcp://localhost:61616
2019-12-05 19:51:40.553  WARN 23436 --- [rOnTimeout[foo]] o.a.c.c.j.r.TemporaryQueueReplyManager   : Timeout occurred after 20000 millis waiting for reply message with correlationID [Camel-ID-DESKTOP-PJH5GNF-1575550269030-0-7] on destination temp-queue://ID:DESKTOP-PJH5GNF-58146-1575550279560-1:1:1. Setting ExchangeTimedOutException on (MessageId: ID-DESKTOP-PJH5GNF-1575550269030-0-2 on ExchangeId: ID-DESKTOP-PJH5GNF-1575550269030-0-3) and continue routing.
2019-12-05 19:51:40.583 ERROR 23436 --- [rOnTimeout[foo]] o.a.camel.processor.DefaultErrorHandler  : Failed delivery for (MessageId: ID-DESKTOP-PJH5GNF-1575550269030-0-2 on ExchangeId: ID-DESKTOP-PJH5GNF-1575550269030-0-3). Exhausted after delivery attempt: 1 caught: org.apache.camel.ExchangeTimedOutException: The OUT message was not received within: 20000 millis due reply message with correlationID: Camel-ID-DESKTOP-PJH5GNF-1575550269030-0-7 not received on destination: temp-queue://ID:DESKTOP-PJH5GNF-58146-1575550279560-1:1:1. Exchange[ID-DESKTOP-PJH5GNF-1575550269030-0-3]


---------------------------------------------------------------------------------------------------------------------------------------
RouteId              ProcessorId          Processor                                                                        Elapsed (ms)
[direct-route      ] [direct-route      ] [seda://next                                                                   ] [     21171]
[route8            ] [to7               ] [seda:next                                                                     ] [         0]
[direct-route      ] [log1              ] [log                                                                           ] [        21]
[direct-route      ] [log2              ] [log                                                                           ] [         0]
[direct-route      ] [transform1        ] [transform[simple{Hello ${in.body.name}}]                                      ] [         1]
[direct-route      ] [to2               ] [activemq:queue:foo                                                            ] [         0]
---------------------------------------------------------------------------------------------------------------------------------------

org.apache.camel.ExchangeTimedOutException: The OUT message was not received within: 20000 millis due reply message with correlationID: Camel-ID-DESKTOP-PJH5GNF-1575550269030-0-7 not received on destination: temp-queue://ID:DESKTOP-PJH5GNF-58146-1575550279560-1:1:1. Exchange[ID-DESKTOP-PJH5GNF-1575550269030-0-3]
    at org.apache.camel.component.jms.reply.ReplyManagerSupport.processReply(ReplyManagerSupport.java:169) ~[camel-jms-3.0.0-M1.jar:3.0.0-M1]
    at org.apache.camel.component.jms.reply.TemporaryQueueReplyHandler.onTimeout(TemporaryQueueReplyHandler.java:60) ~[camel-jms-3.0.0-M1.jar:3.0.0-M1]
    at org.apache.camel.component.jms.reply.CorrelationTimeoutMap$1.run(CorrelationTimeoutMap.java:58) ~[camel-jms-3.0.0-M1.jar:3.0.0-M1]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[na:1.8.0_171]
    at java.util.concurrent.FutureTask.run(Unknown Source) ~[na:1.8.0_171]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[na:1.8.0_171]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[na:1.8.0_171]
    at java.lang.Thread.run(Unknown Source) ~[na:1.8.0_171]

如果您希望從您的消息回復到您的 foo 隊列,那么您需要通過發送 inOnly 類型交換來告訴 activeMQ 您不希望收到回復,否則它將創建一個臨時隊列並等待回復:

from("seda:next")
    .routeId("direct-route")
    .tracing()
    .log(">>> ${body.id}")
    .log(">>> ${body.name}")
    .transform().simple("Hello ${in.body.name}")
    .inOnly("activemq:queue:foo")

這將導致您的“Hello Name”消息作為seda:next的結果返回,從而返回到 rest 調用。

或者,你可以有

.inOnly("seda:next")

在您的第一條路線中,如果您不想要來自“下一個”路線的響應,我認為這意味着您的休息調用將獲得原始輸入類作為響應(但不要引用我的話)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM