Common utilities, API classes, and shared functionality for Apache ActiveMQ Artemis message broker
npx @tessl/cli install tessl/maven-org-apache-activemq--artemis-commons@2.42.0Apache ActiveMQ Artemis Commons provides essential common utilities, API classes, exception definitions, and shared functionality for the Apache ActiveMQ Artemis message broker ecosystem. This library serves as the foundational layer containing core APIs, utility classes, JSON processing capabilities, and shared data structures that other Artemis components depend upon.
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>artemis-commons</artifactId>
<version>2.42.0</version>
</dependency>// Core API classes
import org.apache.activemq.artemis.api.core.QueueConfiguration;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
import org.apache.activemq.artemis.api.core.RoutingType;
// Exception handling
import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.api.core.ActiveMQExceptionType;
// Utilities
import org.apache.activemq.artemis.utils.ByteUtil;
import org.apache.activemq.artemis.utils.ActiveMQThreadFactory;
import org.apache.activemq.artemis.utils.FileUtil;
import org.apache.activemq.artemis.utils.TimeUtils;
import org.apache.activemq.artemis.utils.UTF8Util;
import org.apache.activemq.artemis.utils.UUID;
import org.apache.activemq.artemis.utils.UUIDGenerator;
// Collections
import org.apache.activemq.artemis.utils.collections.TypedProperties;
import org.apache.activemq.artemis.utils.collections.ConcurrentLongHashMap;
import org.apache.activemq.artemis.utils.collections.ConcurrentHashSet;
import org.apache.activemq.artemis.utils.collections.LinkedListImpl;
// Actor Framework
import org.apache.activemq.artemis.utils.actors.Actor;
import org.apache.activemq.artemis.utils.actors.ThresholdActor;
import org.apache.activemq.artemis.utils.actors.OrderedExecutor;
// JSON API (shaded)
import org.apache.activemq.artemis.json.JsonObject;
import org.apache.activemq.artemis.json.JsonArray;
import org.apache.activemq.artemis.utils.JsonLoader;import org.apache.activemq.artemis.api.core.QueueConfiguration;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.RoutingType;
// Create a queue configuration with fluent API
QueueConfiguration queueConfig = QueueConfiguration.of("myQueue")
.setAddress(SimpleString.of("myAddress"))
.setRoutingType(RoutingType.ANYCAST)
.setDurable(true)
.setMaxConsumers(10);
// Convert to JSON
String jsonString = queueConfig.toJSON();
// Create from JSON
QueueConfiguration fromJson = QueueConfiguration.fromJSON(jsonString);
// Work with SimpleString for performance
SimpleString address = SimpleString.of("my.address.name");
boolean isMatch = address.startsWith(SimpleString.of("my."));Artemis Commons is organized into several key architectural layers:
org.apache.activemq.artemis.api.core): Primary API classes for queue configuration, buffer operations, and core data typesorg.apache.activemq.artemis.utils): Threading, pooling, validation, and general-purpose utilitiesorg.apache.activemq.artemis.json): Complete shaded JSON API based on Jakarta JSON and Apache Johnzonorg.apache.activemq.artemis.logs): Internationalized logging with audit capabilitiesKey design principles:
Central configuration classes and core data types for queue management, message routing, and buffer operations.
// Queue configuration with fluent API
QueueConfiguration config = QueueConfiguration.of("queueName")
.setAddress(SimpleString.of("address"))
.setRoutingType(RoutingType.ANYCAST);
// High-performance string handling
SimpleString str = SimpleString.of("text");
byte[] data = str.getData();
// Buffer operations
ActiveMQBuffer buffer = /* ... */;
buffer.writeSimpleString(str);Specialized high-performance collection implementations for concurrent operations, primitive types, and type-safe properties.
// Concurrent collections with no boxing overhead
ConcurrentLongHashMap<Message> messages = new ConcurrentLongHashMap<>(1000);
messages.put(messageId, message);
// Type-safe properties with JMS-compliant conversions
TypedProperties props = new TypedProperties();
props.putIntProperty(SimpleString.of("priority"), 5);Asynchronous message processing framework with guaranteed ordering, backpressure management, and sophisticated state control.
// Create actor for ordered message processing
Actor<String> actor = new Actor<>(executor, message -> processMessage(message));
actor.act("message");
// Threshold-based flow control
ThresholdActor<Buffer> bufferActor = new ThresholdActor<>(
executor, this::processBuffer, maxSize, Buffer::size,
this::applyBackpressure, this::releaseBackpressure);Comprehensive exception hierarchy with 40+ specific exception types for different error conditions in ActiveMQ Artemis.
try {
// ActiveMQ operations
} catch (ActiveMQException e) {
ActiveMQExceptionType type = e.getType();
// Handle based on specific exception type
}Threading, pooling, validation, environment access, and general-purpose utilities for Artemis components.
// Thread factory with proper naming
ActiveMQThreadFactory factory = new ActiveMQThreadFactory("MyGroup", true, classLoader);
Thread thread = factory.newThread(runnable);
// Byte utilities
byte[] bytes = ByteUtil.hexStringToByteArray("48656c6c6f");
String hex = ByteUtil.bytesToHex(bytes);Complete JSON API implementation with object/array builders, providing Jakarta JSON compatibility through shaded dependencies.
// Create JSON objects
JsonObject obj = JsonLoader.createObjectBuilder()
.add("name", "value")
.add("number", 42)
.build();
// Parse JSON
JsonObject parsed = JsonLoader.readObject(new StringReader(jsonString));
String value = parsed.getString("name");Internationalized logging framework with audit capabilities for system events and operations.
// Access logging interfaces
ActiveMQUtilLogger logger = /* ... */;
AuditLogger.log(event, details);// Core routing types
enum RoutingType {
MULTICAST(0),
ANYCAST(1);
byte getType();
static RoutingType getType(byte type);
}
// Generic pair utility
class Pair<A, B> implements Serializable {
public A a;
public B b;
public Pair(A a, B b);
}
// Object + long combination
class ObjLongPair<A> {
public A obj;
public long longValue;
public ObjLongPair(A obj, long longValue);
}