or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

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

0

# Spring JMS

1

2

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.

3

4

## Package Information

5

6

- **Package Name**: spring-jms

7

- **Package Type**: maven

8

- **Language**: Java

9

- **Installation**:

10

```xml

11

<dependency>

12

<groupId>org.springframework</groupId>

13

<artifactId>spring-jms</artifactId>

14

<version>6.2.8</version>

15

</dependency>

16

```

17

18

## Core Imports

19

20

```java

21

import org.springframework.jms.core.JmsTemplate;

22

import org.springframework.jms.annotation.JmsListener;

23

import org.springframework.jms.annotation.EnableJms;

24

import org.springframework.jms.config.DefaultJmsListenerContainerFactory;

25

```

26

27

## Basic Usage

28

29

```java

30

import org.springframework.beans.factory.annotation.Autowired;

31

import org.springframework.jms.core.JmsTemplate;

32

import org.springframework.jms.annotation.JmsListener;

33

import org.springframework.stereotype.Component;

34

35

@Component

36

public class OrderService {

37

38

@Autowired

39

private JmsTemplate jmsTemplate;

40

41

// Send a message

42

public void placeOrder(Order order) {

43

jmsTemplate.convertAndSend("order.queue", order);

44

}

45

46

// Receive messages using @JmsListener

47

@JmsListener(destination = "order.queue")

48

public void processOrder(Order order) {

49

System.out.println("Processing order: " + order.getId());

50

// Process order logic here

51

}

52

}

53

54

// Configuration

55

@Configuration

56

@EnableJms

57

public class JmsConfig {

58

59

@Bean

60

public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {

61

DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();

62

factory.setConnectionFactory(connectionFactory());

63

return factory;

64

}

65

66

@Bean

67

public JmsTemplate jmsTemplate() {

68

return new JmsTemplate(connectionFactory());

69

}

70

}

71

```

72

73

## Architecture

74

75

Spring JMS provides a layered architecture for JMS integration:

76

77

- **JmsTemplate**: Central class providing synchronous JMS operations with template pattern

78

- **Listener Containers**: Manage message-driven beans and polling for asynchronous message consumption

79

- **Message Converters**: Handle conversion between Java objects and JMS messages

80

- **Connection Management**: Provide connection pooling, caching, and transaction-aware connections

81

- **Destination Resolution**: Abstract destination lookup supporting JNDI, dynamic, and bean factory-based resolution

82

- **Exception Translation**: Convert vendor-specific JMS exceptions to Spring's consistent exception hierarchy

83

84

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

85

86

## Capabilities

87

88

### Core JMS Operations

89

90

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

91

92

```java { .api }

93

public interface JmsOperations {

94

void send(String destinationName, MessageCreator messageCreator) throws JmsException;

95

void convertAndSend(String destinationName, Object message) throws JmsException;

96

Message receive(String destinationName) throws JmsException;

97

Object receiveAndConvert(String destinationName) throws JmsException;

98

}

99

100

public class JmsTemplate implements JmsOperations {

101

public JmsTemplate();

102

public JmsTemplate(ConnectionFactory connectionFactory);

103

104

// Configuration methods

105

public void setConnectionFactory(ConnectionFactory connectionFactory);

106

public void setDefaultDestinationName(String defaultDestinationName);

107

public void setMessageConverter(MessageConverter messageConverter);

108

public void setReceiveTimeout(long receiveTimeout);

109

}

110

```

111

112

[Core Operations](./core-operations.md)

113

114

### Message Listeners and Containers

115

116

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

117

118

```java { .api }

119

@Target({ElementType.TYPE, ElementType.METHOD})

120

@Retention(RetentionPolicy.RUNTIME)

121

public @interface JmsListener {

122

String destination() default "";

123

String containerFactory() default "";

124

String selector() default "";

125

}

126

127

public class DefaultMessageListenerContainer extends AbstractMessageListenerContainer {

128

public DefaultMessageListenerContainer();

129

public void setConnectionFactory(ConnectionFactory connectionFactory);

130

public void setDestinationName(String destinationName);

131

public void setMessageListener(MessageListener messageListener);

132

}

133

```

134

135

[Message Listeners](./message-listeners.md)

136

137

### Message Conversion

138

139

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

140

141

