Hi Claus. Adding <dependency> <groupId>org.apache.camel.quarkus</groupId> <artifactId>camel-quarkus-vertx-http</artifactId> <version>2.2.0</version> </dependency>
did the trick. Many many thanks. Now to figure out how to retry in case of timeout and handle errors. Back to reading the documentation (sparce though it may be). Elmar -----Original Message----- From: Claus Ibsen <claus.ib...@gmail.com> Sent: Monday, 13 September 2021 14:48 To: users@camel.apache.org Subject: Re: .process vs .to(bean: ? CAUTION: This email originated from outside the Stellenbosch University network. Do not click links or open attachments unless you recognize the sender and know the content is safe. Hi You may need to set producerComponent in the rest configuration, and specify which component it uses such as vertx-http Or try just to add the vertx-http camel quarkus extensions so its on the classpath then Camel can potentially auto find it. It can do that standalone, but all this quarkus pre build stuff may have some "issues" still that could cause this to not work (yet). And then you can tell Camel which component to use with that producerComponent setting On Mon, Sep 13, 2021 at 2:39 PM Matthee, Elmar [elm...@sun.ac.za] <elm...@sun.ac.za> wrote: > > Hi Claus. > > Thank you for this clue. > > I've chanced my route to look as follows: (For now I'm just hardcoding the > url of the rest service as I don't want to introduce additional points of > failure just yet. FYI: in my application.properties, the url is defined as: > http://localhost:7101/DummyRestService/regEvent/ and when I use the .process > component as previously stated, it goes through fine). > > from(kafka(registrationTopicName) > .brokers(kafkaBroker) > .clientId(kafkaClientId) > .groupId(groupId) > .keyDeserializer(keyDeserializer) > .valueDeserializer(valueDeserializer) > .autoOffsetReset(offset)) > .log("Registration Event received: ${body}") > // .process(eers) > > .to("rest://post:regEvent?host=http://localhost:7101/DummyRestService") > .log("After calling REST service: ${body}"); > > Now however when I try to start the route with quarkus:dev I get the > following error: Failed to start application (with profile dev): > java.lang.IllegalStateException: Cannot find RestProducerFactory in > Registry or as a Component to use > > I've even tried adding: > > restConfiguration().host("localhost:7101/DummyRestService/").component > ("http"); > > before the route but that didn't have any effect. > > I'm sure I'm missing something small but I can't seem to find any examples > showing how to use the .to(rest component. Very frustrating. > > Thanks for all your help. > > Elmar > > -----Original Message----- > From: Claus Ibsen <claus.ib...@gmail.com> > Sent: Sunday, 12 September 2021 10:00 > To: users@camel.apache.org > Subject: Re: .process vs .to(bean: ? > > CAUTION: This email originated from outside the Stellenbosch University > network. Do not click links or open attachments unless you recognize the > sender and know the content is safe. > > > Hi > > The rest component is also a producer so you can do to("rest:xxx:) > https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fcame > l.apache.org%2Fcomponents%2Flatest%2Frest-component.html&data=04%7 > C01%7C%7C966496cfcb1e40878fae08d976b4c5e7%7Ca6fa3b030a3c42588433a120df > fcd348%7C0%7C0%7C637671342568373757%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC > 4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sd > ata=jMmpV4wXKlsr4rNd2JdU1Fe%2FUzhj2U5WkUiynVYysbI%3D&reserved=0 > > > On Sat, Sep 11, 2021 at 7:18 AM Mark Nuttall <mknutt...@gmail.com> wrote: > > > > Yeah. That seems better. I wish the rest component supported to > > > > On Friday, September 10, 2021, Steve Huston <shus...@riverace.com> wrote: > > > > > You could also use something like cxfrs to do the REST call and > > > have it unmarshal your JSON return. > > > That would make it easier to integrate with Mark's idea to use > > > Camel's error handling and retries. > > > > > > -Steve > > > > > > > -----Original Message----- > > > > From: Mark Nuttall <mknutt...@gmail.com> > > > > Sent: Friday, September 10, 2021 3:51 PM > > > > To: users@camel.apache.org > > > > Subject: Re: .process vs .to(bean: ? > > > > > > > > You should use the Camel Processing to do retries. > > > > > > > > Also, look at using something like OpenFeign to reduce the > > > > boilerplate > > > HTTP > > > > call. It can be very few lines of code. > > > > or you should use the Camel HTTP component. > > > > > > > > > > > > > > > > On Fri, Sep 10, 2021 at 2:00 AM Matthee, Elmar > > > > [elm...@sun.ac.za] < elm...@sun.ac.za> wrote: > > > > > > > > > Good morning all. > > > > > > > > > > I'm VERY new to camel so I'm still trying to get a grip on all > > > > > the various components so please bear with me. > > > > > > > > > > I'm using quarkus/camel and have a route where I pull a > > > > > message off of a kafka topic (this part works perfectly btw) > > > > > but then I want to send the string on to a REST service and > > > > > based on the response I get back from the service (i.e. 200 - > > > > > Ok - Go on to next message, 400 - Bad Request - throw message > > > > > in an error queue or 503 - Service unavailable > > > > > - Wait x amount of time and do y amounts of retries before > > > > > stopping the > > > > route completely). > > > > > > > > > > My first attempt was to do all the REST calls in a .proccess > > > > > java > > > class. > > > > > > > > > > But I now saw that you can do a .to(bean:xxx) and basically > > > > > also call a java class to do all the required code etc. > > > > > > > > > > So my question is: what is the more "correct" way to do this > > > > > (especially with regards to getting application.properties > > > > > values to the java class and then sending/handeling the > > > > > responses from the REST service. Would it be better to do all > > > > > the error/wait handeling in the java class or rather build it > > > > > into the route itself (with .errorHandler etc?) > > > > > > > > > > Here is my current working route code: > > > > > > > > > > @ApplicationScoped > > > > > public class EnrollementEventRoute extends RouteBuilder { > > > > > private EnrollmentEventRestSender eers; > > > > > > > > > > @ConfigProperty(name = "kafka.topic.academia.registration") > > > > > String registrationTopicName; > > > > > > > > > > @ConfigProperty(name = "kafka.academia.broker") > > > > > String kafkaBroker; > > > > > > > > > > @ConfigProperty(name = "kafka.academia.config.clientId") > > > > > String kafkaClientId; > > > > > > > > > > @ConfigProperty(name = > > > > > "kafka.academia.registration.autoOffsetReset", > > > > > defaultValue = "latest") > > > > > String offset; > > > > > > > > > > @ConfigProperty(name = "kafka.academia.config.groupId") > > > > > String groupId; > > > > > > > > > > @ConfigProperty(name = "kafka.academia.config.keyDeserializer") > > > > > String keyDeserializer; > > > > > > > > > > @ConfigProperty(name = "kafka.academia.config.valueDeserializer") > > > > > String valueDeserializer; > > > > > > > > > > @ConfigProperty(name = "fms.registration.restservice.endpoint") > > > > > String restEndpoint; > > > > > > > > > > @Override > > > > > public void configure() throws Exception { > > > > > eers = new EnrollmentEventRestSender(restEndpoint); > > > > > from(kafka(registrationTopicName) > > > > > .brokers(kafkaBroker) > > > > > .clientId(kafkaClientId) > > > > > .groupId(groupId) > > > > > .keyDeserializer(keyDeserializer) > > > > > .valueDeserializer(valueDeserializer) > > > > > .autoOffsetReset(offset)) > > > > > .log("Registration Event received: ${body}") > > > > > .process(eers); > > > > > > > > > > } > > > > > > > > > > And then here is the code in the EnrollmentEventRestSender class: > > > > > > > > > > @ApplicationScoped > > > > > public class EnrollmentEventRestSender implements Processor { > > > > > private String restEndpoint; > > > > > > > > > > public EnrollmentEventRestSender() { //Dummy constructor needed. > > > > > > > > > > }; > > > > > > > > > > public EnrollmentEventRestSender(String url) { > > > > > this.restEndpoint = url; > > > > > } > > > > > > > > > > > > > > > > > > > > @Override > > > > > public void process(Exchange exchange) throws Exception { > > > > > try { > > > > > CloseableHttpClient client = HttpClients.createDefault(); > > > > > System.out.println("Got endpoint of: " + restEndpoint); > > > > > HttpPost httpPost = new HttpPost(restEndpoint); > > > > > String json = (String) exchange.getIn().getBody(); > > > > > System.out.println("Got JSON in Exchange: " + json); > > > > > StringEntity entity = new StringEntity(json); > > > > > httpPost.setEntity(entity); > > > > > // httpPost.setHeader("Accept", "application/json"); > > > > > httpPost.setHeader("Content-type", "text/plain; > > > charset=utf-8"); > > > > > CloseableHttpResponse response = client.execute(httpPost); > > > > > System.out.println("Got Response of: " + > > > > > response.getStatusLine().getStatusCode()); > > > > > if > > > > > (!(response.getStatusLine().getStatusCode()==200)) > > > > > { // Something wrong > > > > > InputStream is = response.getEntity().getContent(); > > > > > BufferedReader rd = new BufferedReader(new > > > > > InputStreamReader(is)); > > > > > StringBuilder errReply = new StringBuilder(); > > > > > String responseLine = null; > > > > > while ((responseLine = rd.readLine()) != null) { > > > > > errReply.append(responseLine.trim()); > > > > > } > > > > > rd.close(); > > > > > is.close(); > > > > > System.out.println(errReply); > > > > > } > > > > > client.close(); > > > > > } > > > > > catch (Exception ex ) { > > > > > ex.printStackTrace(); > > > > > } > > > > > } > > > > > > > > > > } > > > > > [https://www.sun.ac.za/productionfooter/email/ProductionFooter > > > > > .j pg]< > > > > > https://www.sun.ac.za/english/about-us/strategic-documents> > > > > > > > > > > The integrity and confidentiality of this email are governed > > > > > by these terms. > > > > > Disclaimer<https://www.sun.ac.za/emaildisclaimer/default.aspx> > > > > > Die integriteit en vertroulikheid van hierdie e-pos word deur > > > > > die volgende bepalings bereël. Vrywaringsklousule< > > > > > https://www.sun.ac.za/emaildisclaimer/default.aspx> > > > > > > > > > > > > -- > Claus Ibsen > ----------------- > https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fdavsc > laus.com%2F&data=04%7C01%7C%7C966496cfcb1e40878fae08d976b4c5e7%7Ca > 6fa3b030a3c42588433a120dffcd348%7C0%7C0%7C637671342568373757%7CUnknown > %7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJ > XVCI6Mn0%3D%7C3000&sdata=cbr8FzpoDhCu4vNvQbPruK%2BAb%2BRm%2FAQNJsj > z%2FmCznEQ%3D&reserved=0 @davsclaus Camel in Action 2: > https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww. > manning.com%2Fibsen2&data=04%7C01%7C%7C966496cfcb1e40878fae08d976b > 4c5e7%7Ca6fa3b030a3c42588433a120dffcd348%7C0%7C0%7C637671342568373757% > 7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik > 1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=PYUVv7ke2xXYcCeFALbmibmyRKpFH7p% > 2BafMCXeZC5Ww%3D&reserved=0 > [https://www.sun.ac.za/productionfooter/email/ProductionFooter.jpg]<ht > tps://www.sun.ac.za/english/about-us/strategic-documents> > > The integrity and confidentiality of this email are governed by these > terms. Disclaimer<https://www.sun.ac.za/emaildisclaimer/default.aspx> > Die integriteit en vertroulikheid van hierdie e-pos word deur die > volgende bepalings bereël. > Vrywaringsklousule<https://www.sun.ac.za/emaildisclaimer/default.aspx> -- Claus Ibsen ----------------- https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fdavsclaus.com%2F&data=04%7C01%7C%7C966496cfcb1e40878fae08d976b4c5e7%7Ca6fa3b030a3c42588433a120dffcd348%7C0%7C0%7C637671342568383749%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=bOApfsb%2FYFEQuLDn%2Ft%2FUczouYKc0G%2FtPcCnWi%2BlbQsA%3D&reserved=0 @davsclaus Camel in Action 2: https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.manning.com%2Fibsen2&data=04%7C01%7C%7C966496cfcb1e40878fae08d976b4c5e7%7Ca6fa3b030a3c42588433a120dffcd348%7C0%7C0%7C637671342568383749%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=JBXnjOPLQCyEXOcQMk9050nmxlLkjAdv8Ghvp5w3iI4%3D&reserved=0 [https://www.sun.ac.za/productionfooter/email/ProductionFooter.jpg]<https://www.sun.ac.za/english/about-us/strategic-documents> The integrity and confidentiality of this email are governed by these terms. Disclaimer<https://www.sun.ac.za/emaildisclaimer/default.aspx> Die integriteit en vertroulikheid van hierdie e-pos word deur die volgende bepalings bereël. Vrywaringsklousule<https://www.sun.ac.za/emaildisclaimer/default.aspx>