Bookmark this page

Configuring Messaging Resources

Objectives

  • Configure JMS connection factories and destinations.

  • Describe ActiveMQ connectors and acceptors.

ActiveMQ Connectors and Acceptors

During the remainder of this book, the Red Hat JBoss Enterprise Application Platform (JBoss EAP) embedded ActiveMQ Artemis is referred to as ActiveMQ. Red Hat JBoss Enterprise Application Platform (JBoss EAP) provides an embedded instance of ActiveMQ Artemis. Its network configuration is based on the following components:

  • Acceptors define networking protocols and parameters for accepting connections from messaging clients.

  • Connectors define networking protocols and parameters for connecting to ActiveMQ servers.

Note

ActiveMQ uses the term connector to refer to a client-side component, but other JBoss EAP subsystems often use connector to refer to a server-side component.

Because JBoss EAP acts as both a server and a client for ActiveMQ, the default configuration files include definitions for both component types. The following two kinds of ActiveMQ acceptors and connectors are provided:

  • The http variety use the native ActiveMQ protocol tunneled through an HTTP connection. The HTTP connection is accepted by the undertow subsystem. This way, a JBoss EAP server instance does not require opening additional firewall ports to accept connections from remote messaging clients.

  • The in-vm variety enable messaging clients running under the same JVM as the ActiveMQ server to connect without networking overhead.

Networking parameters for an ActiveMQ connector are defined indirectly by referring to an acceptor element. The connector connects to the IP address and TCP port from which the acceptor accepts connections. This indirection is related to ActiveMQ remote clients using a discovery mechanism to find connectable servers.

The following listing shows the connectors and acceptors in the default JBoss EAP configuration files:

<subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">
    <server name="default">
        ...

        <http-connector
          name="http-connector"
          socket-binding="http"
          endpoint="http-acceptor" /> 1

        ...

        <in-vm-connector
          name="in-vm"
          server-id="0" /> 2

        <http-acceptor
          name="http-acceptor"
          "http-listener="default"> 3

        ...

        <in-vm-acceptor
          name="in-vm"
          server-id="0" />

        ...
    </server>
</subsystem>

1

The <http-connector> element called http-connector uses the endpoint attribute to reference the <http-acceptor> element called http-acceptor.

2

The <in-vm-connector> element does not need to reference any <in-vm-acceptor> element because local clients do not need discovery to find the messaging server.

3

The <http-acceptor> element references the http-listener called default, which is defined by the undertow subsystem.

The remote type is a third connector and acceptor type that JBoss EAP supports. This type enables remote clients to connect to the messaging server by using the ActiveMQ native protocol instead of HTTP tunneling. The ActiveMQ native protocol is required by remote clients running external to the JBoss EAP server. Additionally, it enables remote clients to connect to standalone ActiveMQ servers.

Creating a new <remote-connector> and <remote-acceptor> pair on JBoss EAP also requires creating a new <socket-binding>. These provide the IP address and TCP port to be used by the <remote-acceptor>.

JMS Connection Factories and Pooled-Connection Factories

Connection factory resources defined inside the messaging-activemq subsystem refer to an ActiveMQ connector also defined in the same subsystem. The following excerpt shows the connection-factory resources in the default JBoss EAP configuration files:

<subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">
    <server name="default">
        ....
        <connection-factory
          name="InVmConnectionFactory"
          connectors="in-vm"
          entries="java:/ConnectionFactory" /> 1

        <connection-factory
          name="RemoteConnectionFactory"
          connectors="http-connector"
          entries="java:jboss/exported/jms/RemoteConnectionFactory"/> 2
        ...
    </server>
</subsystem>

1

The <connection-factory> element is called InVmConnectionFactory and refers to the <in-vm-connector> element called in-vm. It serves applications by using the JMS API in the Java SE style, but still deployed within JBoss EAP. It should not be used by enterprise components, such as servlets and EJBs.

2

The <connection-factory> element is called RemoteConnectionFactory and refers to the <http-connector> element called http-connector. It serves remote JMS clients connecting to the embedded ActiveMQ.

