0
# Messaging
1
2
JMS API for asynchronous messaging with support for queues, topics, and message-driven beans.
3
4
## Core Interfaces
5
6
```java { .api }
7
public interface ConnectionFactory;
8
9
public interface Connection extends AutoCloseable {
10
Session createSession() throws JMSException;
11
Session createSession(boolean transacted, int acknowledgeMode) throws JMSException;
12
void start() throws JMSException;
13
void stop() throws JMSException;
14
void close() throws JMSException;
15
}
16
17
public interface Session extends Runnable, AutoCloseable {
18
MessageProducer createProducer(Destination destination) throws JMSException;
19
MessageConsumer createConsumer(Destination destination) throws JMSException;
20
Message createMessage() throws JMSException;
21
TextMessage createTextMessage() throws JMSException;
22
TextMessage createTextMessage(String text) throws JMSException;
23
void commit() throws JMSException;
24
void rollback() throws JMSException;
25
void close() throws JMSException;
26
}
27
```
28
29
## Message Types
30
31
```java { .api }
32
public interface Message {
33
String getJMSMessageID() throws JMSException;
34
void setJMSMessageID(String id) throws JMSException;
35
long getJMSTimestamp() throws JMSException;
36
void setJMSTimestamp(long timestamp) throws JMSException;
37
Destination getJMSDestination() throws JMSException;
38
void setJMSDestination(Destination destination) throws JMSException;
39
}
40
41
public interface TextMessage extends Message {
42
void setText(String string) throws JMSException;
43
String getText() throws JMSException;
44
}
45
```
46
47
## Usage Example
48
49
```java
50
@MessageDriven
51
public class OrderMessageBean implements MessageListener {
52
53
@Override
54
public void onMessage(Message message) {
55
try {
56
if (message instanceof TextMessage) {
57
TextMessage textMessage = (TextMessage) message;
58
String orderData = textMessage.getText();
59
// Process order
60
}
61
} catch (JMSException e) {
62
// Handle exception
63
}
64
}
65
}
66
```