Open Source Development

 View Only

Red Hat build of Apache Camel for Spring Boot with AMQP on OpenShift for IBM Power

By Siddhesh Prabhu posted Mon January 06, 2025 07:14 AM

  

In the previous blog, we explored the world of Red Hat build of Apache Camel for Spring Boot on OpenShift for IBM Power and also looked at the example of simple application deployment. Now let us take a step further and delve into the integration of Camel Spring Boot with Advanced Message Queuing Protocol (AMQP). In this blog we will explore the advantages of leveraging the AMQ broker operator on an OpenShift cluster tailored for IBM Power. By the end of this blog, you will feel confident about unlocking the potential of seamless messaging and advanced integration techniques!

What is AMQP for Power?

The AMQP is an open standard application layer protocol designed for message-oriented middleware. It facilitates reliable communication between applications by allowing them to send and receive messages asynchronously. AMQP is platform-independent and supports multiple messaging patterns, including:

  • Point-to-point
  • Publish-subscribe
  • Request-response

AMQP is widely used in scenarios where decoupled communication between different parts of a system is essential. This includes applications in financial services, telecommunications, enterprise systems, and so on where messaging needs to be secure, reliable, and fast.

Figure 1. AMQP Protocol

Figure 1. AMQP protocol

Red Hat OpenShift AMQ broker operator

The Red Hat OpenShift AMQ broker operator streamlines the deployment, management, and scaling of AMQP-based messaging infrastructure on OpenShift, a leading Kubernetes platform.

In OpenShift, operators are Kubernetes extensions that enable the packaging and management of complex applications as cloud-native services. The Red Hat OpenShift AMQP Operator provides an efficient solution for deploying AMQP brokers, configuring them, and managing their lifecycle.

Key operational tasks automated by the operator include:

  • Provisioning: Automatically deploys AMQP brokers within the OpenShift cluster.
  • Scaling: Dynamically adjusts the messaging infrastructure based on workload demands.
  • Monitoring: Delivers visibility into the health and performance of AMQP brokers.
  • Self-Healing: Recovers from failures automatically to maintain high availability.

Using the Red Hat OpenShift AMQP Operator enables organizations to focus on developing and deploying applications without the complexity of managing the underlying messaging infrastructure.

Use cases for AMQP on Red Hat OpenShift on IBM Power

AMQP on Red Hat OpenShift is particularly useful in scenarios that require robust and scalable messaging solutions. Some typical use cases include:

  1. Event-driven architectures: In microservices-based systems, AMQP can be used to enable asynchronous communication between services, decoupling them and improving system resilience.
  2. Data streaming: AMQP is ideal for streaming data between applications, such as in IoT environments where devices need to send large volumes of data to central systems for processing.
  3. Enterprise integration: AMQP is often used to integrate legacy systems with modern cloud-native applications, ensuring smooth and reliable data exchange.
  4. Distributed applications: In geographically distributed systems, AMQP can facilitate the exchange of messages between different data centres, ensuring consistency and reliability.

Integrating Red Hat build of Apache Camel for Spring Boot with AMQP on Red Hat OpenShift

Apache Camel is a powerful integration framework that simplifies the process of integrating different systems. When used with Spring Boot, Apache Camel provides a lightweight platform for building standalone integration applications. Integrating Apache Camel Spring Boot with AMQP on Red Hat OpenShift allows developers to create highly scalable and resilient messaging solutions.

Figure 2. AMQP on OpenShift

Figure 2. AMQP on OpenShift

Prerequisites:

Following are the prerequisites required for deployment

System requirements:

Note:

  • Use a package manager such as yum for installation on RHEL-based distributions.
  • Before proceeding with the configuration steps, ensure familiarity with the following concepts:
    • Maven
    • Java
    • SpringBoot
    • Apache Camel
    • OpenShift
    • AMQP