Each <connection-factory> element refers to a different connector and is bound to different JNDI names by using the entries attribute.

Jakarta EE applications should not use the JMS ConnectionFactory resources. Instead, they should use a JMS PooledConnectionFactory, which provides the following:

  • Reuse of connections to the messaging server

  • XA transaction integration

  • JAAS security context propagation

The following excerpt shows the pooled-connection-factory resource in the default JBoss EAP configuration files:

<subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">
    <server name="default">
        ...
        <pooled-connection-factory
          name="activemq-ra" transaction="xa"
          connectors="in-vm"
          entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" />
        ...
    </server>
</subsystem>

In this example, the pooled connection factory is used by Jakarta EE applications when no connection factory is declared. Notice that the pooled connection factory refers to the in-vm connector.

If a different messaging server is to be used by default, then the factory should either be changed to refer to a different connector element or replaced by one referring to a JCA resource adapter.

Applications might refer to a connection factory via a JNDI name that does not exist. Thus, administrators must create a new pooled-connection-factory resource under the same JNDI name referring to the correct connector.

For example, to use the JNDI name java:/MyCF and point to the embedded messaging server, add the following to the messaging-activemq subsystem:

<pooled-connection-factory name="mycf" transaction="xa" connectors="in-vm" entries="java:/MyCF"/>

The following CLI command creates the resource from the previous listing under the full profile for a JBoss EAP managed domain:

[domain@localhost:9990 /] cd /profile=full/subsystem=messaging-activemq/​server=default
[domain@localhost:9990 server=default] ./pooled-connection-factory=mycf:add(\
connectors=[in-vm], entries=[java:/jms/MyCF])

If an application refers to a non-existing JNDI name it might deploy without errors, and throw Java NamingException errors only at run-time, when the application tries to actually connect to the messaging server.

The reason to use a pooled connection factory instead of a regular connection factory is the same as using a JDBC datasource instead of a driver manager. Although Jakarta EE applications can use connection factories and driver managers, they are less efficient due to the following reasons:

  • The application must include additional code to manage sharing connections between multiple threads, which reduces scalability.

  • The application creates and destroys connections for each user request, which are computationally expensive.

Both JDBC datasource and JMS pooled connection factory objects bring connection pools to improve application performance and scalability. With JDBC, the difference is that the developer must use the right interface, but for JMS only the administrator has to create the correct resource type. This is because a PooledConnectionFactory is also a ConnectionFactory.

JMS Destinations

When using the embedded Message-oriented Middleware (MOM) from JBoss EAP, creating the JMS destinations resources also creates the underlying MOM objects. This facility is provided by the messaging-activemq subsystem that closely integrates JBoss EAP with the embedded ActiveMQ instance.

Note

If using an external MOM, JMS destinations are configured as part of the JMS Provider configuration in the naming and resource-adapters subsystems, but creating them does not creates the underlying objects in the MOM. To learn more about connecting JBoss EAP applications to external MOMs, see the references section.

To create a destination by using the CLI, create either a jms-queue or a jms-topic resource. For example, the following command create a topic called stocks that is bound to the JNDI name java:/jms/broker/StockUpdates:

[domain@localhost:9990 server=default] ./jms-topic=stocks:add(entries=[java:/jms/broker/StockUpdates])

The previous command adds the following to the domain mode configuration files:

<jms-topic
  name="stocks" 1
  entries="java:/jms/broker/StockUpdates"/> 2

1

The name attribute is the name of the managed object. This name is only administrative, as it is not used by applications that use the JMS API.

2

The entries attribute provides one or more JNDI names for the resource. These are the names visible to applications.

A jms-queue resource can have all attributes from a jms-topic resource as well as the following attributes:

  • durable: if it is true, then messages in this queue are saved to disk and are not lost on MOM restart. If it is false, then messages are kept only in memory and can be discarded in situations such as out-of-memory conditions.

  • selector: provides a filter for messages accepted by this queue. For more information, refer to the JMS specification.

JMS destinations for the embedded MOM in JBoss EAP are created and configured by using the management console. To view the destinations in managed domain mode, navigate to ConfigurationProfiles, select either full or menu:[\full-ha], and select MessagingServerdefaultDestinations. Click View next to the Destinations button.

