Overview
GigaSpaces offers a virtual JMS implementation, built on top of the core JavaSpaces layer.
JMS messages are implemented as externalizable MetaDataEntries, indexed, and routed to the space according to the destination name.
Since GigaSpaces XAP 6.0, the JMS implementation supports the unified messaging model, introduced in version 1.1 of the JMS specification.
JMS Domains
JMS 1.0.2 introduced two domains:
- Point to Point – in this domain, a producer sends messages to a destination of type Queue. Each message is consumed by only one consumer.
- Publish/Subscribe – in this domain, a producer publishes messages to a destination of type Topic. Any consumer that listens on that Topic receives the messages.
In JMS 1.0.2, each domain used a separate set of interfaces.
JMS 1.1 presents the unified model, that unites the usage of both domains under a single set of interfaces.
GigaSpaces XAP 6.0 JMS implementation supports both the unified model, and the separate domains.
Basic JMS Workflow
- Obtain/create a ConnectionFactory instance.
- Create a Connection with the ConnectionFactory.
- Create a Session with the Connection.
- Obtain/create a Destination (Topic or Queue).
- Message production:
- Create MessageProducers with the Session and the destination.
- Create a Message with the Session.
- Send the Message with the MessageProducer.
- Message Consumption:
- Create MessageConsumers with the Session and the destination.
- Enable connection message consumption by calling the Connection.start() method.
- For synchronous consumption, call the MessageConsumer.receive() method.
- For asynchronous consumption, set the MessageConsumer MessageListener, and implement the onMessage() method.
- When the application finishes, release all resources by closing the connection.
Using Unified Messaging Model (JMS 1.1)
Click to see the code example:
ConnectionFactory connectionFactory = Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue destination =
MessageProducer producer = session.createProducer(destination);
Message msg = session.createMessage();
for (...) {
producer.send(msg);
}
MessageConsumer consumer = session.createConsumer(destination);
for (...) {
Message msg = consumer.receive();
...
}
MessageConsumer consumer = session.createConsumer(destination);
consumer.setMessageListener(new MessageListener() {
public void onMessage(Message msg) {
...
}
});
connection.start();
connection.close();
Using Separate Domains (JMS 1.0.2)
Publish/Subscribe
Click to see the code example:
TopicConnectionFactory topicConnectionFactory = TopicConnection topicConnection = topicConnectionFactory.createTopicConnection();
TopicSession topicSession = topicConnection.createTopicSession
(false, Session.AUTO_ACKNOWLEDGE);
Topic destination =
TopicPublisher publisher = topicSession.createPublisher();
Message msg = topicSession.createMessage();
for (...) {
publisher.send(msg);
}
TopicSubscriber subscriber = topicSession.createSubscriber(destination);
for (...) {
Message msg = subscriber.receive();
...
}
TopicSubscriber subscriber = topicSession.createSubscriber(destination);
subscriber.setMessageListener(new MessageListener() {
public void onMessage(Message msg) {
...
}
});
topicConnection.start();
topicConnection.close();
Point to Point
Click to see the code example:
QueueConnectionFactory queueConnectionFactory = QueueConnection queueConnection = queueConnectionFactory.createQueueConnection();
QueueSession queueSession = queueConnection.createQueueSession
(false, Session.AUTO_ACKNOWLEDGE);
Queue destination =
QueueSender sender = queueSession.createSender(destination);
Message msg = qSession.createMessage();
for (...) {
sender.send(msg);
}
QueueReceiver receiver = queueSession.createReceiver(destination);
for (...) {
Message msg = receiver.receive();
...
}
QueueReceiver receiver = queueSession.createReceiver(destination);
receiver.setMessageListener(new MessageListener() {
public void onMessage(Message msg) {
...
}
});
queueConnection.start();
queueConnection.close();
|
Section Contents
|