Tuesday, November 16, 2021

Camel: How to increment the value of an Integer header by a set amount

 

Code

from("direct:hello")

    .setHeader("offset", header("offset").convertTo(Integer.class))

    .setHeader("offset").ognl("request.headers.offset + 50");


Ref: https://newbedev.com/camel-how-to-increment-the-value-of-an-integer-header-by-a-set-amount

Camel & ActiveMQ


XML File

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="        http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd        http://camel.apache.org/schema/spring       https://camel.apache.org/schema/spring/camel-spring-2.23.3.xsd">


    <bean class="org.apache.activemq.ActiveMQConnectionFactory" id="jmsConnectionFactory">

        <property name="brokerURL" value="tcp://localhost:61616"/>

    </bean>

    <bean class="org.apache.activemq.pool.PooledConnectionFactory"

        destroy-method="stop" id="pooledConnectionFactory" init-method="start">

        <property name="maxConnections" value="8"/>

        <property name="connectionFactory" ref="jmsConnectionFactory"/>

    </bean>

    

    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">

        <route id="simple-route">

<from id="_to2" uri="activemq:queue:sample?connectionFactory=#pooledConnectionFactory" />

<log id="route-log" message=">>> ${body}" />

</route>

    </camelContext>

</beans>




Camel & MongoDB

Add Depdendency to POM

<dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-mongodb</artifactId> <version>3.0.3.RELEASE</version> </dependency>

Define XML

 <?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mongo="http://www.springframework.org/schema/data/mongo" xsi:schemaLocation= " http://www.springframework.org/schema/data/mongo https://www.springframework.org/schema/data/mongo/spring-mongo.xsd http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring https://camel.apache.org/schema/spring/camel-spring-2.23.3.xsd"> <!-- Default bean name is 'mongo' --> <mongo:mongo-client id="mongoClient" host="localhost" port="27017"/>      <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> <route id="_route2"> <from id="_to1" uri="timer:timertimerName?period=3600000"/> <setBody id="_setBody1q"> <constant>{"item" : "card", "qty" : 99}</constant> </setBody> <to id="_to2" uri="mongodb:mongoClient?collection=mycollection&amp;database=sample&amp;operation=insert"/> </route>
</camelContext>
</beans>

Camel Saga & Narayana LRA


 

Ref: 

  • https://jbossts.blogspot.com/2017/12/narayana-lra-implementation-of-saga.html
  • https://camel.apache.org/components/3.7.x/eips/saga-eip.html
  • https://github.com/nicolaferraro/camel-saga-quickstart

Use Redhat Fuse to create Integration Project for editing camel file with visual editor

The Pom file look like

<?xml version="1.0" encoding="UTF-8"?>

<project

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"

xmlns="http://maven.apache.org/POM/4.0.0"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<modelVersion>4.0.0</modelVersion>

<groupId>org.mycompany</groupId>

<artifactId>camel-ose-springboot-xml</artifactId>

<version>1.0.0-SNAPSHOT</version>

<name>Fabric8 :: Quickstarts :: Spring-Boot :: Camel XML</name>

<description>Spring Boot example running a Camel route defined in XML</description>

<properties>

<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>

<fuse.version>7.7.0.fuse-sb2-770010-redhat-00001</fuse.version>

</properties>

<dependencyManagement>

<dependencies>

<dependency>

<groupId>org.jboss.redhat-fuse</groupId>

<artifactId>fuse-springboot-bom</artifactId>

<version>7.7.0.fuse-sb2-770010-redhat-00001</version>

<type>pom</type>

<scope>import</scope>

</dependency>

</dependencies>

</dependencyManagement>

<dependencies>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-undertow</artifactId>

</dependency>

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-web</artifactId>

<exclusions>

<exclusion>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-tomcat</artifactId>

</exclusion>

</exclusions>

</dependency>

<dependency>

<groupId>org.apache.camel</groupId>

<artifactId>camel-spring-boot-starter</artifactId>


</dependency>

<dependency>

<groupId>org.apache.camel</groupId>

<artifactId>camel-lra-starter</artifactId>

<version>2.21.0</version>

</dependency>

<dependency>

<groupId>org.apache.camel</groupId>

<artifactId>camel-servlet-starter</artifactId>

</dependency>

<dependency>

<groupId>org.apache.camel</groupId>

<artifactId>camel-http4-starter</artifactId>

</dependency>

</dependencies>

<repositories>

<repository>

<id>red-hat-ga-repository</id>

<url>https://maven.repository.redhat.com/ga</url>

</repository>

</repositories>

<pluginRepositories>

<pluginRepository>

<id>red-hat-ga-repository</id>

<url>https://maven.repository.redhat.com/ga</url>

</pluginRepository>

</pluginRepositories>

<build>

<defaultGoal>spring-boot:run</defaultGoal>

<plugins>

<plugin>

<artifactId>maven-compiler-plugin</artifactId>

<version>${maven-compiler-plugin.version}</version>

<configuration>

<source>1.8</source>

<target>1.8</target>

</configuration>

</plugin>

<plugin>

<groupId>org.jboss.redhat-fuse</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

<version>${fuse.version}</version>

<executions>

<execution>

<goals>

<goal>repackage</goal>

</goals>

</execution>

</executions>

</plugin>

<plugin>

<groupId>org.jboss.redhat-fuse</groupId>

<artifactId>fabric8-maven-plugin</artifactId>

<version>${fuse.version}</version>

<executions>

<execution>

<goals>

<goal>resource</goal>

<goal>build</goal>

