<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>messaging</artifactId>
</dependency>
Messaging
The Messaging fraction brings support for JMS to your application. Currently, the messaging capability does not span across multiple independent WildFly Swarm-based services, but is only available within a single service.
The WildFly Swarm messaging broker is based upon ActiveMQ.
Configuration
To enable messaging for your application, you need to include the following dependency:
Additionally, you must configure some destinations for the messaging broker
to be useful. This is done through your main(…)
function.
swarm.fraction(new MessagingFraction()
.defaultServer( (server)->{
server.topic("my-topic")
server.queue("my-queue");
} );
);
);
Remote Message Broker
While the above configures a message broker internal to your application, that is many times sub-optimal when working with microservices. A better approach may be to run your message broker as a separate, more persistent process, and simply connect all of your microservices to it.
WildFly Swarm supports two separate methods for achieving that.
Java API
You can use the same Java API as above to create a remote connection to an outboard message broker, configuring the host, port, and JNDI name for the pooled connection factory.
swarm.fraction( new MessagingFraction()
.defaultServer( (server)->{
server.remoteConnection( "remote-mq", (connection)->{
connection.host( "mq.mycorp.com" );
connection.port( 61616 );
connection.jndiName( "java:/jms/remote-mq" );
} );
} );
);
Configuration Properties
Additionally, if you only need a single remote connection, it can
be completely configured using Java system properties, or configuration
values from project-stages.yml
.
If any of the following properties are set, a remote connection will
be created. Any un-set properties will use their defaults, as long as
at least the swarm.messaging.remote
flag is set to true. If any of
the other values are configured explicitly, there is no need to also
set swarm.messaging.remote
.
Key | Default Value | Description |
---|---|---|
|
none |
Flag ( |
|
|
Base name of the remote connection. Used to build JNDI name if not otherwise specified |
|
|
Hostname of the remote message broker |
|
61616 |
Port of the remote message broker |
|
|
JNDI name of the remote pooled connection factory A combination of the two methods above may be used, where the configuration properties override the values set through the Java API. |