Dashboard > GridGain User Guide > Table Of Contents > Developers Guide > Communication SPI > GridJmsCommunicationSpi
GridJmsCommunicationSpi
Added by user-1-ds, last edited by morpheus on Oct 22, 2007  (view change)
Labels: 
(None)


Click on Javadoc link to open Javadoc documentation.

Package

org.gridgain.grid.spi.communication.jms Javadoc

Description

GridJmsCommunicationSpi Javadoc provides JMS implementation of GridCommunicationSpi Javadoc . This implementation uses JMS topic and queue to send messages to an individual node or to a group of remote nodes. Note that JMS queue is optional. If provided, then it will be used for sending messages to a single node (method GridJmsCommunicationSpi.sendMessage(GridNode, Serializable) Javadoc ), otherwise
JMS topic will be used in which case a message will be sent to all nodes, but only destination node will process it and others will ignore it. JMS Topic is a mandatory parameter and is always used for communication with more than one node (method GridJmsCommunicationSpi.sendMessage(Collection, Serializable) Javadoc ). Both, topic and queue will be first obtained from JNDI lookup.

Configuration

Starting with release 1.6.0 GridGain comes with sample JMS configuration files for various providers, such as ActiveMQ, JBoss, SunMQ, etc... Please refer to examples/config folder under GridGain installation folder for more information.

The following configuration parameters can be used to configure GridJmsCommuncationSpi

Setter Method Description Optional Default
setConnectionFactoryName(String) Javadoc JNDI name of JMS connection factory. Yes. Either connection factory or connection factory name must be set.
setConnectionFactory(ConnectionFactory) Javadoc JMS connection factory. (Since 1.6.0) Yes. Either connection factory or connection factory name must be set.
setJndiEnvironment(Map) Javadoc JNDI environment properties. For example, JBoss would require the following JNDI environment properties
  • javax.naming.Context.INITIAL_CONTEXT_FACTORY
  • javax.naming.Context.PROVIDER_URL
  • javax.naming.Context.URL_PKG_PREFIXES
Yes
setTopicName(String) Javadoc JNDI name of JMS topic. Yes. Either topic or topic name must be set.
setTopic(Topic) Javadoc JMS topic. (Since 1.6.0) Yes. Either topic or topic name must be set.
setQueueName(String) Javadoc JNDI name of JMS queue. Yes null
setQueue(Queue) Javadoc JMS queue. (Since 1.6.0) Yes null
setDeliveryMode(int) Javadoc JMS message delivery mode. Yes javax.jms.Message.DEFAULT_DELIVERY_MODE
setPriority(int) Javadoc JMS message priority. Yes javax.jms.Message.DEFAULT_PRIORITY
setTimeToLive(long) Javadoc JMS message time to live. Yes javax.jms.Message.DEFAULT_TIME_TO_LIVE
setTransacted(boolean) Javadoc Indicates whether JMS messages are transacted or not. Yes false
setUser(String) Javadoc JMS connection user name for connectivity authentication. Note that if user is provided, then password must also be provided. Yes null which means that no authentication will be used.
setPassword(String) Javadoc JMS connection password for connectivity authentication. Note that if password is provided, then user is also provided. Yes null which means that no authentication will be used.

Examples

In order to use GridJmsCommunicationSpi Javadoc it needs to be explicitely configured

GridJmsCommunicationSpi commSpi = new GridJmsCommunicationSpi();

// JNDI connection factory name.
commSpi.setConnectionFactoryName("java:ConnectionFactory");

// JNDI environment mandatory parameter.
Map<Object, Object> env = new Hashtable<Object, Object>(3);

env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

commSpi.setJndiEnvironment(env);

// JNDI topic name.
commSpi.setTopicName("topic/myjmstopic");

GridConfigurationAdapter cfg = new GridConfigurationAdapter();

// Override default communication SPI.
cfg.setCommunicationSpi(commSpi);

// Start grid.
GridFactory.start(cfg);

or from Spring configuration file

<bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfigurationAdapter" singleton="true">
        ...
        <property name="communicationSpi">
            <bean class="org.gridgain.grid.spi.communication.jms.GridJmsCommunicationSpi">
                <property name="connectionFactoryName" value="java:ConnectionFactory"/>
                <property name="topicName" value="topic/myjmstopic"/>
                <property name="jndiEnvironment">
                    <map>
                        <entry>
                            <key><util:constant static-field="javax.naming.Context.INITIAL_CONTEXT_FACTORY"/></key>
                            <value>org.jnp.interfaces.NamingContextFactory</value>
                        </entry>
                        <entry>
                            <key><util:constant static-field="javax.naming.Context.PROVIDER_URL"/></key>
                            <value>jnp://localhost:1099</value>
                        </entry>
                        <entry>
                            <key><util:constant static-field="javax.naming.Context.URL_PKG_PREFIXES"/></key>
                            <value>org.jboss.naming:org.jnp.interfaces</value>
                        </entry>
                    </map>
                </property>
            </bean>
        </property>
        ...
</bean>


For more information about using Spring framework for configuration click here.

Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.10 Build:#528 Nov 29, 2006) - Bug/feature request - Contact Administrators