or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdconnection-management.mdcore-operations.mddestination-resolution.mdindex.mdmessage-conversion.mdmessage-listeners.md
tile.json

tessl/maven-org-springframework--spring-jms

Spring JMS integration module that simplifies JMS development by providing template-based messaging, message-driven POJOs, declarative transaction management, and comprehensive exception handling

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
mavenpkg:maven/org.springframework/spring-jms@6.2.x

To install, run

npx @tessl/cli install tessl/maven-org-springframework--spring-jms@6.2.0

index.mddocs/

Spring JMS

Spring JMS integration module that simplifies JMS development by providing template-based messaging, message-driven POJOs, declarative transaction management, and comprehensive exception handling. It serves as the foundation for building robust message-driven applications within the Spring ecosystem.

Package Information

  • Package Name: spring-jms
  • Package Type: maven
  • Language: Java
  • Installation:
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jms</artifactId>
      <version>6.2.8</version>
    </dependency>

Core Imports

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;

Basic Usage

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

@Component
public class OrderService {
    
    @Autowired
    private JmsTemplate jmsTemplate;
    
    // Send a message
    public void placeOrder(Order order) {
        jmsTemplate.convertAndSend("order.queue", order);
    }
    
    // Receive messages using @JmsListener
    @JmsListener(destination = "order.queue")
    public void processOrder(Order order) {
        System.out.println("Processing order: " + order.getId());
        // Process order logic here
    }
}

// Configuration
@Configuration
@EnableJms
public class JmsConfig {
    
    @Bean
    public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory());
        return factory;
    }
    
    @Bean
    public JmsTemplate jmsTemplate() {
        return new JmsTemplate(connectionFactory());
    }
}

Architecture

Spring JMS provides a layered architecture for JMS integration:

  • JmsTemplate: Central class providing synchronous JMS operations with template pattern
  • Listener Containers: Manage message-driven beans and polling for asynchronous message consumption
  • Message Converters: Handle conversion between Java objects and JMS messages
  • Connection Management: Provide connection pooling, caching, and transaction-aware connections
  • Destination Resolution: Abstract destination lookup supporting JNDI, dynamic, and bean factory-based resolution
  • Exception Translation: Convert vendor-specific JMS exceptions to Spring's consistent exception hierarchy

This design enables enterprise messaging patterns while maintaining Spring's programming model consistency and providing extensive configuration options for various JMS providers.

Capabilities

Core JMS Operations

Central messaging operations using the template pattern for synchronous JMS operations including sending, receiving, and browsing messages with comprehensive configuration options.

public interface JmsOperations {
    void send(String destinationName, MessageCreator messageCreator) throws JmsException;
    void convertAndSend(String destinationName, Object message) throws JmsException;
    Message receive(String destinationName) throws JmsException;
    Object receiveAndConvert(String destinationName) throws JmsException;
}

public class JmsTemplate implements JmsOperations {
    public JmsTemplate();
    public JmsTemplate(ConnectionFactory connectionFactory);
    
    // Configuration methods
    public void setConnectionFactory(ConnectionFactory connectionFactory);
    public void setDefaultDestinationName(String defaultDestinationName);
    public void setMessageConverter(MessageConverter messageConverter);
    public void setReceiveTimeout(long receiveTimeout);
}

Core Operations

Message Listeners and Containers

Asynchronous message processing through listener containers and annotation-driven message handling with @JmsListener support for building message-driven applications.

@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface JmsListener {
    String destination() default "";
    String containerFactory() default "";
    String selector() default "";
}

public class DefaultMessageListenerContainer extends AbstractMessageListenerContainer {
    public DefaultMessageListenerContainer();
    public void setConnectionFactory(ConnectionFactory connectionFactory);
    public void setDestinationName(String destinationName);
    public void setMessageListener(MessageListener messageListener);
}

Message Listeners

Message Conversion

Comprehensive message conversion system for automatic translation between Java objects and JMS messages, supporting JSON, XML, and custom serialization formats.

