3

I am trying to use Spring Boot 1.5.2.RELEASE + Camel (Spring Boot starter) 2.19.2 to listen to ActiveMQ queue and then post the message to a rest endpoint URL (POST method) as its body. What would be the best possible way to achieve this? I have gathered pieces of information and am trying to tie it all together but getting a bit confused.

Here is what I have gathered for Camel Rest DSL, I am not too sure if camel below is creating these rest services via this or is it just an already exposed endpoint, in my case it is an already exposed endpoint

rest("/basePath")
  post("/someEndpoint").to("direct:restEndpoint")

Using the above is what I have gathered for ActiveMQ which I am not too sure is correct

from("activemq:queue:<queue_name>").to("direct:restEndpoint")

But again, I am not too sure how to listen to the ActiveMQ queue for new messages or is it something that Camel would do by default always? Additionally, I need to pass the message as a post body to my rest endpoint. I also saw some references to camel-http4 and camel-http as well and I am completely confused.

Any assistance would be greatly appreciated.

Sayantan
  • 564
  • 2
  • 7
  • 23
  • 2
    Since you are just starting out I would suggest to don't do a lot of things at once, which you are doing. Forget REST, just focus on reading from a queue. Get that to work. Once that is done, move to the next and the next. Each step on its own has many parameters and options to configure. Get familiar with those and then build your routes. Most of your questions are stated in the documentation so you need to read on that. – Souciance Eqdam Rashti Aug 22 '17 at 07:37
  • Look at content enricher EIP to do a on-demand poll from a queue/camel endpoint - you can use `pollEnrich` and then mind about if there is no messages in the queue, then use a timeout or something. – Claus Ibsen Aug 23 '17 at 01:59
  • Also you are getting things a bit mixed up. A REST service is triggered when some HTTP client calls it - not when a new message arrives on a JMS queue. – Claus Ibsen Aug 23 '17 at 02:00
  • I am not sure you are understanding what I am trying to achieve, I am trying to poll for new messages and trigger a HTTP call (rest service), so basically my camel route is going to act as the client here. – Sayantan Aug 23 '17 at 05:03

1 Answers1

3

Some confusion is common when starting to use Camel, but your final solution will look something like:

from("activemq:queue:my-route")
  .process(/* change the in/out messages if you need to */)
  .to("http4://your-endpoint.com");

Don't try to simply copy/paste this code until it works. My Camel rule of thumb is: always read the component documentation and try playing with it using it in your software. In your case I suggest:

  1. Read ActiveMQ component docs and try reading from ActiveMQ / writing to a Log;
  2. Generate some input from a Timer and send to your Rest endpoint using HTTP4 Component;

Your first routes will take some time for simple things but you will get on flow quickly.

jfneis
  • 2,139
  • 18
  • 31
  • Thanks, that is really some good help to being with. Btw, one thing which is still not clear to me, if I configure the route to read from a queue does it always look for new messages? Or do I need to configure that separately? – Sayantan Aug 22 '17 at 22:21
  • It always looks for new messages. You can configure how many threads you want and other things, but as soon as a msg arrives and there is a free thread it will be read. – jfneis Aug 22 '17 at 23:54
  • thanks that helps. I am now currently stuck at getting by spring boot app up with activeMQ configuration, posting a separate question for that. As you said, started with baby steps :) – Sayantan Aug 23 '17 at 05:10
  • Here is the question I posted on the same. Could you please assist if possible? https://stackoverflow.com/questions/45831782/camel-activemq-spring-boot-not-reading-spring-activemq-configurations – Sayantan Aug 23 '17 at 06:07
  • I'll take a look. Please consider accepting this answer if it helped! Tks – jfneis Aug 23 '17 at 11:46