繁体   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