wahyu eko hadi saputro
wahyu eko hadi saputro

Reputation: 427

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

i am trying to implement spring-boot camel. i should create an REST API then the REST API will put object/string to ActiveMQ. i have done :

 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")
        ; 

Error Logs =======================================================:

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]

Upvotes: 0

Views: 174

Answers (1)

Screwtape
Screwtape

Reputation: 1367

If you are not expecting a reply from your message into your foo queue, then you need to tell activeMQ you are not expecting a reply by sending an inOnly type exchange, or it will create a temporary queue and await a reply:

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

This will result in your "Hello Name" message being returned as the result of the seda:next, and thus to the rest call.

Alternatively, you could have

.inOnly("seda:next")

in your first route if you don't want a response from the "next" route, which I think would mean that your rest call would get the original input class as the response (but don't quote me on that).

Upvotes: 2

Related Questions