Section Summary: GigaSpaces allows applications to use the space as a messaging hub. Applications use JMS to create topics and queues as usual; these are transparently translated into space Entries.
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 MessageConsumerMessageListener, 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 = // obtain
Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue destination = // obtain (the destination can also be a Topic)
// producer code
MessageProducer producer = session.createProducer(destination);
Message msg = session.createMessage();
for (...) {
producer.send(msg);
}
// consumer code
// synchronous consumer code
MessageConsumer consumer = session.createConsumer(destination);
for (...) {
Message msg = consumer.receive();
...
}
// asynchronous consumer code
MessageConsumer consumer = session.createConsumer(destination);
consumer.setMessageListener(new MessageListener() {
public void onMessage(Message msg) {
...
}
});
// start the connection to receive messages
connection.start();
// release resources
connection.close();
JMS Messages in GigaSpaces — JMS messages implementation; supported and unsupported message types; message compression; accessing JMS messages via space API.
JMS-Space Interoperability — Creating JMS messages with the space API; reading/taking JMS messages with the space API; using JMS API with the MessageConverter to send custom POJOs to the space.
Using JMS with OpenSpaces Example — Including a JMS feeder in a processing unit using Spring JmsTemplate, and using the JMS message converter to send POJOs to the space, using the JMS API.