public interface MessageConverter {
    Message toMessage(Object object, Session session) throws JMSException, MessageConversionException;
    Object fromMessage(Message message) throws JMSException, MessageConversionException;
}

public class SimpleMessageConverter implements MessageConverter {
    public SimpleMessageConverter();
}

public class MappingJackson2MessageConverter implements MessageConverter {
    public MappingJackson2MessageConverter();
    public void setObjectMapper(ObjectMapper objectMapper);
    public void setTargetType(MessageType targetType);
}

Message Conversion

Connection Management

Connection factory implementations providing connection pooling, caching, single connection sharing, and transaction-aware connection management for optimal resource utilization.

public class CachingConnectionFactory implements ConnectionFactory {
    public CachingConnectionFactory();
    public CachingConnectionFactory(ConnectionFactory targetConnectionFactory);
    public void setSessionCacheSize(int sessionCacheSize);
    public void setCacheProducers(boolean cacheProducers);
    public void setCacheConsumers(boolean cacheConsumers);
}

public class SingleConnectionFactory implements ConnectionFactory {
    public SingleConnectionFactory();
    public SingleConnectionFactory(ConnectionFactory targetConnectionFactory);
    public void setReconnectOnException(boolean reconnectOnException);
}

Connection Management

Destination Resolution

Pluggable destination resolution supporting JNDI lookups, dynamic destination creation, bean factory integration, and caching for flexible destination management.

public interface DestinationResolver {
    Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain) 
        throws JMSException;
}

public class DynamicDestinationResolver implements DestinationResolver {
    public DynamicDestinationResolver();
}

public class JndiDestinationResolver implements DestinationResolver {
    public JndiDestinationResolver();
    public void setJndiTemplate(JndiTemplate jndiTemplate);
    public void setCache(boolean cache);
}

Destination Resolution

Configuration Support

Factory classes and configuration support for creating and managing JMS listener containers, annotation processing, and XML namespace support for declarative configuration.

public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMessageListenerContainer> 
    implements JmsListenerContainerFactory<C> {
    
    public void setConnectionFactory(ConnectionFactory connectionFactory);
    public void setDestinationResolver(DestinationResolver destinationResolver);
    public void setMessageConverter(MessageConverter messageConverter);
}

public class DefaultJmsListenerContainerFactory extends AbstractJmsListenerContainerFactory<DefaultMessageListenerContainer> {
    public DefaultJmsListenerContainerFactory();
}

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface EnableJms {
}

Configuration

Types

// Core interfaces
public interface ConnectionFactory {
    Connection createConnection() throws JMSException;
    Connection createConnection(String userName, String password) throws JMSException;
}

public interface MessageCreator {
    Message createMessage(Session session) throws JMSException;
}

public interface SessionCallback<T> {
    T doInJms(Session session) throws JMSException;
}

public interface ProducerCallback<T> {
    T doInJms(Session session, MessageProducer producer) throws JMSException;
}

// Quality of Service settings
public class QosSettings {
    public QosSettings();
    public QosSettings(int deliveryMode, int priority, long timeToLive);
    
    public void setDeliveryMode(int deliveryMode);
    public void setPriority(int priority);  
    public void setTimeToLive(long timeToLive);
}

// Exception hierarchy
public abstract class JmsException extends NestedRuntimeException {
    public JmsException(String msg);
    public JmsException(String msg, Throwable cause);
}

public class UncategorizedJmsException extends JmsException {
    public UncategorizedJmsException(JMSException cause);
}

// Additional supporting interfaces
public interface InvocableHandlerMethod {
    Object invoke(Message message, Object... providedArgs) throws Exception;
}

public interface HandlerMethodArgumentResolver {
    boolean supportsParameter(MethodParameter parameter);
    Object resolveArgument(MethodParameter parameter, Message message) throws Exception;
}

public interface ErrorHandler {
    void handleError(Throwable t);
}

public interface BackOff {
    BackOffExecution start();
}

public interface BackOffExecution {
    long nextBackOff();
}