Here’s a step-by-step overview of how to achieve this integration:

  1. Set up AMQP on OpenShift for IBM Power (ppc64le)

    IBM Power Systems, particularly the ppc64le architecture, provides a robust platform for running containerized workloads. Red Hat OpenShift on IBM Power Systems offers a scalable and secure environment for deploying cloud-native applications. To begin, ensure that your OpenShift cluster is up and running on IBM Power Systems. This involves:

    • Provisioning the OpenShift cluster on ppc64le.
    • Installing the Red Hat AMQ broker operator via the OpenShift OperatorHub.
    • Configuring the cluster for high availability and scaling.
    Figure 3. Create a new project for example

    Figure 3. Create a new project

    Figure 4. Install AMQ Broker Operator from OperatorHub

    Figure 4. Install AMQ Broker Operator from OperatorHub

    Figure 5. Install AMQ Broker Operator

    Figure 5. Install AMQ Broker Operator

  2. Deploy the AMQP

    After the Red Hat AMQ broker operator is installed, you can deploy an AMQP broker in your OpenShift cluster:

    • Create an ActiveMQArtemis custom resource that defines the desired state of the AMQP broker.
    • Apply the custom resource to deploy the AMQP broker, managed by the operator. This can be achieved using the CLI with the following configuration or through the web console, as demonstrated.
      apiVersion: broker.amq.io/v1beta1
      kind: ActiveMQArtemis
      metadata:
        name: amq-broker
        namespace: csb-amqp
      spec:
        acceptors:
          - expose: true
            name: all-ssl
            port: 61636
            protocols: all
            sslEnabled: true
            sslSecret: amqp-csb-ssl
          - expose: false
            name: all-internal
            port: 61626
            protocols: all
            sslEnabled: false
        adminPassword: admin123.admin123.admin123.
        adminUser: admin
        deploymentPlan:
          image: placeholder
          journalType: nio
          messageMigration: true
          persistenceEnabled: false
          requireLogin: false
          size: 1
      

    This step ensures that the messaging infrastructure is in place and ready for your Apache Camel Spring Boot application.

    Figure 6.1 ActiveMQArtemis Custom Resource
    Figure 6.2 ActiveMQArtemis Custom Resource

    Figure 6. ActiveMQArtemis custom resource

  3. The Apache Camel Spring Boot application will leverage the AMQP broker for messaging. To configure the application, follow these steps:
    • Add the required dependencies for Apache Camel and AMQP to your Spring Boot project:
      ```
        <dependency>
                  <groupId>com.redhat.camel.springboot.platform</groupId>
                  <artifactId>camel-spring-boot-bom</artifactId>
                  <version>4.0.0.redhat-00045</version>
       </dependency>
         <dependency>
                  <groupId>org.apache.camel.springboot</groupId>
                  <artifactId>camel-amqp-starter</artifactId>
              </dependency>
        ```
      
    • Configure Apache Camel routes to send and receive messages via the AMQP broker:
      ``` 
      @Component
      public class SampleAutowiredAmqpRoute extends RouteBuilder {
          @Autowired
          JmsConnectionFactory amqpConnectionFactory;
      
          @Bean
          public AMQPComponent amqpConnection() {
              AMQPComponent amqp = new AMQPComponent();
              amqp.setConnectionFactory(amqpConnectionFactory);
              return amqp;
          }
      
          @Override
          public void configure() throws Exception {
              restConfiguration().component("servlet");
              rest().post("/").to("direct:send");
              from("direct:send")
                      .setExchangePattern(ExchangePattern.InOnly)
                      .to("amqp:queue:example")
                      .log("Message sent to AMQP queue");
              from("amqp:queue:example").log("Received message from AMQP queue: ${body}");
          }
      }
        ```
    • Modify the application-properties by adding AMQP_REMOTE_URI in properties as shown below:

      amqp://amq-broker-ss-0.amq-broker-hdls-svc.csb-amqp.svc.cluster.local:61626

      amqp://<pod_name>.<svc_name>.<namespace>:<port>
  4. Deploy the application on OpenShift

    Creating a new build configuration and deploying the Spring Boot application as a container.

    mvn clean -DskipTests oc:deploy –Popenshift
    Figure 7. CSB with AMQP on OpenShift

    Figure 7. CSB with AMQP on OpenShift

  5. Testing and scaling

    After the Apache Camel Spring Boot application is deployed, test the integration to ensure that messages are being sent and received correctly via the AMQP broker. You can also scale the application horizontally within OpenShift to handle increased load. OpenShift’s monitoring tools can help you track the performance and health of your Apache Camel routes and the AMQP broker.

    Verify the Apache Camel Spring Boot app pods, amq-broker pod, and other resources.

    Figure 8. All applications and AMQP pods

    Figure 8. All applications and AMQP pods

    Figure 9. Camel Application Deployment Config

    Figure 9. Camel application deployment configuration

    Figure 10. Application and AMQ-broker routes

    Figure 10. Application and AMQ-broker routes

    The process of sending messages to an AMQ broker is described in pod logs. After establishing a connection with the broker, messages are sent to the endpoint URL: http://<Endpoint>/amqp/ using the POST method. The messages are sent with the media type application or Json for proper message formatting. This ensures that the application communicates effectively with the broker to transmit data.

    Figure 11

    Figure 11. Camel SpringBoot application pod logs

    Figure 12

    Figure 12. Sending POST request

    After the message is sent from URL, it reflects in the application in messaging queue.

    Message = ”Hello AMQ....” 

    figure 13

    Figure 13. Reflecting message in application logs

Conclusion

The integration of Red Hat build of Apache Camel for Spring Boot with AMQP on Red Hat OpenShift running on IBM Power (ppc64le) offers a powerful and scalable messaging solution for enterprise applications. By leveraging the Red Hat’s AMQ broker operator, you can simplify the management of your messaging infrastructure, allowing you to focus on developing and deploying cloud-native applications. Whether you are building event-driven architectures, integrating legacy systems, or developing distributed applications, this combination of technologies provides the tools and flexibility needed to succeed.

The AMQ broker operator simplifies the deployment and management of the broker, while the Apache Camel framework provides robust integration capabilities within a Spring Boot application. By leveraging OpenShift's capabilities, you can efficiently manage and scale your messaging infrastructure.

Permalink