Skip to content

Configuring ActiveMQ Classic for Martini

ActiveMQ Classic is embedded within the Martini Server Runtime and is used by default for development purposes. This setup simplifies the development process by providing a ready-to-use messaging solution. However, for enhanced performance and reliability in production environments, it is strongly recommended to switch to a standalone instance of ActiveMQ. A standalone configuration offers greater scalability, improved resource management, and better overall performance, making it a more suitable choice for production-level applications.

1
INFO [MartiniBrokerConfiguration] Using broker configuration at '<martini-home>/conf/broker/activemq-embedded.xml'

Transport Connectors

Transport connectors define communication protocols for clients to connect to the ActiveMQ broker. Martini supports various transport protocols, including TCP, VM, AMQP, MQTT, and STOMP. Configuring a transport connector involves adjusting its settings to meet your specific requirements, such as security settings, protocol-specific configurations, and performance tuning.

Adding a Transport Connector

To add a transport connector:

  1. Open the activemq-embedded.xml file located at <martini-home>/conf/broker.
  2. Locate the transportConnectors property under the broker bean.
  3. Modify the connector's properties according to your requirements.
  4. Add a new TransportConnector bean with the desired URI for the new transport protocol. This might include setting up SSL/TLS, adjusting client connection limits, or configuring protocol-specific options. For example, configuring an MQTT connector for better security might involve adding SSL/TLS properties to the connector's configuration.
  5. Save the file and restart Martini Server Runtime to apply the changes.

Editing a Transport Connector

To edit a transport connector:

  1. Modify the existing TransportConnector bean elements in the activemq-embedded.xml file.
  2. Save the changes and restart Martini Server Runtime to reflect the updates.

Removing a Transport Connector

To remove a transport connector:

  1. Comment out or remove the corresponding TransportConnector bean element from the activemq-embedded.xml file.
  2. Save the file and restart Martini Server Runtime as needed.

Using a External ActiveMQ Classic Instance

ActiveMQ Classic can be connected to by the Martini Server Runtime, providing the capability to integrate with an external instance. This integration allows users to leverage the robust messaging features of ActiveMQ, facilitating efficient communication between applications. By configuring the connection settings, developers can utilize the external broker for message sending and receiving, enhancing the overall scalability and performance of their messaging workflows.

Prerequisites

Before configuring Martini Server Runtime to connect with an ActiveMQ Classic broker, ensure the following prerequisite is met:

  • Apache ActiveMQ Classic: Ensure your message broker is running. You can follow guides for setup here: Standalone or Docker Container.

Connect to a remote ActiveMQ Classic instance

  1. Configure Martini's connection properties in the <martini-home>/conf/overrides/override.properties. Configuration properties: These properties represent the bare minimum requirements needed to get started with the application.

    1
    2
    3
    jms.configuration-file=activemq-external
    # The URL of the remote broker. 
    activemq.uri=tcp://[HOST]:61616
    

    Authentication properties: If you are using the default credentials, you can skip the following properties. For guidance on setting up authentication, refer to the documentation here.

    1
    2
    3
    4
    5
    6
    # Sets the login when connecting to a remote ActiveMQ broker.
    # If unspecified, Martini will use 'guest' for the login.
    activemq.username=[username]
    # Sets the password when connecting to a remote ActiveMQ broker.
    # If unspecified, Martini will use 'guest' for the password.
    activemq.password=[password]
    

    JMS properties: These settings will prevent Martini colliding with different instances with the default properties.

    1
    2
    3
    4
    5
    6
    # The value of this property must be unique among clients connected to the ActiveMQ instance.
    # This is used to identify the name of the Martini instance in the ActiveMQ connections.
    jms.client-id=[client-id]
    # The prefix is added to mitigate overlapping JMS destinations and to distinguish between different Martini instances connected to a single message broker.
    # It adds a prefix to the beginning of a queue and topic; for example: `your-prefix.io.lonti.martini`
    jms.destination-prefix=your-prefix
    
  2. Restart Martini Server Runtime to apply the changes.

  3. Verify connection establishment.
1
INFO [MartiniBrokerConfiguration] Using broker configuration at '<martini-home>/conf/broker/activemq-external.xml'

Advanced properties

These properties will optimize the performance of ActiveMQ Classic on Martini. Adjust them according to the needs of your applications.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# The maximum amount of times the message is redelivered to the queue
# before it is thrown to the DLQ (Dead Letter Queue).
# If unspecified, this is set to 6.
# Use -1 to set it to an unlimited amount.
activemq.maximum-redeliveries=5

# The amount of time (in milliseconds) before a message is to be redelivered.
# If unspecified, this is set to -1.
activemq.maximum-redelivery-delay=5000

# Set to true to acknowledge receipt of messages back to the broker in batches (to improve performance).
# If unspecified, defaults to 'true'.
activemq.optimize-acknowledge=true

# The percentage (%) threshold applied to Martini's total allocated JVM memory which,
# when exceeded, will cause the destination's cursor to either block or be written
# to disk while waiting to be processed.
#
# Be careful when setting the value as this may lead to OOM if improperly configured.
activemq.cursor-memory-high-water-mark=25

# If true, ActiveMQ connections will send messages asynchronously.
# This adds a massive performance boost, but could lead to message loss
# since there is no guarantee that messages have been sent or not.
# If unspecified, defaults to 'true'.
activemq.send-asynchronously=true

# If true, advisory topics are created which can be used to receive information
# regarding what is happening on your JMS provider,
# along with what's happening with producers, consumers and destinations.
# If unspecified, defaults to 'false'.
activemq.watch-topic-advisories=true

# A hint to set the maximum size of the message data logs.
# By default, this is set to 32MB.
activemq.maximum-data-log-size=33554432

#Controls storage space usage by the ActiveMQ broker
#Configure the maximum storage limit for broker usage
#defaults to 100GB (https://activemq.apache.org/xml-configuration)
# 107374182400 in bytes
activemq.broker-storage-limit-size=107374182400

Master / Slave setup

For improved performance and high availability, consider configuring ActiveMQ in a master / slave setup. This configuration is particularly beneficial for Martini's performance, especially when handling search indices. For more information, refer to Introduction to Master / Slave by Apache.

1
activemq.uri=failover:(tcp://broker1:61616,tcp://broker2:61616,tcp://broker3:61616)

Failover Transport setup

For improved redundancy, consider configuring ActiveMQ in a Failover setup. This setup ensures continuous operation during broker failures, failover allows for seamless reconnection without manual intervention, which simplifies the application's architecture and improves user experience. It guarantees message delivery, preventing data loss and maintaining integrity, while also enabling load balancing through broker redundancy. For more information, refer to The Failover Transport by Apache.

1
activemq.uri=failover:(tcp://localhost:61616,tcp://remotehost:61616)?initialReconnectDelay=100

ActiveMQ Classic Configuration

Configure ActiveMQ instances via XML for advanced options and flexibility. Key configurations include:

  • broker bean element
  • Destination policies
  • Management context
  • KahaDB directory
  • Transport connectors (e.g., openwire for fail-over)

Refer to Apache documentation for detailed configuration instructions on ActiveMQ Classic.

Testing

Refer to JMS Messaging to learn more about sending and receiving JMS messages.