</goals>

</execution>

</executions>

</plugin>

</plugins>

</build>

<profiles>

<profile>

<id>jdk9+-build</id>

<activation>

<jdk>[9,)</jdk>

</activation>

<dependencies>

<dependency>

<groupId>javax.annotation</groupId>

<artifactId>javax.annotation-api</artifactId>

</dependency>

<dependency>

<groupId>javax.xml.ws</groupId>

<artifactId>jaxws-api</artifactId>

<exclusions>

<exclusion>

<artifactId>jaxb-api</artifactId>

<groupId>javax.xml.bind</groupId>

</exclusion>

</exclusions>

</dependency>

<dependency>

<groupId>jakarta.xml.bind</groupId>

<artifactId>jakarta.xml.bind-api</artifactId>

<version>2.3.3</version>

</dependency>

<dependency>

<groupId>com.sun.activation</groupId>

<artifactId>javax.activation</artifactId>

</dependency>

<dependency>

<groupId>org.apache.geronimo.specs</groupId>

<artifactId>geronimo-ws-metadata_2.0_spec</artifactId>

<version>1.1.3</version>

</dependency>

<dependency>

<groupId>com.sun.xml.messaging.saaj</groupId>

<artifactId>saaj-impl</artifactId>

</dependency>

<dependency>

<groupId>org.apache.geronimo.specs</groupId>

<artifactId>geronimo-jta_1.1_spec</artifactId>

</dependency>

<dependency>

<groupId>org.jboss.spec.javax.rmi</groupId>

<artifactId>jboss-rmi-api_1.0_spec</artifactId>

<version>1.0.6.Final</version>

</dependency>

</dependencies>

</profile>

</profiles>

</project>

File application.yaml

camel:

  springboot:

    name: MyCamel

    main-run-controller: true

  service:

    lra:

      enabled: true

      coordinator-url: http://localhost:8081

      local-participant-url: http://localhost:8080/api

  component:

    servlet:

      mapping:

        context-path: /api/*


logging:

  config: classpath:logback.xml


server:

  address: 0.0.0.0


management:

  address: 0.0.0.0

  port: 8080

endpoints:

  enabled: false

  health:

    enabled: true



#spring:

#  main:

#    web-application-type: none


Ok, Now create Saga in Camel 

<route id="simple-route">
            <from id="route-timer" uri="timer://foo?period=10000"/>
            <saga id="_saga1">
                <to id="_to1" uri="direct:order"/>
                <to id="_to2" uri="direct:credit"/>
            </saga>
            <log id="route-log" message=">>> ${body}"/>
        </route>
        <route id="_route1">
            <from id="_from1" uri="direct:order"/>
            <saga id="_saga2">
                <transform id="_transform1">
                    <header>Exchange.SAGA_LONG_RUNNING_ACTION</header>
                </transform>
                <log id="_log1" message="order completed with body ${body}"/>
                <compensation uri="direct:cancel"/>
                <completion uri="direct:refund"/>
            </saga>
        </route>
        <route id="_route2">
            <from id="_from2" uri="direct:credit"/>
            <saga id="_saga3" propagation="MANDATORY">
                <transform id="_transform2">
                    <header>Exchange.SAGA_LONG_RUNNING_ACTION</header>
                </transform>
                <log id="_log2" message="credit completed with body ${body}"/>
                <compensation uri="direct:refund"/>
                <completion uri="direct:cancel"/>
            </saga>
        </route>
        <route id="_route3">
            <from id="_from3" uri="direct:refund"/>
            <log id="_log3" message="refund"/>
        </route>
        <route id="_route4">
            <from id="_from4" uri="direct:cancel"/>
            <log id="_log4" message="credit completed"/>
        </route>

We have to run LRA coordinator with docker:
docker run -d -p 8081:8080 -e JAVA_ARGS=-Djava.net.preferIPv4Stack=true docker.io/jbosstm/lra-coordinator:5.8.2.Final

Now,We can run appliction

Friday, October 15, 2021

How can I validate xsd using apache camel?

 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/blueprint"
       xsi:schemaLocation="
       http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
       http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/spring/camel-blueprint.xsd">

  <camelContext xmlns="http://camel.apache.org/schema/blueprint">
      <route>
          <from uri="file:flights/data-in?noop=false"/>
          <doTry>
              <to uri="validator:file:flights/schema/flight.xsd"/>
              <to uri="file:flights/data-valid"/>
              <doCatch>
                  <exception>org.apache.camel.ValidationException</exception>
                  <to uri="file:flights/data-invalid"/>
              </doCatch>
              <!--
              <doFinally>
                  <to uri="file:test/src/data/finally"/>
              </doFinally>
              -->
          </doTry>
      </route>

  </camelContext>

</blueprint>

Ref: https://stackoverflow.com/questions/28263085/how-can-i-validate-xsd-using-apache-camel

Friday, June 25, 2021

Extract Python from installer file.

 msiexec /a python-3.3.2.msi /qb TARGETDIR=%TARGET%

Build dashbuilder-components for Redhat PAM

Build dashbuilder-components for Redhat PAM
  •  Clone Project in https://github.com/jesuino/dashbuilder-components
  • Install yarn: npm install -g yarn
  • Init project: npm run init 
  • Build project:  npm run build:prod ( must replace "rm -rf" to  "rimraf -rf" on file package.json in case you build on window mache)


Install and use xorg-server on macOS via Homebrew

  The instructions to install and use xorg-server on macOS via Homebrew: Install Homebrew (if you haven't already): /bin/bash -c ...