```java { .api }

142

public interface MessageConverter {

143

Message toMessage(Object object, Session session) throws JMSException, MessageConversionException;

144

Object fromMessage(Message message) throws JMSException, MessageConversionException;

145

}

146

147

public class SimpleMessageConverter implements MessageConverter {

148

public SimpleMessageConverter();

149

}

150

151

public class MappingJackson2MessageConverter implements MessageConverter {

152

public MappingJackson2MessageConverter();

153

public void setObjectMapper(ObjectMapper objectMapper);

154

public void setTargetType(MessageType targetType);

155

}

156

```

157

158

[Message Conversion](./message-conversion.md)

159

160

### Connection Management

161

162

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

163

164

```java { .api }

165

public class CachingConnectionFactory implements ConnectionFactory {

166

public CachingConnectionFactory();

167

public CachingConnectionFactory(ConnectionFactory targetConnectionFactory);

168

public void setSessionCacheSize(int sessionCacheSize);

169

public void setCacheProducers(boolean cacheProducers);

170

public void setCacheConsumers(boolean cacheConsumers);

171

}

172

173

public class SingleConnectionFactory implements ConnectionFactory {

174

public SingleConnectionFactory();

175

public SingleConnectionFactory(ConnectionFactory targetConnectionFactory);

176

public void setReconnectOnException(boolean reconnectOnException);

177

}

178

```

179

180

[Connection Management](./connection-management.md)

181

182

### Destination Resolution

183

184

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

185

186

```java { .api }

187

public interface DestinationResolver {

188

Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain)

189

throws JMSException;

190

}

191

192

public class DynamicDestinationResolver implements DestinationResolver {

193

public DynamicDestinationResolver();

194

}

195

196

public class JndiDestinationResolver implements DestinationResolver {

197

public JndiDestinationResolver();

198

public void setJndiTemplate(JndiTemplate jndiTemplate);

199

public void setCache(boolean cache);

200

}

201

```

202

203

[Destination Resolution](./destination-resolution.md)

204

205

### Configuration Support

206

207

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

208

209

```java { .api }

210

public abstract class AbstractJmsListenerContainerFactory<C extends AbstractMessageListenerContainer>

211

implements JmsListenerContainerFactory<C> {

212

213

public void setConnectionFactory(ConnectionFactory connectionFactory);

214

public void setDestinationResolver(DestinationResolver destinationResolver);

215

public void setMessageConverter(MessageConverter messageConverter);

216

}

217

218

public class DefaultJmsListenerContainerFactory extends AbstractJmsListenerContainerFactory<DefaultMessageListenerContainer> {

219

public DefaultJmsListenerContainerFactory();

220

}

221

222

@Target(ElementType.TYPE)

223

@Retention(RetentionPolicy.RUNTIME)

224

public @interface EnableJms {

225

}

226

```

227

228

[Configuration](./configuration.md)

229

230

## Types

231

232

```java { .api }

233

// Core interfaces

234

public interface ConnectionFactory {

235

Connection createConnection() throws JMSException;

236

Connection createConnection(String userName, String password) throws JMSException;

237

}

238

239

public interface MessageCreator {

240

Message createMessage(Session session) throws JMSException;

241

}

242

243

public interface SessionCallback<T> {

244

T doInJms(Session session) throws JMSException;

245

}

246

247

public interface ProducerCallback<T> {

248

T doInJms(Session session, MessageProducer producer) throws JMSException;

249

}

250

251

// Quality of Service settings

252

public class QosSettings {

253

public QosSettings();

254

public QosSettings(int deliveryMode, int priority, long timeToLive);

255

256

public void setDeliveryMode(int deliveryMode);

257

public void setPriority(int priority);

258

public void setTimeToLive(long timeToLive);

259

}

260

261

// Exception hierarchy

262

public abstract class JmsException extends NestedRuntimeException {

263

public JmsException(String msg);

264

public JmsException(String msg, Throwable cause);

265

}

266

267

public class UncategorizedJmsException extends JmsException {

268

public UncategorizedJmsException(JMSException cause);

269

}

270

271

// Additional supporting interfaces

272

public interface InvocableHandlerMethod {

273

Object invoke(Message message, Object... providedArgs) throws Exception;

274

}

275

276

public interface HandlerMethodArgumentResolver {

277

boolean supportsParameter(MethodParameter parameter);

278

Object resolveArgument(MethodParameter parameter, Message message) throws Exception;

279

}

280

281

public interface ErrorHandler {

282

void handleError(Throwable t);

283

}

284

285

public interface BackOff {

286

BackOffExecution start();

287

}

288

289

public interface BackOffExecution {

290

long nextBackOff();

291

}

292

```