4

How to run Artemis Messaging in a Bootable Jar

 1 year ago
source link: http://www.mastertheboss.com/eclipse/eclipse-microservices/how-to-run-artemis-messaging-in-a-bootable-jar/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to run Artemis Messaging in a Bootable Jar

19 October 202219 October 2022 by F.Marchioni

This article is a walk-through the new embedded-activemq layer which allows to run the Artemis MQ Server in a WildFly Bootable Jar.

WildFly Bootable Jar allows to run Jakarta EE applications as runnable Jar applications, which include the required subsystems as Galleon layers. You can learn more about WildFly bootable Jar in this article: Turn your WildFly applications in bootable JARs

A Galleon layer includes one or more WildFly subsystems which provide a core functionality. The list of Galleon layers is available in the product documentation: https://docs.wildfly.org/26/Galleon_Guide.html#wildfly_galleon_layers

With the upcoming WildFly 27 release a new Galleon layer is available: embedded-activemq . By including this layer in the Bootable Jar you will be able to embed the Artemis MQ Broker in your Jar file.

Turning the MDB quickstart into a Bootable Jar

Firstly, we need an example which uses Message Driven Beans and a JMS producer. For this purpose we will use the HelloWorld MDB quickstart.

In order to enable the creation of WildFly bootable Jar, you need to include its plugin in your pom.xml. For example:

<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-jar-maven-plugin</artifactId>
<version>8.0.1.Final</version>
<configuration>
<feature-pack-location>wildfly@maven(org.jboss.universe:community-universe)#${version.wildfly}</feature-pack-location>
<layers>
<layer>ejb</layer>
<layer>web-server</layer>
<layer>jsf</layer>
<layer>embedded-activemq</layer>
</layers>
<plugin-options>
<jboss-fork-embedded>${plugin.fork.embedded}</jboss-fork-embedded>
</plugin-options>
</configuration>
<executions>
<execution>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
 <plugin>
	<groupId>org.wildfly.plugins</groupId>
	<artifactId>wildfly-jar-maven-plugin</artifactId>
	<version>8.0.1.Final</version>
	<configuration>
	  <feature-pack-location>wildfly@maven(org.jboss.universe:community-universe)#${version.wildfly}</feature-pack-location>
	  <layers>
	    <layer>ejb</layer>
	    <layer>web-server</layer>
	    <layer>jsf</layer>
	    <layer>embedded-activemq</layer>
	  </layers>
	  <plugin-options>
	    <jboss-fork-embedded>${plugin.fork.embedded}</jboss-fork-embedded>
	  </plugin-options>
	</configuration>
	<executions>
	  <execution>
	    <goals>
	      <goal>package</goal>
	    </goals>
	  </execution>
	</executions>
</plugin>

The most interesting aspect, is the embedded-activemq layer which allows to build the Embedded ActiveMQ broker. Besides, this layer will also provide additional configuration resources, e.g. socket-bindings. Necessary dependencies needed to support this use case, e.g. the resource-adapters subsystem, will also be provided.

Finally, include WildFly version as property:

<version.wildfly>27.0.0.Beta1</version.wildfly>
 <version.wildfly>27.0.0.Beta1</version.wildfly>

Running the application

To build and run the application you can execute:

mvn clean package wildfly-jar:run
mvn clean package wildfly-jar:run

As you can see from the Server logs, WildFly starts. The ActiveMQ resource adapter deploys and so are the JMS Destinations which are in the example:

Screenshot-from-2022-10-19-17-52-14-1024x399.png

Then, reach the JMS Servlet available at: http://localhost:8080/HelloWorldMDBServletClient

As you can see, messages are dispatched to the MessageDriven Bean:

Screenshot-from-2022-10-19-17-54-30.png

Conclusion

This article shows how to provide the a messaging-activemq subsystem in a WildFly Bootable Jar application. This quickstart defines programmaticaly JMS desitnations. if you want to add them via CLI in a Bootable Jar then check this article: How to execute CLI scripts in WildFly Bootable Jar

Special thanks to Jean-Francois Denise @RedHat for providing insights on the embedded-activemq layer

Post Views: 22

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK