A JMS client application must instantiate a Sybase InitialContext, and provide information to connect to a JMS provider.
The core JNDI interface used by client applications is javax.naming.Context, which represents the initial naming context used to resolve names to connection factories, message queues, and topics. To obtain an initial naming context:
Initialize a java.util.Properties instance:
java.util.Properties props = new java.util.Properties()
Set the InitialContext.INITIAL_CONTEXT_FACTORY property:
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sybase.jms.client.InitialContextFactory")
To define the connection properties, either specify a JMS provider or set the properties manually. EAServer includes a JMS provider named “default.”
To use the connection properties defined by the default JMS provider:
Initialize an instance of a JMS provider:
com.sybase.jms.client.JmsProvider _jmsProvider = new com.sybase.jms.client.JmsProvider()
Set the InitialContext.PROVIDER_URL property to “jms-provider:default”:
props.put(Context.PROVIDER_URL, "jms-provider:default")
This provides the information that is needed to connect to the default JMS provider. You can configure the properties of the default JMS provider and create new providers using the Management Console—see “Creating JMS providers”.
To set the connection properties manually, set the URL for the server’s IIOP port, the user name (principal), and the password (credentials):
props.put(Context.PROVIDER_URL, "iiop://myhost:2000") props.put(Context.SECURITY_PRINCIPAL, "jmsuser") props.put(Context.SECURITY_CREDENTIALS, "jmspass1")
Create the InitialContext instance:
return new InitialContext(props)
The JMS provider uses properties defined in the local client installation, not the server installation. You cannot use a JMS provider in an applet, since this feature requires access to configuration files in the EAServer installation. To run a JMS client application that uses a JMS provider, verify that the operating system library search path includes the server’s lib subdirectory. For example, on Windows, PATH must include %DJC_HOME%\lib, and on UNIX, LD_LIBRARY_PATH must include $DJC_HOME/lib.
If you are creating a client application that must be portable to other servers, use an external mechanism to specify properties, rather than hard-coding values in the source code. For example, in a Java application, use command line arguments or a serialized Java properties file. To specify properties used by a Java applet, use parameters in the HTML Applet tag that loads the applet.
This example runs the JMS client application JMSClientClass and sets the InitialContext factory, URL, user name, and password properties at runtime:
java -Djava.naming.factory.initial=com.sybase.jms.client.InitialContextFactory -Djava.naming.provider.url=iiop://myhost:9000 -Djava.naming.security.principal=”jmsuser” -Djava.naming.security.credentials=”jmspass1” JMSClientClass