Figure 8.1: Destinations navigation

Within the destinations page, click either JMS Queue or JMS Topic to manage the corresponding destinations.

Figure 8.2: Managing JMS queues

From this page, destinations can be created, modified, and removed. Use the links on the left to configure other messaging parameters.

Monitoring JMS Destinations

In the embedded ActiveMQ instance, JMS destinations are monitored by using object run-time attributes and operations.

Note

Only a few attributes and operations are covered in this course, so use the CLI operations read-resource-description and read-resource-operations to learn about additional ones.

In standalone server mode, monitoring attributes and operations are available on the same object that defines the resource as part of the server profile. For example, on a queue object, the message-count attribute stores the number of messages waiting to be consumed. To view this count on a hypothetical queue called MyQueue, use the following command:

[standalone@localhost:9990 /] cd /subsystem=messaging-activemq/server=default
[standalone@localhost:9990 server=default] ./jms-queue=MyQueue:read-attribute(\
name=message-count)

In managed domain server mode, the same attributes and operations are available from a running server instance, but not from the subsystem configuration. For example, the messages-added operation counts the number of messages published to the destination since the MOM was started.

Messages are listed in the DMR format, but each message only shows headers and properties as object attributes. There is no way to see a message body by using the management CLI.

To list the number of messages waiting to be consumed in a queue called MyQueue within the srv1 server on the devhost host, use the following command to invoke the list-messages operation:

[domain@localhost:9990 /] cd /host=devhost/server=srv1
[domain@localhost:9990 server=srv1] cd ./subsystem=messaging-activemq/server=default
[domain@localhost:9990 server=default] ./jms-queue=MyQueue:list-messages
{
    "outcome" => "success",
    "result" => [ 1
        {
            "JMSPriority" => 4, 2
            "JMSMessageID" => "ID:b921a30-12e4-11e6-ae18-597e323e1397",
            "address" => "jms.queue.TestQueue", 3
            "JMSExpiration" => 0,
            "AMQ_CID" => "f51cfb7a-12e4-11e6-ae18-597e323e151397",
            "MyAppProperty" => "MyAppValueXYZ", 4
            "JMSTimestamp" => 1462468442322L,
            "messageID" => 5,
            "JMSDeliveryMode" => "PERSISTENT"
        },
        {
            "JMSPriority" => 4,
            "JMSMessageID" => "ID:f5136421-12e4-11e6-ae18-597e323e2def",
            "address" => "jms.queue.TestQueue",
            "JMSExpiration" => 0,
            "AMQ_CID" => "3d0cfb7a-12e4-11e6-ae18-597e323e2def",
            "OtherAppProperty" => "OtherValueASD",
            "JMSTimestamp" => 1462468442339L,
            "messageID" => 9,
            "JMSDeliveryMode" => "PERSISTENT"
        }
    ]
}

1

The result attribute is an array containing two objects, each containing a single message. These attributes show the headers and properties of the JMS message.

2

The JMS specification defines some properties, such as those with the JMS prefix.

3

The MOM defines others, such as address and messageID.

4

The application defines some properties, such as MyAppProperty and OtherAppProperty. These properties are meaningless to the JMS API and the MOM.

There is no way to distinguish attributes and message headers from message properties just by the list-messages operation output. It is similarly impossible to determine which ones are defined by the MOM.

Naturally, the attributes and operations differ for queues and topics. For example, only topics have subscribers. Check the JBoss EAP and A-MQ product documentation and the JMS specification for information about specific headers and properties. Also check with the application developer about application-defined properties.

References

JSR 343: JMS Specification

For more information about ActiveMQ embedded in JBoss EAP, see the ActiveMQ Artemis section in the Configuring Messaging guide of the Red Hat documentation at Configuring Messaging

For more information about connecting JBoss EAP appliccations to external MOMs, see the Resource Adapters chapter in the Configuring Messaging guide of the Red Hat documentation at https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.4/html-single/configuring_messaging/index#resource_adapters

Revision: ad248-7.4-18a9db2