Morphium version 6

info

date: 2025-10-08 21:14:10

tags:

category: morphium

Created by: Stephan BΓΆsebeck

logged in

ADMIN


Morphium version 6

Announcing Morphium 6.0: Modern Java ODM with Built-in Messaging

Today we're thrilled to announce Morphium 6.0, a major release of our feature-rich MongoDB Object Document Mapper for Java. This release brings full JDK 21 support, a completely rewritten messaging system, and comprehensive new documentation.

What Makes Morphium Special?

Morphium isn't just another MongoDB ODM. It's a complete data layer solution that includes:

  • πŸ—„οΈ Powerful Object Mapping with annotation-driven configuration
  • πŸ“¨ Built-in Message Queue using MongoDB as the backend
  • ⚑ Multi-level Caching with automatic cluster synchronization
  • πŸ§ͺ In-Memory Driver for lightning-fast testing (no MongoDB needed!)
  • 🎯 JMS API Support for standards-based messaging

The key differentiator? You get distributed messaging without adding RabbitMQ, Kafka, or ActiveMQ to your infrastructure. If you're already using MongoDB, you already have everything you need.

Highlights of Version 6.0

JDK 21 & Modern Java

Morphium 6.0 embraces modern Java features:

  • Virtual threads for improved messaging concurrency
  • Pattern matching for cleaner code
  • Full support for Records as entities
  • Sealed classes for better domain modeling

Enhanced Messaging System

The MongoDB-based messaging system has been rewritten from the ground up:

// Setup is simple
Messaging messaging = new Messaging(morphium, 100, true);
messaging.start();

// Send messages with priorities and TTL
Msg message = new Msg("orderQueue", "Process Order", orderData);
message.setPriority(5);
message.setTtl(300000)// 5 minutes
messaging.sendMessage(message);

// Process messages
messaging.addMessageListener((msg, m) -> {
    processOrder(msg.getValue());
    return true; // Message handled
});

Why use Morphium Messaging?

βœ… Zero additional infrastructure (uses your existing MongoDB) βœ… Persistent by default (messages survive restarts) βœ… Distributed locking built-in βœ… Supports priorities, TTL, exclusive & broadcast modes βœ… JMS compatible for legacy integration

Performance in 6.0:

  • 90%+ reduction in duplicate message processing
  • Virtual thread integration for better concurrency
  • Optimized queries for 5,000-8,000 msg/sec throughput
  • Improved multi-instance coordination

In-Memory Driver for Testing

One of Morphium's killer features is the InMemoryDriver:

# Run your entire test suite without MongoDB
./runtests.sh  --driver inmem --tags core,messaging

# 10-100x faster than testing against real MongoDB
# Perfect for CI/CD pipelines
# No external dependencies needed

The InMemoryDriver provides ~93% MongoDB feature coverage including:

  • Full CRUD operations with all standard operators
  • Complete aggregation pipeline with $lookup, $graphLookup, $bucket, $mergeObjects
  • MapReduce support with JavaScript engine integration
  • Array operators including $pop, $push, $pull, $addToSet
  • Transactions (single-instance)
  • Change streams (basic)
  • Drop-in replacement for most development and testing scenarios

Quick Comparison: Morphium vs. Alternatives

AspectMorphiumSpring Data + RabbitMQKafka
InfrastructureMongoDB onlyMongoDB + RabbitMQMongoDB + Kafka
Setup Complexity⭐ Very Low⭐⭐⭐ Medium⭐⭐⭐⭐⭐ High
Message PersistenceBuilt-inConfigureBuilt-in
Message Prioritiesβœ… Yesβœ… Yes❌ No
Distributed Locksβœ… Yes❌ No❌ No
ThroughputMedium (8K msg/s)High (50K msg/s)Very High (100K+ msg/s)
Operations⭐ Very Simple⭐⭐ Medium⭐⭐⭐⭐ Complex

Use Morphium when:

  • You already use MongoDB
  • You need simple, reliable messaging (<10K msg/sec)
  • You want to minimize operational complexity
  • You need persistent messages by default

Consider alternatives when:

  • You need ultra-high throughput (>100K msg/sec)
  • You need complex routing patterns
  • You're building a streaming platform

Real-World Use Case

Here's a simplified example from an e-commerce application:

@Entity
@Cache(readCache = true, writeCache = true, syncCache = true)
public class Order {
    @Id private ObjectId id;
    private String customerId;
    private List<OrderItem> items;
    private OrderStatus status;
    private LocalDateTime createdAt;
}

// Service layer with caching
public class OrderService {
    private final Morphium morphium;
    private final Messaging messaging;

    public Order createOrder(Order order) {
        // Store with automatic caching
        order.setCreatedAt(LocalDateTime.now());
        order.setStatus(OrderStatus.PENDING);
        morphium.store(order);

        // Send async notification
        Msg msg = new Msg("order.created", "New Order", order.getId());
        msg.setPriority(5);
        messaging.sendMessage(msg);

        return order;
    }

    public void processOrders() {
        // Listen for order events
        messaging.addMessageListener((msg, m) -> {
            ObjectId orderId = new ObjectId(msg.getValue().toString());

            // Query with caching - subsequent calls hit cache
            Order order = morphium.findById(Order.class, orderId);

            // Process order...
            order.setStatus(OrderStatus.PROCESSING);
            morphium.store(order)// Cache auto-invalidated

            return true;
        });
    }
}

This example shows:

  • Automatic caching with cluster synchronization (syncCache = true)
  • Async messaging for event-driven architecture
  • Clean, intuitive API
  • Zero additional infrastructure

Getting Started

Add to your pom.xml:

<dependency>
    <groupId>de.caluga</groupId>
    <artifactId>morphium</artifactId>
    <version>6.0.0</version>
</dependency>

Basic configuration (morphium.properties):

morphium.hosts=mongo1.example.com:27017,mongo2.example.com:27017
morphium.database=myapp
morphium.replicaSet=myReplicaSet
morphium.safe=true
morphium.writeTimeout=5000

Initialize:

MorphiumConfig config = MorphiumConfig.fromProperties(
    getClass().getResourceAsStream("/morphium.properties")
);
Morphium morphium = new Morphium(config);

That's it! You're ready to go.

Migration from 5.x

Morphium 6.0 maintains backward compatibility for most features. Key changes:

  1. JDK 21 required - Update your Java version
  2. Minor API changes in messaging for virtual thread support
  3. Deprecated methods removed - Update to recommended alternatives

See our detailed migration guide for complete instructions.

Documentation & Resources

We've completely rewritten the documentation:

What's Next?

We're already planning improvements for 6.x and beyond:

Coming in 6.x:

  • Enhanced InMemoryDriver with more MongoDB 7.0 features
  • Better change streams integration
  • Built-in Prometheus metrics

Looking ahead to 7.0:

  • MongoDB 8.0 support
  • Native GraalVM support
  • Vector search integration
  • Reactive streams API

Try It Today!

# Maven Central
6.0.0

# Or build from source
git clone https://github.com/sboesebeck/morphium.git
mvn clean install

We'd love to hear your feedback! Open issues, contribute code, or share your use cases on GitHub.


Questions? Check our documentation or open an issue on GitHub.

Upgrading? See the migration guide for step-by-step instructions.

Happy coding! πŸš€