Publish message on Topic destination in Oracle Weblogic Server 10.3.2

I have created two administrator objects on server: one Connection factory JNDI (cfjndi) and one Queue destination JNDI (qjndi). There are two applications : one is sender and other is receiver and both are connefted to the server.

Below steps are to create JMS sender and receiver :

  • Install Oracle WebLogic Server 10.3.2
  • Create Domain on Orcale WebLogic Server 10.3.2
  • Configure Domain in Eclipse
  • Create administrator objects for Queue on Server
  • Create Java project with Sender and Receiver
  • Run receiver and Sender

Step 1: Install Oracle WebLogic Server 10.3.2 [ Click here - How to install WebLogic Server ]

Step 2: Create Domain on Orcale WebLogic Server 10.3.2 [ Click here - How to create Domain on WebLogic Server ]

Step 3: Configure Domain in Eclipse [ Click here - How to Configure Domain in Eclipse ]

Step 4: Create administrator objects for Queue on Server [ Click here - How to create JMS administrator objects on Server]

Step 5: Create Java project with Sender and Receiver
File -> New -> Project -> Java Project -> Next -> Specify Project name : JMSTopicClient -> Next
JMS Queue Sender

Active Library and Click Add External JARs and select weblogic.jar from WebLogic Server installation directory.
JMS Queue Sender

Create Sender : QueueSender1.java
package techmyguru.queuesender;
// all imports
public class QueueSender1{
public static void main(String[] args) {
try {  
System.out.println("Queue Sening message");
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://localhost:7001");
InitialContext context = new InitialContext(p);
QueueConnectionFactory qcf = (QueueConnectionFactorycontext.lookup("cfjndi");
Queue queue = (Queuecontext.lookup("qjndi1");
QueueConnection qc = qcf.createQueueConnection();
QueueSession session = qc.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
QueueSender qp = session.createSender(queue);
qc.start();
TextMessage msg1 = session.createTextMessage();
for(int i=0;i<5;i++)
{
msg1.setText("Message from Client "+i);
qp.send(msg1);
}
System.out.println("Message saent");
catch (NamingException e) {
e.printStackTrace();
catch (JMSException e) {
e.printStackTrace();
catch (Exception e) {
e.printStackTrace();
}
}
}

Create Message Listener : MyMessageListener.java
package techmyguru.queuesender;
import javax.jms.*;
import utils.system;

public class MyMessageListener implements MessageListener
{
public MyMessageListener() 
{
System.out.println("Within Listener");
}

public void onMessage(Message msg) {
try {
  TextMessage tmsg = (TextMessagemsg;
  String message = tmsg.getText();
  System.out.println(message);
catch (JMSException e) {
  e.printStackTrace();
}
}
}

Create Message Receiver : QueueReceiver1.java
package techmyguru.queuesender;
// all import statements
public class QueueReceiver1 {
public static void main(String args[]) 
{
Queue topic = null;
QueueConnectionFactory tcf = null;
QueueConnection tc = null;
try {
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, "t3://localhost:7001");
InitialContext context = new InitialContext(p);
tcf = (QueueConnectionFactorycontext.lookup("cfjndi");
topic = (Queuecontext.lookup("qjndi1");
tc = tcf.createQueueConnection();
QueueSession session = tc.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
QueueReceiver ts = session.createReceiver(topic);
ts.setMessageListener(new MyMessageListener());
tc.start();
System.out.println("Queue Receiver1");
while (true
{
  Thread.sleep(1000);
}
catch (NamingException e) {
e.printStackTrace();
catch (JMSException e) {
e.printStackTrace();
catch (InterruptedException e) {
e.printStackTrace();
}
catch(Exception e)  {
e.printStackTrace();
}
}
}

Verify the project directory structure :
JMS Queue Sender

Run QueueReceiver1.java and QueueSender1.java respectively and get the output :
JMS Queue Sender
JMS Queue Sender
Previous Download Source Code Next

Comment by : Saul October 3rd, 2015
Comment : Apologize, but I disagree with one termI call Web Server to the acppilation that serves HTML pages, with its images and so on. What I call static content.Tomcat and Jetty are known as Servlet engines.


Write your Comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code