Integrate Red Hat Fuse 7 on Apache Karaf with Red Hat AMQ 7

n this article, I will demonstrate how to use Apache Camel applications in Red Hat Fuse 7.8 to produce and consume messages from Red Hat AMQ 7 or its upstream project, Apache ActiveMQ Artemis. This approach uses AMQ Core Protocol Java Message Service (JMS). Users who want to migrate from Red Hat Fuse 6 and Red Hat AMQ 6 to Red Hat Fuse 7 and Red Hat AMQ 7 will also find this tutorial helpful.

Set up the ActiveMQ Artemis broker

Here are the steps to set up the ActiveMQ Artemis broker:

  1. Download Apache Artemis. At the time of writing this article, apache-artemis-2.17.0-bin.zip is the latest version.
  2. Unzip this distribution. Create a folder called apache-artemis-2.17-instance in parallel to the unzipped folder, as shown in the following example:
    
    $ ls -ltr|grep artemis
    drwxr-xr-x. 7 chandrashekhar chandrashekhar 4096 Feb 11 12:21 apache-artemis-2.17.0
    -rw-r--r--. 1 chandrashekhar chandrashekhar 63489635 Apr 24 21:23 apache-artemis-2.17.0-bin.zip
    drwxr-xr-x. 2 chandrashekhar chandrashekhar 4096 Apr 24 21:26 apache-artemis-2.17-instance
    
    $ cd apache-artemis-2.17-instance
    
    $ ../apache-artemis-2.17.0/bin/artemis create artemis_instance_1 --user admin --password admin
    Creating ActiveMQ Artemis instance at: /mnt/79fece0c-d480-4c54-8268-eaf9ce6ba53d/Development_SSD/AMQ_RH/apache-artemis-2.17-instance/artemis_instance_1
    
    --allow-anonymous | --require-login: is a mandatory property!
    Allow anonymous access?, valid values are Y,N,True,False
    N
    
    Auto tuning journal ...
    done! Your system can make 62.5 writes per millisecond, your journal-buffer-timeout will be 16000
    
    You can now start the broker by executing:
    
    "/mnt/79fece0c-d480-4c54-8268-eaf9ce6ba53d/Development_SSD/AMQ_RH/apache-artemis-2.17-instance/artemis_instance_1/bin/artemis" run
    
    Or you can run the broker in the background using:
    
    "/mnt/79fece0c-d480-4c54-8268-eaf9ce6ba53d/Development_SSD/AMQ_RH/apache-artemis-2.17-instance/artemis_instance_1/bin/artemis-service" start
    
    $ ls -ltr
    total 4
    drwxrwxr-x. 8 chandrashekhar chandrashekhar 4096 Apr 24 21:37 artemis_instance_1
    
  3. Add the following acceptor in apache-artemis-2.17-instance/etc/broker.xml and save the file. Certificates are located in the example GitHub repo:
    
    ---
    tcp://localhost:61621?sslEnabled=true;keyStorePath=/home/chandrashekhar/certificates/activemq.example.keystore;keyStorePassword=activemqexample
    ---
    
  4. Don’t forget to modify the keystore path. Then, start the broker from the location apache-artemis-2.17-instance/bin:
    $ ./artemis run
    
    # we will see logs like
    
    2021-04-24 21:56:07,978 INFO [org.apache.activemq.artemis.integration.bootstrap] AMQ101000: Starting ActiveMQ Artemis Server
    ----
    ----
    2021-04-24 21:56:08,900 INFO [org.apache.activemq.artemis.core.server] AMQ221020: Started EPOLL Acceptor at localhost:61621 for protocols [CORE,MQTT,AMQP,HORNETQ,STOMP,OPENWIRE]
    ----
    ----
    2021-04-24 21:56:08,920 INFO [org.apache.activemq.artemis.core.server] AMQ221007: Server is now live
    2021-04-24 21:56:08,920 INFO [org.apache.activemq.artemis.core.server] AMQ221001: Apache ActiveMQ Artemis Message Broker version 2.17.0 [0.0.0.0, nodeID=c6090ffc-a519-11eb-a4d5-b0fc366fae1f]

Set up Red Hat Fuse on Karaf

Next, set up Red Hat Fuse on Karaf:

  1. Download Red Hat Fuse and select the Karaf installer. At the time of writing this article, Red Hat Fuse 7.8 is the latest version.
  2. Unzip the file and run it from the bin folder:
    $ cd fuse-karaf-7.8.0.fuse-780038-redhat-00001/bin
    $./fuse
  3. You can use the mvn clean install command to build the application. The application code and certificates are located in the example GitHub repository.
  4. Modify the Camel route as per our requirements. Don’t forget to update the truststore path. We are using Camel’s Java Message Service (JMS) component with the Artemis connection factory (ActiveMQJMSConnectionFactory).
  5. In the Karaf console, install the following features and applications:
    [email protected]()> features:install pax-jms-artemis
    [email protected]()> features:install pax-jms-pool-pooledjms
    [email protected]()> features:install camel-jms
    [email protected]()> install -s mvn:com.mycompany/karafArtemis/1.0.0-SNAPSHOT
  6. In the Red Hat Fuse logs, you will see the following entries:
    [chandrashekhar[email protected] log]$ tail -f fuse.log
    2021-04-24 22:40:59,731 | INFO | sConsumer[someQueue] | consume_message | 64 - org.apache.camel.camel-core - 2.23.2.fuse-780036-redhat-00001 | message 20210424 10:40
    2021-04-24 22:41:59,729 | INFO | sConsumer[someQueue] | consume_message | 64 - org.apache.camel.camel-core - 2.23.2.fuse-780036-redhat-00001 | message 20210424 10:41
    2021-04-24 22:42:59,734 | INFO | sConsumer[someQueue] | consume_message | 64 - org.apache.camel.camel-core - 2.23.2.fuse-780036-redhat-00001 | message 20210424 10:42
  7. In Artemis, we can check the queue statistics from the bin folder of the broker instance:
    $ pwd
    /path/to/apache-artemis-2.17-instance/artemis_instance_1/bin
    
    $ [[email protected] bin]$ ./artemis queue stat --user admin --password admin
    Connection brokerURL = tcp://localhost:61616
    |NAME |ADDRESS |CONSUMER_COUNT |MESSAGE_COUNT |MESSAGES_ADDED |DELIVERING_COUNT |MESSAGES_ACKED |SCHEDULED_COUNT |ROUTING_TYPE |
    |someQueue |someQueue |1 |0 |18 |0 |18 |0 |ANYCAST |
    [[email protected] bin]$

Conclusion

That’s it! I hope you found this article interesting and helpful. You can find more details about these technologies at the following links:

The post Integrate Red Hat Fuse 7 on Apache Karaf with Red Hat AMQ 7 appeared first on Red Hat Developer.

Source: Red Hat

Leave a Reply

Your email address will not be published.


*