Re: .process vs .to(bean: ?

2021-09-10 Thread Mark Nuttall
Yeah. That seems better. I wish the rest component supported to

On Friday, September 10, 2021, Steve Huston  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 
> > 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");
> > >   Clos

RE: .process vs .to(bean: ?

2021-09-10 Thread Steve Huston
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 
> 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 Buffer

Re: .process vs .to(bean: ?

2021-09-10 Thread Mark Nuttall
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.jpg]<
> https://www.sun.ac.za/e

Re: Camel QuickFix sessions start problem

2021-09-10 Thread Claus Ibsen
Hi

Ah okay this is more of an advanced problem and you would need to do
some custom coding or whatnot.
The nature of this seems that quickfix should be improved to have
independent configurations per session and then allow to only load the
configuration for which session is being started.

So at this point there is not something we can do in camel-quickfix.

On Sat, Sep 4, 2021 at 10:51 PM Claus Ibsen  wrote:
>
> Hi
>
> Ah okay maybe we can defer starting that quickfix till the route
> starts the consumer.
> Can you put together maybe a sample app or unit test, and create a
> JIRA and put your code there.
> That is a great start to look into this.
>
>
> On Wed, Sep 1, 2021 at 7:06 PM Alexander A  wrote:
> >
> > Hi!
> >
> > I have 2 camel routes from quickfix consumers.
> > Camel version is 3.4.4 but behaviour is the same with greater versions too.
> > 2 sessions are described in fix.properties file.
> > Second route is .autoStartup(false).
> >
> > When camel starts a quickfix consumer for the active route, it starts
> > second quickfix session (for disabled route) too.
> >
> > This happens in org.apache.camel.component.quickfixj.doStart()
> > -> quickfix.SocketInitiator
> >
> > private void initialize() throws ConfigError {
> > if (isStarted.equals(Boolean.FALSE)) {
> > eventHandlingStrategy.setExecutor(longLivedExecutor);
> > createSessionInitiators();
> > for (Session session : getSessionMap().values()) {
> > Session.registerSession(session);
> > }
> > *startInitiators();*
> > eventHandlingStrategy.blockInThread();
> > isStarted = Boolean.TRUE;
> > } else {
> > log.warn("Ignored attempt to start already running
> > SocketInitiator.");
> > }
> > }
> >
> > One possible workaround - store sessions in different files.
> >
> > QuickFixJ approach for independen sessions startup described here:
> > https://stackoverflow.com/questions/61611047/how-to-manage-and-reload-multiple-quickfix-j-sessions-independently
> > .
> >
> > How can I implement independent sessions startup with Camel using single
> > config file?
> >
> >
> > 
> > Без
> > вирусов. www.avast.ru
> > 
> > <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
>
>
> --
> Claus Ibsen
> -
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



-- 
Claus Ibsen
-
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2