Hi,
Java Messaging Service is an API that provides reliable, asynchronous communication between applications in a distributed computing environment. It enables a Java applications that share a messaging system to exchange messages and Simplifies application development by providing a standard interface for creating, sending, and receiving messages.
What are major components of JMS system? To Know this as well as to see a Simple Demo of WebLogic Queues Please refer to: basic-jms-demo-using-weblogic-queue/
Here we are going to see how we can configure WebLogic JMS Server, JMS Modules (Topic/ConnectionFactory) how to Target them and then How to test it using a Simpel Java Programs.
Step1). Start your WebLogic Server an Login to the AdminConsole.
Step2). To Create a JMS Server Please refer to the (S t e p – 2) of basic-jms-demo-using-weblogic-queue/
Step3). Now we need to create a JMS Module.
Step4). Now we need to create a ConnectionFactory.
Step5). Creating a WebLogic Topic.
Step6). Create a Directory somewhere in your file system like: “C:WebLogic_Topic_Demo” to write the TopicSend and TopicReceive programs.
Step7). Write the “TopicSend.java” program as following inside “C:WebLogic_Topic_Demo”
import java.io.*; import java.util.*; import javax.transaction.*; import javax.naming.*; import javax.jms.*; import javax.rmi.PortableRemoteObject; public class TopicSend { public final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory"; public final static String JMS_FACTORY="TCF"; public final static String TOPIC="TestTopic"; protected TopicConnectionFactory tconFactory; protected TopicConnection tcon; protected TopicSession tsession; protected TopicPublisher tpublisher; protected Topic topic; protected TextMessage msg; public void init(Context ctx, String topicName) throws NamingException, JMSException { tconFactory = (TopicConnectionFactory) PortableRemoteObject.narrow(ctx.lookup(JMS_FACTORY),TopicConnectionFactory.class); tcon = tconFactory.createTopicConnection(); tsession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); topic = (Topic) PortableRemoteObject.narrow(ctx.lookup(topicName), Topic.class); tpublisher = tsession.createPublisher(topic); msg = tsession.createTextMessage(); tcon.start(); } public void send(String message) throws JMSException { msg.setText(message); tpublisher.publish(msg); } public void close() throws JMSException { tpublisher.close(); tsession.close(); tcon.close(); } public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println("Usage: java examples.jms.topic.TopicSend WebLogicURL"); return; } InitialContext ic = getInitialContext(args[0]); TopicSend ts = new TopicSend(); ts.init(ic, TOPIC); readAndSend(ts); ts.close(); } protected static void readAndSend(TopicSend ts)throws IOException, JMSException { BufferedReader msgStream = new BufferedReader (new InputStreamReader(System.in)); String line=null; System.out.print("nt TopicSender Started ... Enter message ("quit" to quit): n"); do { System.out.print("Topic Sender Says > "); line = msgStream.readLine(); if (line != null && line.trim().length() != 0) { ts.send(line); } } while (line != null && ! line.equalsIgnoreCase("quit")); } protected static InitialContext getInitialContext(String url) throws NamingException { Hashtable<String,String> env = new Hashtable<String,String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); env.put(Context.PROVIDER_URL, url); env.put("weblogic.jndi.createIntermediateContexts", "true"); return new InitialContext(env); } }
Step8). Write the “TopicReceive.java” program as following inside “C:WebLogic_Topic_Demo” to receive messages from the WebLogic Topic
import java.io.*; import java.util.*; import javax.transaction.*; import javax.naming.*; import javax.jms.*; import javax.rmi.PortableRemoteObject; public class TopicReceive implements MessageListener { public final static String JNDI_FACTORY="weblogic.jndi.WLInitialContextFactory"; public final static String JMS_FACTORY="TCF"; public final static String TOPIC="TestTopic"; private TopicConnectionFactory tconFactory; private TopicConnection tcon; private TopicSession tsession; private TopicSubscriber tsubscriber; private Topic topic; private boolean quit = false; public void onMessage(Message msg) { try { String msgText; if (msg instanceof TextMessage) { msgText = ((TextMessage)msg).getText(); } else { msgText = msg.toString(); } System.out.println("JMS Message Received: "+ msgText ); if (msgText.equalsIgnoreCase("quit")) { synchronized(this) { quit = true; this.notifyAll(); } } } catch (JMSException jmse) { System.err.println("An exception occurred: "+jmse.getMessage()); } } public void init(Context ctx, String topicName)throws NamingException, JMSException { tconFactory = (TopicConnectionFactory)PortableRemoteObject.narrow(ctx.lookup(JMS_FACTORY), TopicConnectionFactory.class); tcon = tconFactory.createTopicConnection(); tsession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); topic = (Topic) PortableRemoteObject.narrow(ctx.lookup(topicName), Topic.class); tsubscriber = tsession.createSubscriber(topic); tsubscriber.setMessageListener(this); tcon.start(); } public void close() throws JMSException { tsubscriber.close(); tsession.close(); tcon.close(); } public static void main(String[] args) throws Exception { if (args.length != 1) { System.out.println("Usage: java examples.jms.topic.TopicReceive WebLogicURL"); return; } InitialContext ic = getInitialContext(args[0]); TopicReceive tr = new TopicReceive(); tr.init(ic, TOPIC); System.out.println("JMS Ready To Receive Messages (To quit, send a "quit" message)."); synchronized(tr) { while (! tr.quit) { try { tr.wait(); } catch (InterruptedException ie) {} } } tr.close(); } private static InitialContext getInitialContext(String url) throws NamingException { Hashtable<String,String> env = new Hashtable<String,String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY); env.put(Context.PROVIDER_URL, url); env.put("weblogic.jndi.createIntermediateContexts", "true"); return new InitialContext(env); } }
Step9). Open 3 – Command Windows and run “setWLSEn.cmd” in all the three Command Windows to set the Environment (PATH & CLASSPATH).
Then compile the “TopicSend.java” and “TopicReceive.java” programs.
Step10). Start the “TopicReceive.java” program in two Command Windows like following :
java TopicReceive t3:/localhost:7001
Step11). Now start the “TopicSend.java” program to send some messages to the WebLogic Topic….As soon as u send message you will see that the Receivers started getting those messages…(One to Many Communication….one sender multiple receiver Which is called as Publish-Subscribe Messaging…. TOPIC)
NOTE: If you want to see the Messages inside the Topic from AdminConsole then Please follow the Tips provided by “Wolkenfels” http://middlewaremagic.com/weblogic/?p=2431#comment-1496
.
.
Thanks
Jay SenSharma
July 22nd, 2010 on 12:10 pm
Thanks for the good walkthrough.
you may know that you can look into a queue with the admin console but there is also a way to see the topic-messages there. To do that you have to create a durable subscriber to that topic in the console and then you can see the messages there.
Wanted to add that you website is a real gem for weblogic users! Kudos!
July 22nd, 2010 on 12:14 pm
Hi Wolkenfels,
I really appreciate your Tips for viewing Topic Message. I didn’t know that. I will try it once. That will be a good Point here.
Thanks a Lot, Thanks for visting Wonders. We will be waiting to see some more tips from u.
.
.
Keep Posting 🙂
Thanks
jay SenSharma
July 28th, 2010 on 1:12 pm
Hi Jay,
Thanks for the document , well appreciated!
Till step(6) I’m done successfully , now small doubt with step(7) –
Writing “TopicSend.java” program means is it normal text file or ?
I working on windows platform
Can you help from here – thanks much.
–Arun
July 28th, 2010 on 1:46 pm
Hi Arun,
“TopicSend.java” is a Java Program … to run this program u need to do the following
Step1). Save the content of this post in your file “TopicSend.java”
Step2). open a command window and then run the “setWLSEnv.cmd” (This script we need to set the environment like CLASSPATH & PATH in our command prompt. This script can be found inside “C:bea103wlserver_10.3serverbin” Location….Location may be different in your case according to your installation directory)
Step3). In the same command prompt compile the “TopicSend.java” like following:
javac TopicTest.java
Step4). Run the TopicSend program like described in the Image.
java TopicSend
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
July 29th, 2010 on 11:36 am
Thanks Jay.
Now I’m struck at executing the programs;
Error after executing TopicSend.java:-
D:WLS_HOME_103>java TopicSend t3://127.0.0.1:10001
Exception in thread “Main Thread” java.lang.NoClassDefFoundError: TopicSend
Info:
My Weblogic Admin Console URL
http://127.0.0.1:10001/console
Please let me know if you need any information more..
Thanks
July 29th, 2010 on 12:04 pm
Hi Arun,
Please follow the below Steps…
Step1). Open a fresh command prompt …then run the “setWLSEnv.cmd” (which is inside %WL_HOME%serverbin)
Step2). in the same command prompt do the following: (Below step is very important to tell the command prompt that pick the classes from the CLASSPATH including the current directory…. see i added a DOT also in the classpath).
set CLASSPATH=%CLASSPATH%;.;
Step3). In the same prompt do the following
Move inside the D-Drive
cd WLS_HOME_103
Step4). compile and run the program like:
D:WLS_HOME_103>javac TopicSend.java
D:WLS_HOME_103>java TopicSend t3://127.0.0.1:10001
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
July 29th, 2010 on 2:56 pm
Please see this how i executed your steps :
D:WLS_HOME_103>cd wlserver_10.3serverbin
D:WLS_HOME_103wlserver_10.3serverbin>setWLSEnv.cmd
CLASSPATH=D:WLS_HO~2patch_wlw1030profilesdefaultsys_manifest_classpathwebl
ogic_patch.jar;D:WLS_HO~2patch_wls1030profilesdefaultsys_manifest_classpath
weblogic_patch.jar;D:WLS_HO~2patch_cie660profilesdefaultsys_manifest_class
pathweblogic_patch.jar;D:WLS_HO~2JROCKI~1libtools.jar;D:WLS_HO~2WLSERV~1.
3serverlibweblogic_sp.jar;D:WLS_HO~2WLSERV~1.3serverlibweblogic.jar;D:W
LS_HO~2modulesfeaturesweblogic.server.modules_10.3.0.0.jar;D:WLS_HO~2WLSERV
~1.3serverlibwebservices.jar;D:WLS_HO~2modulesORGAPA~1.5/lib/ant-all.jar;D
:WLS_HO~2modulesNETSFA~1.0_1/lib/ant-contrib.jar;D:WLS_HO~2patch_wlw1030pr
ofilesdefaultsys_manifest_classpathweblogic_patch.jar;D:WLS_HO~2patch_wls10
30profilesdefaultsys_manifest_classpathweblogic_patch.jar;D:WLS_HO~2patch_
cie660profilesdefaultsys_manifest_classpathweblogic_patch.jar;D:WLS_HO~2JR
OCKI~1libtools.jar;D:WLS_HO~2WLSERV~1.3serverlibweblogic_sp.jar;D:WLS_HO
~2WLSERV~1.3serverlibweblogic.jar;D:WLS_HO~2modulesfeaturesweblogic.serv
er.modules_10.3.0.0.jar;D:WLS_HO~2WLSERV~1.3serverlibwebservices.jar;D:WLS
_HO~2modulesORGAPA~1.5/lib/ant-all.jar;D:WLS_HO~2modulesNETSFA~1.0_1/lib/an
t-contrib.jar;;.;
PATH=D:WLS_HO~2patch_wlw1030profilesdefaultnative;D:WLS_HO~2patch_wls1030
profilesdefaultnative;D:WLS_HO~2patch_cie660profilesdefaultnative;D:WLS
_HO~2WLSERV~1.3servernativewin32;D:WLS_HO~2WLSERV~1.3serverbin;D:WLS_H
O~2modulesORGAPA~1.5bin;D:WLS_HO~2JROCKI~1jrebin;D:WLS_HO~2JROCKI~1bin
;D:WLS_HO~2patch_wlw1030profilesdefaultnative;D:WLS_HO~2patch_wls1030pro
filesdefaultnative;D:WLS_HO~2patch_cie660profilesdefaultnative;D:WLS_HO~
2WLSERV~1.3servernativewin32;D:WLS_HO~2WLSERV~1.3serverbin;D:WLS_HO~2
modulesORGAPA~1.5bin;D:WLS_HO~2JROCKI~1jrebin;D:WLS_HO~2JROCKI~1bin;C:
Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:Program FilesTortoiseSV
Nbin;D:WLS_HO~2WLSERV~1.3servernativewin32oci920_8;D:WLS_HO~2WLSERV~1.
3servernativewin32oci920_8
Your environment has been set.
D:WLS_HOME_103wlserver_10.3serverbin>set CLASSPATH=%CLASSPATH%;.;
D:WLS_HOME_103wlserver_10.3serverbin>cd ../..
D:WLS_HOME_103wlserver_10.3>cd ..
D:WLS_HOME_103>javac TopicSend.java
TopicSend.java:9: illegal character: 8221
public final static String JNDI_FACTORY=öweblogic.jndi.WLInitialContextFactoryö;
^
TopicSend.java:9: illegal character: 8221
public final static String JNDI_FACTORY=öweblogic.jndi.WLInitialContextFactoryö;
^
TopicSend.java:10: illegal character: 8221
public final static String JMS_FACTORY=öTCFö;
^
TopicSend.java:10: illegal character: 8221
public final static String JMS_FACTORY=öTCFö;
^
TopicSend.java:11: illegal character: 8221
public final static String TOPIC=öTestTopicö;
^
TopicSend.java:11: illegal character: 8221
public final static String TOPIC=öTestTopicö;
^
TopicSend.java:44: illegal character: 8220
System.out.println(ôUsage: java examples.jms.topic.TopicSend WebLogicURLö);
^
TopicSend.java:44: ‘;’ expected
System.out.println(ôUsage: java examples.jms.topic.TopicSend WebLogicURLö);
^
TopicSend.java:44: illegal start of expression
System.out.println(ôUsage: java examples.jms.topic.TopicSend WebLogicURLö);
^
TopicSend.java:44: ‘;’ expected
System.out.println(ôUsage: java examples.jms.topic.TopicSend WebLogicURLö);
^
TopicSend.java:44: illegal character: 8221
System.out.println(ôUsage: java examples.jms.topic.TopicSend WebLogicURLö);
^
TopicSend.java:58: illegal character: 8220
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:58: illegal character: 92
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:58: illegal character: 92
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:58: not a statement
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:58: ‘;’ expected
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:58: illegal character: 8230
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:58: not a statement
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:58: ‘;’ expected
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:58: illegal character: 92
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:58: illegal character: 8221
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:58: illegal character: 92
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:58: not a statement
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:58: illegal character: 8221
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:58: ‘;’ expected
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:58: illegal character: 92
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:58: illegal character: 8221
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:58: not a statement
System.out.print(ônt TopicSender Started à Enter message (öquitö to quit):
nö);
^
TopicSend.java:60: illegal character: 8220
System.out.print(ôTopic Sender Says > ô);
^
TopicSend.java:60: ‘;’ expected
System.out.print(ôTopic Sender Says > ô);
^
TopicSend.java:60: ‘;’ expected
System.out.print(ôTopic Sender Says > ô);
^
TopicSend.java:60: illegal character: 8220
System.out.print(ôTopic Sender Says > ô);
^
TopicSend.java:65: illegal character: 8220
} while (line != null && ! line.equalsIgnoreCase(ôquitö));
^
TopicSend.java:65: ‘)’ expected
} while (line != null && ! line.equalsIgnoreCase(ôquitö));
^
TopicSend.java:65: illegal character: 8221
} while (line != null && ! line.equalsIgnoreCase(ôquitö));
^
TopicSend.java:65: illegal start of expression
} while (line != null && ! line.equalsIgnoreCase(ôquitö));
^
TopicSend.java:65: ‘;’ expected
} while (line != null && ! line.equalsIgnoreCase(ôquitö));
^
TopicSend.java:74: illegal character: 8220
env.put(ôweblogic.jndi.createIntermediateContextsö, ôtrueö);
^
TopicSend.java:74: ‘;’ expected
env.put(ôweblogic.jndi.createIntermediateContextsö, ôtrueö);
^
TopicSend.java:74: illegal start of expression
env.put(ôweblogic.jndi.createIntermediateContextsö, ôtrueö);
^
TopicSend.java:74: ‘;’ expected
env.put(ôweblogic.jndi.createIntermediateContextsö, ôtrueö);
^
TopicSend.java:74: illegal character: 8221
env.put(ôweblogic.jndi.createIntermediateContextsö, ôtrueö);
^
TopicSend.java:74: not a statement
env.put(ôweblogic.jndi.createIntermediateContextsö, ôtrueö);
^
TopicSend.java:74: illegal character: 8220
env.put(ôweblogic.jndi.createIntermediateContextsö, ôtrueö);
^
TopicSend.java:74: illegal character: 8221
env.put(ôweblogic.jndi.createIntermediateContextsö, ôtrueö);
^
45 errors
D:WLS_HOME_103>
July 29th, 2010 on 3:57 pm
Hi Arun,
Whenever u copy paste some programs from weblogic – wonders …in a Noteopad or textpad then …always replace/alter some special characters (which are UTF characters) from the program while pasting it. Like replace all double quote marks with your Notepad/TextPad double quote marks…etc. which takes another 1-2 minutes to correct all the characters before running it.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
July 30th, 2010 on 12:27 pm
Thanks alot Jay , that works perfect for me!
I am able to send and receive messages successfully now
Publish-Subscribe messages works fine!
Do we have any option to test the same sending and receiving stuff from Admin-Console itself ?
Thanks Jay for helping me.
–Arun
September 25th, 2010 on 9:05 pm
Hi Arun,
Yes, we have an option to send messages from Admin-Console just like for Queues BUT that can only be done for “Durable Subscribers”
Below is the the link which would help you to create a durable subscribers and then you can use the code to check it.
Option-1
Link: http://download.oracle.com/docs/cd/E12840_01/wls/docs103/ConsoleHelp/taskhelp/jms_modules/topics/ManageDurableSubscribers.html
Option-2
# Copy the below code in the “TopicReceive.java” program in the following Dir “C:WebLogic_Topic_DemoDurable_Subscribers”
NOTE: DIR is “C:WebLogic_Topic_DemoDurable_Subscribers”
// STARTING OF CODE
import java.io.*;
import java.util.*;
import javax.transaction.*;
import javax.naming.*;
import javax.jms.*;
import javax.rmi.PortableRemoteObject;
public class TopicReceive implements MessageListener {
public final static String JNDI_FACTORY=”weblogic.jndi.WLInitialContextFactory”;
public final static String JMS_FACTORY=”CF”;
public final static String TOPIC=”T”;
private TopicConnectionFactory tconFactory;
private TopicConnection tcon;
private TopicSession tsession;
private TopicSubscriber tsubscriber;
private Topic topic;
private boolean quit = false;
public void onMessage(Message msg) {
try {
String msgText;
if (msg instanceof TextMessage) {
msgText = ((TextMessage)msg).getText();
} else {
msgText = msg.toString();
}
System.out.println(“JMS Message Received: “+ msgText );
if (msgText.equalsIgnoreCase(“quit”)) {
synchronized(this) {
quit = true;
this.notifyAll();
}
}
} catch (JMSException jmse) {
System.err.println(“An exception occurred: “+jmse.getMessage());
}
}
/**
*
*
* Below are the code which makes it a Durable Subscriber by giving the Client ID and Subscription Name
*
*
*/
public void init(Context ctx, String topicName)
throws NamingException, JMSException
{
tconFactory = (TopicConnectionFactory)
PortableRemoteObject.narrow(ctx.lookup(JMS_FACTORY),
TopicConnectionFactory.class);
tcon = tconFactory.createTopicConnection();
// ############## Below the Clinet ID is been given which is “Ravish” #####################
tcon.setClientID(“Ravish”);
tsession = tcon.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
topic = (Topic)
PortableRemoteObject.narrow(ctx.lookup(topicName),
Topic.class);
// ############## Below the Subscription Name is been given which is “Test” #####################
tsubscriber = tsession.createDurableSubscriber(topic, “Test”);
tsubscriber.setMessageListener(this);
tcon.start();
}
public void close() throws JMSException {
tsubscriber.close();
tsession.close();
tcon.close();
}
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.out.println(“Usage: java examples.jms.topic.TopicReceive WebLogicURL”);
return;
}
InitialContext ic = getInitialContext(args[0]);
TopicReceive tr = new TopicReceive();
tr.init(ic, TOPIC);
System.out.println(“JMS Ready To Receive Messages (To quit, send a “quit” message).”);
synchronized(tr) {
while (! tr.quit) {
try {
tr.wait();
} catch (InterruptedException ie) {}
}
}
tr.close();
}
private static InitialContext getInitialContext(String url)
throws NamingException
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, url);
env.put(“weblogic.jndi.createIntermediateContexts”, “true”);
return new InitialContext(env);
}
}
// END OF CODE
# Repeat the STEP 9 and 10
Using the above code you will create a durable subscriber and also can directly start sending messages from the Admin-console from the following path
Path:
JMS Modules -> MySystemModule -> TestTopic -> Monitoring (Tab) -> Durable Subscribers (Sub-Tab)
# Check “Test”
# Click “Show Messages”
# Click “New”
# Fill “Type”, “Correlation ID” and “Body” and hit “OK”
Result:
You will receive the same message written in Body.
For more information on durable subscribers below are few links:
Under the Topic: Monitoring Durable Subscribers for Topics
http://download.oracle.com/docs/cd/E12840_01/wls/docs103/jms_admin/manage_msg.html
Under the Topic: Setting Up Durable Subscriptions
http://download.oracle.com/docs/cd/E13222_01/wls/docs81/jms/implement.html#1097632
Hope this helps
Regards,
Ravish Mody
September 27th, 2010 on 11:07 am
Thanks alot Ravish.
I’ll get back to you incase if i face any problem
Thanks
Arun
September 27th, 2010 on 8:19 pm
Hi Arun,
Sure, just let us know if you face any issue.
We would try to help you out with it, that’s what MM team does 😉
Keep posting…
Regards,
Ravish Mody
February 20th, 2011 on 12:52 pm
Hello Jay/Ravish
Why we are creating the connection factory like way using PortableRemoteObject.narrow.
tconFactory = (TopicConnectionFactory) PortableRemoteObject.narrow(ctx.lookup(JMS_FACTORY),TopicConnectionFactory.class);
I tied the above example simply using
tconFactory = (TopicConnectionFactory)ctx.lookup(JMS_FACTORY);
and it works fine. Can you please let me know what is the use of PortableRemoteObject.narrow here??
Sumit
February 20th, 2011 on 1:07 pm
Hi Sumit,
Please ignore “PortableRemoteObject.narrow” from JDK1.5 onwards you don’t need to cast the remote objects like this. However in Jdk1.4 for Plain RMI based implementations this was required just to ensure the casting happens properly.
Java RMI-IIOP provides a mechanism to narrow the the Object you have received from from your lookup, to the appropriate type. This is done through the javax.rmi.PortableRemoteObject class and, more specifically, using the narrow() method.
The narrow method takes an object reference or abstract interface type and attempts to narrow it to conform to the given interface. If the operation is successful the result will be an object of the specified type, otherwise an exception will be thrown.
From JDK1.5 onwards the JDK has become more mature. So u can ignore it.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
March 24th, 2011 on 10:59 am
i m unable to see the snapshots…please help me…and i have doubt on sending message to topic that weather can i sent the message to the web-logic on my system only or on other systems which r connected to the LAN by giving there ipaddress some where in the program..
March 24th, 2011 on 12:50 pm
Hi tejuishere89,
You can send/receive messages to any Topic which is residing on your local system or even to the remote system where you can connect. The things you would need is the Connection Factory JNDI name, Topic JNDI name and the IP-address/Host name with its Port to connect to the Topic.
The code given in the above post would work fine in your case also and the ip-address:port has to be given when you are going to run the java code which is show above in the STEP-10
Example:
Sending messages = java TopicSend t3:/10.10.10.10:7001
Receiving messages = java TopicReceive t3:/10.10.10.10:7001
April 21st, 2011 on 1:24 pm
The screenshots are missing here. Images are not showing up. Thanks
April 21st, 2011 on 2:48 pm
Hi Testab,
Sorry !!! But these Images are not available at present we will upload the images soon.
Magic Team Shares Bonus 20 Magic Points with you.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
April 26th, 2011 on 8:49 am
You might want to fix the code syntax in TopicReceive. It is showing escape chaarcters causing syntax error in the code.
Hashtable env = new Hashtable();
April 26th, 2011 on 11:45 pm
Hi testab,
The Hashtable syntax is corrected. Thanks for keen observation.
Magic Team shares 10 Bonus Magic Points to your Account. 🙂
These kind of observations makes us more strong and bug free codes.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
November 18th, 2011 on 5:39 am
hi Ravish
i have followed above steps correctly but when I execute TopicReceive,TopicSend i got following exceptions
C:beauser_projectsdomainssample_domainbin>java TopicReceive t3://localhost:7001
Exception in thread “main” javax.naming.NameNotFoundException: Unable to resolve
‘TCF’. Resolved ” [Root exception is javax.naming.NameNotFoundException: Unabl
e to resolve ‘TCF’. Resolved ”]; remaining name ‘TCF’
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:221)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef
.java:338)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef
.java:252)
i have JMSServer target as Server-1(manage server) and also subdeployemnt target is Server-1(manage server)
i had just given the following parameters in console
JMS server = MJMSServer
File Store= MFileStore
JMS Module =MSystemModule
ConnectionFactory =TCF
subdeployment=Msub
Topic = TestTopic
can you please assist me to resolve this issue.
November 18th, 2011 on 5:47 am
hi Ravish
i have followed above steps correctly but when I execute TopicReceive,TopicSend i got following exceptions
C:beauser_projectsdomainssample_domainbin>java TopicReceive t3://localhost:
7001
Exception in thread “main” javax.naming.NameNotFoundException: Unable to resolve
‘TCF’. Resolved ” [Root exception is javax.naming.NameNotFoundException: Unabl
e to resolve ‘TCF’. Resolved ”]; remaining name ‘TCF’
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:221)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef
.java:338)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef
.java:252)
i have JMSServer which is targetted(target) as Server-1(manage server) and also subdeployemnt targetted(target) is Server-1(manage server)
i had just given the following parameters in console
JMS server = MJMSServer
File Store= MFileStore
JMS Module =MSystemModule
ConnectionFactory =TCF
subdeployment=Msub
Topic = TestTopic
can you please assist me to resolve this issue.
November 18th, 2011 on 2:33 pm
Hi satyaweblogicadmin,
First make sure that your managed server is running on 7001 port, I believe not. You should connect to the server on which you have created the topic and connection factory.
From the exception it looks like the JNDI for connection factory (TCF) is not been found, hence can you check in the JNDI tree of your managed server (Server-1) if you can see the TCF in it or not.
Regards,
Ravish Mody
November 23rd, 2011 on 2:40 pm
Hi Ravish
instead of giving the hostname in the Listen Address column i had given IP address .also bounced the server.now everything looks good.
thanks
satya
October 11th, 2012 on 2:58 pm
HI Guys,
i have doubt on the connection factory. For example if we have both queue and topic on the same JMS module, whether we need to create separate Connection factory for queue and topic? or if one connection factory is enough then how it knows whether its for queue or topic ?
January 24th, 2013 on 9:41 pm
hi there, thanks for this article. but your image links are broken, can you please fix that. thanks in advance.
February 6th, 2013 on 9:04 am
Hi,
I have a query on the distributed topic. Is it possible to configure a distributed topic with jdbc store (non-xa multidata source) and a distributed queue with file store? I had tried this out but am getting a transaction rollback exception after i put a test message into the first managed server.
Can you please help me out.
Thanks in advance.