Look up Administered Objects Stored in EMS
You can lookup objects from an EMS server by name. All clients can lookup objects in the EMS naming service. Alternatively, Java applications can lookup objects in a third-party JNDI server, and C# clients can lookup objects in a third-party LDAP server.
To lookup administered objects stored in EMS, you need to create the initial context that identifies the URL of the naming service provider and any other properties, such as the username and password to authenticate the client to the service. The naming service provider URL has form:
tibjmsnaming://host:port
The following examples demonstrate how to access Jakarta Messaging administered objects when using TIBCO Enterprise Message Service. Each of these examples assume that a connection factory, named
ConFac, exists in the
factories.conf file, a
topic.sample topic exists in
topics.conf, and a
queue.sample queue exists in
queues.conf.
- Java
Create an
InitialContextobject for the initial context, which consists of the provider context factory and JNDI provider URL, as well as the username and password to authenticate the client to the EMS server:Hashtable env = new Hashtable();env.put(Context.INITIAL_CONTEXT_FACTORY,"com.tibco.tibjms.naming.TibjmsInitialContextFactory");env.put(Context.PROVIDER_URL,"tibjmsnaming://localhost:7222");env.put(Context.SECURITY_PRINCIPAL, "userName");env.put(Context.SECURITY_CREDENTIALS, "password");InitialContext jndiContext = new InitialContext(env);Look up a connection factory, named
ConFac, and destinations, namedtopic.sampleandqueue.sample, from the initial context:ConnectionFactory factory =(javax.jms.ConnectionFactory)jndiContext.lookup("ConFac");javax.jms.Topic sampleTopic =(javax.jms.Topic)jndiContext.lookup("topic.sample");javax.jms.Queue sampleQueue =(javax.jms.Queue)jndiContext.lookup("queue.sample");See the
tibjmsJNDI.javasample client located in theEMS_HOME/samples/java/JNDIdirectory. - C
Create a
tibemsLookupContextobject for the initial context, which consists of the JNDI provider URL and the username and password to authenticate the client to the EMS server:tibemsLookupContext* contextstatus = NULL;status = tibemsLookupContext_Create(&context,"tcp://localhost:7222","userName","password");Use the
tibemsLookupContext_LookupConnectionFactoryfunction to look up a connection factory, namedConFac, and use thetibemsLookupContext_LookupDestination function to look up the destinations, named andqueue.sample, from the initial context:topic.sample tibemsConnectionFactory factory = NULL; tibemsDestination sampleTopic = NULL; tibemsDestination sampleQueue = NULL; status = tibemsLookupContext_Lookup(context, "ConFac", (void**)&factory); status = tibemsLookupContext_Lookup(context, "sample.queue", (void**)&sampleQueue); status = tibemsLookupContext_Lookup(context, "topic.sample, (void**)&sampleTopic);
- C#
Create a
ILookupContextobject for the initial context, which consists of the JNDI provider URL and the username and password to authenticate the client to the EMS server.Hashtable env = new Hashtable();env.Add(LookupContext.PROVIDER_URL,"tibjmsnaming://localhost:7222");env.Add(LookupContext.SECURITY_PRINCIPAL", "myUserName");env.Add(LookupContext.SECURITY_CREDENTIALS", "myPassword");LookupContextFactory lcf = new LookupContextFactory();ILookupContext searcher = lcf.CreateContext(LookupContextFactory.TIBJMS_NAMING_CONTEXT,env);Use the
ILookupContext.Lookupmethod to look up a connection factory, named ConFac, and destinations, namedtopic.sampleandqueue.sample, from the initial context:ConnectionFactory factory =(ConnectionFactory) searcher.Lookup("ConFac");Topic sampleTopic =(Topic)searcher.Lookup("topic.sample");TIBCO.EMS.Queue sampleQueue =(TIBCO.EMS.Queue)searcher.Lookup("queue.sample");